• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Reset on 18F4520

Status
Not open for further replies.

camerart

Active Member
Hi,
I'm using a PIC 18F4520. Is there a difference between initialising (switch on) and MCLR reset? When I start my program, after initialising, is doesn't give the correct result, If I reset it after initialising it works ok. If I need to reset it every time I switch on, can I simply add a connection from say PIN2 to PIN1 (Reset) then include a delay before resetting PIN1 with PIN2 by taking it low for a second?
Camerart.
 

ericgibbs

Well-Known Member
Most Helpful Member
hi C,
Look at and add before the start of the 18F4520 Program code, lets know what you get.

While
OSCCON.IOFS=0 ; osc stabilised bit,
Wend

Be aware that Oshonsoft may not be setting the variables to what you are expecting, when the programs first runs.

E
 

camerart

Active Member
Sounds like the oscillator is taking too long to stabilize... Are you using an external or the internal Osc?
Hi,
External 20MHz crystal.
I'll check Eric's suggestion tomorrow. I think he's correct, that some of the variables seem wrong until I reset and try a second time without switching off.
C.
 

camerart

Active Member
Hi E,
I tried:
While
OSCCON.IOFS=0 ; osc stabilised bit,
Wend

Wouldn't compile.
I tried:
While OSCCON.IOFS=0 ' osc stabilised bit, (note comma)
Wend

This compiled, but the PIC wouldn't start.
I also tried moving these lines down to just before the variable settings.
Thanks, C.
 

ericgibbs

Well-Known Member
Most Helpful Member
hi C,
Please post your code listing.
The semicolon I use was to signify a comment, Oshonsoft uses an 'apostrophe'.

E
 

ericgibbs

Well-Known Member
Most Helpful Member
hi C,

The program you have posted does not have the OSCCON statement.????
E

This is a clip from my code
TRISA = 0x0f
TRISB = 0x01
TRISC = %00000000
TRISD = %00001111
LATD = %00001111

TRISE.0 = 0 'rsvd for RTC
TRISE.1 = 1
Symbol dht = TRISE.2 'dht22

PORTB = 0
LATB = 0

ADCON0 = 0x03 '4 *adc
ADCON1 = 0x0b
ADCON2 = %10100100

T1CON.TMR1ON = 0
PIE1.TMR1IE = 1

While OSCCON.IOFS = 0
Wend


Lcdinit
Lcdout "TXA "

Hseropen 9600
Hserout "TXA ", CrLf

