PDA

View Full Version : Unexpected PIC reset (probably when byte variable overflows)



Bruce
- 2nd September 2011, 12:26
It sounds to me like PBP does not reset WDT for all instances. I.E. if you have only a simple loop, incrementing or decrementing a variable, with no PBP commands in the loop, you have a WDT reset.

PBP will reset WDT in most command routines, but with something so simple, without any PBP library routines invoked, it may not be resetting WDT!

And - why the heck did this reply end up as the 1st post magically? It was posted after post #6?

HenrikOlsson
- 2nd September 2011, 17:44
Hi,
I've got a problem I can't seem to wrap my head around...
The PIC I'm using is a 18F4520 and when I discovered the problem I was compiling with 2.6A but have now switched to 3.0.1.4

Running the following code:

DEFINE OSC 8

#CONFIG
CONFIG OSC = HS
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRT = ON
CONFIG BOREN = OFF
CONFIG WDT = ON
CONFIG WDTPS = 512
CONFIG CCP2MX = PORTC
CONFIG PBADEN = OFF
CONFIG LPT1OSC = OFF
CONFIG STVREN = OFF
CONFIG MCLRE = ON
CONFIG LVP = OFF
CONFIG XINST = OFF
CONFIG DEBUG = OFF
#ENDCONFIG

i VAR BYTE

High PortD.0 : Pause 500 : Low PortD.0
i = 0

Main:
i = i + 1
PauseUs 20
Goto Main
Everything works as expected, and with everything I mean nothing happens really. PortD.0 pulses on startup and then it sits there doing "nothing" (I've waited for ~5 minutes, you'll understand why soon.)

However, if I reduce the PauseUS to 10 or remove it completely the program restarts (PortD.0 pulses) roughly 22 times per second. (I know PauseUs 10 is border line on the specified miniumu of 9 for a 18F chip at 8Mhz) but why does it restart? And why does it restart if I remove it all together?

This works:

Main:
i = i + 1
If I = 255 Then i = 0
Goto Main
While this restarts the PIC once every 3rd second:

Main:
i = i + 1
Goto Main
The variable i is declared as a BYTE as can be seen above. It "feels" like it has something to do with i overflowing but why and why does it matter if I pause 20us?

What am I doing wrong here? 18F4520, PBP 3.0.1.4, MPLAB 8.73a/MPASM 5.42, compiling for the correct chip from MCSP 5.0.0.0.

Thanks!
/Henrik.

HenrikOlsson
- 2nd September 2011, 18:21
Damn edit "window" timed out allready....anyway...
This too works, no restart:


Main:
For i = 0 to 255
NEXT
Pause 1
Goto Main

While this doesn't

Main:
For i = 0 to 255
NEXT
Goto Main

However, this works:

Main:
For i = 0 to 254
NEXT
Goto Main

/Henrik.

pedja089
- 2nd September 2011, 18:23
MPASM 8.73 have some bug's, try 8.76...

Bruce
- 2nd September 2011, 18:55
What happens if you change CONFIG WDT = ON to CONFIG WDT = OFF?

HenrikOlsson
- 2nd September 2011, 19:59
Turning off the watchdog makes it work so that's what's resetting it for sure...

The original code, where I notices it is like this:

Main:
i = i + 1
Gosub GetValue
PortB = Out
Goto Main
Then the subroutine GetValue is a lookuptable with 255 entries returning the value in Out. It too restarts when the dog is unleashed. However, if I add IF i = 255 then i = 0 at the end it works. I then tried to boil that down to the minimum, which is what I posted above.

So, is this an oversight on my behalf or an unwated side effect of a "tight" (it's not THAT tight) program?

In any case, thanks Bruce!
/Henrik.

mister_e
- 2nd September 2011, 20:29
How your lookup table looks like?

I could be wrong but probably the generated asm for the IF/THEN have some CLRWDT while the lookup don't?