PDA

View Full Version : Restart 18F2620



cerio
- 25th June 2007, 15:17
I ask aid, I do not know English well. Use PBP2.46 and MPLAB v7.50 the circuit works well with 16F876. The connected PIC to Wawecom Q2501ed to the PC. They are passed to the 18F2640. The program from time to time restart and I do not understand the cause, as it is made has to find the cause of the restart? I enclose the SW and the rows 18F2620.INC modified. Salutes to all thanks
Report PC
Fine Inizializzazione
StatoQ2501 OK
Tensione= 3,377
GestioneSŤS <---- non corrected ?
StatoQ2501 OK
Tensione= 3,377
.
.
.
Tensione= 3,377
GestioneSMS
StatoQ2501 OűStartup Startup <---- SW restart
Fine controllo RTS/CTS
Rete GSM OK
CBST OK
Fine Inizializzazione
StatoQ2501OK
Tensione= 3,377
GestioneSMS
3StatoQ2501 OK <---- non corrected ?
Tensione= 3,377
GestioneSMS
StatoQ™501 OK <---- non corrected ?

.
.
.
GestµoneSMS <---- non corrected ?
StatoQ2501 OK
Tensione= 3,377
GestioneSMS
StaStartup Startup <---- SW restart
Fine controllo RTS/CTS
Rete GSM OK
CBST OK
Fine Inizializzazione
StatoQ2501 OK
.
.

Archangel
- 26th June 2007, 05:38
Hello cerio,
Your English is good enough it seems. I have questions about your power supply and the load you have hooked up to your PIC. Is there a posibility you are drawing too much current on an output or on your power supply? I see you have disabled BODREN. Your MCLRE pin, Is tied to +, yes ? Through what ohm value resistor? I would add a .01 uf capacitor to the power pins directly at the PIC and perhaps, a large capacitor of say 50uf as a transient buffer too.
HTH
JS
EDIT: one last thought, if you are having this problem on a breadboard, IT may be the problem.

milestag
- 26th June 2007, 13:31
I had a similar problem when moving from 16F to 18F. Finally I discovered it was a STACK OVERFLOW reset. The 16F does not care if you overflow the stack, but the 18F does!

If you call a subroutine (GOSUB) and you do not RETURN from that subroutine, because of a GOTO or IF-THEN or TimeOut within the subroutine (looks like you have them), then the last address PUSHed onto the stack does not get POPped from the stack and it eventually overflows causing a reset.

If you exit the subroutine without a RETURN, then you must manually POP the stack. (I also use the STKPTR = 0 in some parts of the program, though I know this is cheating a bit).

So... anytime you are exiting a subroutine early (not using Return) you should POP the stack:

@ POP

On the 16F you can keep pushing onto the stack with no problems, so you never see the problem until you move to an 18F chip.

I'm sure someone else here can provide a more detailed (accurate?) explanation of the 18F stack pointer, but I hope this at least helps you in the right direction.

Jim

peterdeco1
- 26th June 2007, 18:22
Am I correct that this can be used to cancel a GOSUB? Thank you.

start:
gosub blink
do more stuff here

blink:
if porta.1 = 1 then sound
high porta.0
pause 50
low porta.0
return

sound:
@ POP
make sound on a pin
goto start

CocaColaKid
- 26th June 2007, 20:54
I believe this is correct. I ran into this problem when I switched from a 16F877 to the 18F452. Took a little bit to track it down. The 16F masked my bad coding practice quite well, lol.

milestag
- 26th June 2007, 21:44
Peter, yes I would say that is correct (or at least one way to do it). I suppose there are no hard and fast rules per se, but any Programming 101 professor would surely beat us with a stick for exiting a GOSUB with a GOTO rather than RETURN with a flag set or some other method.

CCK, Same here, I spent MANY hours headscratching over that one. Until I discovered that the processor always reset after exactly the same number of calls to a certain subroutine. Lots of time spent reading the datasheets/forums too. All resulting from poor (untrained) programming practices/bad habits. But learned a LOT in the process. 18F definitely has a few "gotchas" when migrating.

peterdeco1
- 27th June 2007, 10:07
Thank you for the fast replies guys. Are you also saying that if you don't cancel a gosub with a return on the 16F parts, it doesn't matter? I am not in the habit of doing this but, as a quick fix to a program, it would be handy to know. I was told it will eventually cause a stack overflow on any PIC. Thank you. - Peter

sinoteq
- 27th June 2007, 11:06
You could test to disable the Stack reset in the configuration bits, that should prevent the MCU from doing a reset when doing a stack under- or overflow. Simple and easy but be aware that a return later in the code can make stange things. Page 253 in the manual if you want to look CONFIG4L register.

cerio
- 27th June 2007, 14:29
Power supply: 3.6V current peaks of up to 2° and a maxximum voltage drop of 300mV durino transmission burst. Local power source feeds the Q2501 module and the PIC 18f2620.
Connection MCLRE pin – Diode –R 11Kohm – Vcc. I use one breadboard.
Hour we come to the good news: inserted condenser from 0,1 uf. They are some hours that software turn without restart. The strange characters between the PIC and the PC are passings also. Thanks. Perhaps resolved problem