TMR1L = 0xdc ''0xfc '' 0xdc
TMR1H = 0x80 ''0x80 '''0x0b

Enable High
Enable Low
INTCON.GIE = 1
INTCON.PEIE = 1

T1CON.TMR1ON = 1
int_cnt = 18 'fast 1st txd

main_loop: 'idling loop, interrupts are enabled
 

ericgibbs

Well-Known Member
Most Helpful Member
hi C
Are you trying to run the program in simulation with the osccon statement.?
If so, it will not get past the osccon, as Oshonsoft IDE does not recognise the osccon.iofs
E
 

camerart

Active Member
Hi E,
No, in circuit. You will notice just after the DIMs, there are flashing LEDs, which don't flash when the OSCCON is in either position.
Does OSCCON also with Crystals
C.
 

ericgibbs

Well-Known Member
Most Helpful Member
Does OSCCON also with Crystals
hi C,
I will double check by using my 18F4520 set up, let you know.
E

Update:

The OSCCON.IOFS only works for the Internal Osc block.
When using an external xtal, the programmed PIC hangs up at the OSCCON statement.
 
Last edited:

camerart

Active Member
Hi,
It took a while, but now it's obvious to me that I can't reset MCLR using PIN 2 connected to it and a delayed 'push button' as it would reset and stay in that loop.
I'll just have to press the reset button. No problem!
Thanks, C.
 

ericgibbs

Well-Known Member
Most Helpful Member
hi,
It could be a problem due to a slow rise time of Vdd at power on.?
Try scoping the Vdd to the PIC at power On.
E
 

Attachments

camerart

Active Member
hi,
It could be a problem due to a slow rise time of Vdd at power on.?
Try scoping the Vdd to the PIC at power On.
E
Hi E,
Would this also be the case after reset? Reason! After many complete restart tests, I am finding that this happens after reset too.
I am sending simulated NMEA sentences (See bottom of the program) to the PIC using a macro from a computer terminal. Briefly, I press the IND button as first BASE sentences the sentences are fed into the PIC, which puts the first set of NMEA BASE sentences into BASE, then after release, the sentences are at a 100Mtr range, copying a remote GPS sentence. The first part ELEVATION always seems to work, but if things aren't perfect, when it gets to the AZIMUTH sentences it goes haywire. Once correct, I can reset or not and it always works ok.
EDIT: With my ancient oscilloscope, it looks as the voltage goes steady quickly, and with reset, there's no flicker.
C.
 
Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
I am sending simulated NMEA sentences (See bottom of the program) to the PIC using a macro from a computer terminal.
Hi C.
You say that you are using the list of test messages at the end of the program.
E

If you use this message as an input, note it is 90 characters long plus crlf = 92
$GPGGA,BASEDEGREE.00, 1000.00000, N, 00100.00000, W, 1, 10, 0.94, 000.0, m, 47.8, m,, * 47


Your buffer is only 80 long!
Dim str1(80) As Byte 'UART RXD buffer array

There is also an over length buffer error trap.
getmsg: 'read and save GPGGA msg
If PIR1.RCIF = 0 Then Goto getmsg
char = RCREG
str1(rxi) = char
rxi = rxi + 1
If rxi > 80 Then Goto get_neo 'msg bfr over run
'If char = 0x3f Then Goto eomsg '(0x3f = ?)SIM>>>>>>>>>>>>>>>>>>>>>>>>>>>.
If char = 0x0a Then Goto eomsg '(0x0a = LF)CIRCUIT>>>>>>>>>>>>>>>>>>>>>>>>
Goto getmsg
eomsg:
If rxi < 60 Then 'invalid msg
Goto get_neo
Endif

'$GPGGA,BASEDEGREE.00, 1000.00000, N, 00100.00000, W, 1, 10, 0.94, 000.0, m, 47.8, m,, * 47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'
 

camerart

Active Member
Hi Eric,
Is this ok?
Dim str1(95) As Byte 'UART RXD buffer array

There is also an over length buffer error trap.
getmsg: 'read and save GPGGA msg
If PIR1.RCIF = 0 Then Goto getmsg
char = RCREG
str1(rxi) = char
rxi = rxi + 1
If rxi > 95 Then Goto get_neo 'msg bfr over run
'If char = 0x3f Then Goto eomsg '(0x3f = ?)SIM>>>>>>>>>>>>>>>>>>>>>>>>>>>.
If char = 0x0a Then Goto eomsg '(0x0a = LF)CIRCUIT>>>>>>>>>>>>>>>>>>>>>>>>
Goto getmsg
eomsg:
If rxi < 60 Then 'invalid msg
Goto get_neo
Endif

C.

Hi C.
You say that you are using the list of test messages at the end of the program.
E

If you use this message as an input, note it is 90 characters long plus crlf = 92
$GPGGA,BASEDEGREE.00, 1000.00000, N, 00100.00000, W, 1, 10, 0.94, 000.0, m, 47.8, m,, * 47


Your buffer is only 80 long!
Dim str1(95) As Byte 'UART RXD buffer array

There is also an over length buffer error trap.
getmsg: 'read and save GPGGA msg
If PIR1.RCIF = 0 Then Goto getmsg
char = RCREG
str1(rxi) = char
rxi = rxi + 1
If rxi > 95 Then Goto get_neo 'msg bfr over run
'If char = 0x3f Then Goto eomsg '(0x3f = ?)SIM>>>>>>>>>>>>>>>>>>>>>>>>>>>.
If char = 0x0a Then Goto eomsg '(0x0a = LF)CIRCUIT>>>>>>>>>>>>>>>>>>>>>>>>
Goto getmsg
eomsg:
If rxi < 60 Then 'invalid msg
Goto get_neo
Endif

'$GPGGA,BASEDEGREE.00, 1000.00000, N, 00100.00000, W, 1, 10, 0.94, 000.0, m, 47.8, m,, * 47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'
 

camerart

Active Member
Hi Eric,
Is this ok?

Dim str1(95) As Byte 'UART RXD buffer array

There is also an over length buffer error trap.
getmsg: 'read and save GPGGA msg
If PIR1.RCIF = 0 Then Goto getmsg
char = RCREG
str1(rxi) = char
rxi = rxi + 1
If rxi > 95 Then Goto get_neo 'msg bfr over run
'If char = 0x3f Then Goto eomsg '(0x3f = ?)SIM>>>>>>>>>>>>>>>>>>>>>>>>>>>.
If char = 0x0a Then Goto eomsg '(0x0a = LF)CIRCUIT>>>>>>>>>>>>>>>>>>>>>>>>
Goto getmsg
eomsg:
If rxi < 60 Then 'invalid msg
Goto get_neo
Endif

C.

Hi C.
You say that you are using the list of test messages at the end of the program.
E

If you use this message as an input, note it is 90 characters long plus crlf = 92
$GPGGA,BASEDEGREE.00, 1000.00000, N, 00100.00000, W, 1, 10, 0.94, 000.0, m, 47.8, m,, * 47


Your buffer is only 80 long!
Dim str1(80) As Byte 'UART RXD buffer array

There is also an over length buffer error trap.
getmsg: 'read and save GPGGA msg
If PIR1.RCIF = 0 Then Goto getmsg
char = RCREG
str1(rxi) = char
rxi = rxi + 1
If rxi > 80 Then Goto get_neo 'msg bfr over run
'If char = 0x3f Then Goto eomsg '(0x3f = ?)SIM>>>>>>>>>>>>>>>>>>>>>>>>>>>.
If char = 0x0a Then Goto eomsg '(0x0a = LF)CIRCUIT>>>>>>>>>>>>>>>>>>>>>>>>
Goto getmsg
eomsg:
If rxi < 60 Then 'invalid msg
Goto get_neo
Endif

'$GPGGA,BASEDEGREE.00, 1000.00000, N, 00100.00000, W, 1, 10, 0.94, 000.0, m, 47.8, m,, * 47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
'
 

camerart

Active Member
Hi,
I've changed the 'over length buffer trap to the above settings, with the same result.
I'm guessing that the problem may be to do with having the serial port FTDI cards connected to the USB, so the power is never off. I have had similar problems before.
Once I get the simulation working by repeating the start-up procedure, is stays working ok, until disconnected. I can work with that.
Thanks.
C.
 

ericgibbs

Well-Known Member
Most Helpful Member
hi,
You could do that, but why are you using such a long ,BASEDEGREE.00 field in the string.?
E

Update:
Why are there Spaces in the message.??
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top