Picaxe 20X2 unrequested RESET @ 31KHz, using LOOKUP

PhilHornby

Senior Member
Probably not a combination that happens very often, but the following program demonstrates an unrequested RESET @ 31KHz, using the LOOKUP statement. I've only tested it on the 20X2. It works in the simulator, but not on the real chip.

Code:
[COLOR=navy]#picaxe [/COLOR][COLOR=black]20x2[/COLOR]
[COLOR=navy]#terminal 9600
#no_data[/COLOR]
[COLOR=green]; Demonstration of RESET @ low frequency 
      [/COLOR][COLOR=blue]pause [/COLOR][COLOR=navy]2000[/COLOR]
[COLOR=blue]do    
      sertxd (cr[/COLOR][COLOR=black],[/COLOR][COLOR=blue]lf[/COLOR][COLOR=black],[/COLOR][COLOR=red]"START"[/COLOR][COLOR=blue])
      setfreq K31
      [/COLOR][COLOR=green];
      ; Takes 1.7 seconds to execute!
      ;
      [/COLOR][COLOR=blue]lookup [/COLOR][COLOR=purple]b0[/COLOR][COLOR=black],[/COLOR][COLOR=blue]([/COLOR][COLOR=red]"xxxxxxxxxxxxxxxxxxxx"[/COLOR][COLOR=black], _
                 [/COLOR][COLOR=red]"xxxxxxxxxxxxxxxxxxxx"[/COLOR][COLOR=black], _
                 [/COLOR][COLOR=red]"xxxx"[/COLOR][COLOR=blue])[/COLOR][COLOR=black],[/COLOR][COLOR=purple]b1               [/COLOR][COLOR=green];64 Bytes
      [/COLOR][COLOR=blue]setfreq M8
      sertxd (cr[/COLOR][COLOR=black],[/COLOR][COLOR=blue]lf[/COLOR][COLOR=black],[/COLOR][COLOR=red]"1st lookup done"[/COLOR][COLOR=blue])
      setfreq K31
      [/COLOR][COLOR=green];
      ; Some combination of frequency and size of lookup data, 
      ; causes Picaxe to restart.
      ;
      [/COLOR][COLOR=blue]lookup [/COLOR][COLOR=purple]b0[/COLOR][COLOR=black],[/COLOR][COLOR=blue]([/COLOR][COLOR=red]"xxxxxxxxxxxxxxxxxxxx"[/COLOR][COLOR=black], _
                 [/COLOR][COLOR=red]"xxxxxxxxxxxxxxxxxxxx"[/COLOR][COLOR=black], _
                 [/COLOR][COLOR=red]"xxxxxxxxxxxxxxxxxxxx"[/COLOR][COLOR=black], _
                 [/COLOR][COLOR=red]"xxxxX"[/COLOR][COLOR=blue])[/COLOR][COLOR=black],[/COLOR][COLOR=purple]b1              [/COLOR][COLOR=green];65 Bytes
;
; With parameters as shown, this is part of the program is never executed.
;
; It is, if either of the following parameters are changed :-
;
; Setfreq M31 -> Setfreq K500
; Final "X" removed from lookup data string (shorten string to 64bytes)
;
      [/COLOR][COLOR=blue]setfreq M8
      sertxd (cr[/COLOR][COLOR=black],[/COLOR][COLOR=blue]lf[/COLOR][COLOR=black],[/COLOR][COLOR=red]"NEVER REACHED"[/COLOR][COLOR=blue])
loop[/COLOR]
My guess (FWIW), is that some timer or other is expiring before the
LOOKUP statement completes.


 

Attachments

Last edited:

AllyCat

Senior Member
Hi,

Yes it will be the PIC's "Watchdog Timer" which PICaxe uses as the "Sleep" timer. The Watchdog always runs from its own timer (~31kHz) and activates after about 2.1 seconds (the nominal Sleep time), causing a Reset if any single instruction takes more than ~2 seconds to execute. I discovered that with a (non-completed) PULSIN at a 1 MHz clock frequency on a M2. (i.e. the normal timeout would be 2.6 seconds).

There are various ways to over-ride the Watchdog timer by using a POKESFR, either to disable it or to increase its delay time.

Cheers, Alan.
 
Last edited:

Technical

Technical Support
Staff member
As allycat says it is a feature rather than a bug, no (non-pause) command is expected to take longer than the deliberate watchdog safeguarding timeout @ 2.1 seconds.

Of course the solution here is to not use lookup at such a low clock speed!
 

PhilHornby

Senior Member
There are various ways to over-ride the Watchdog timer by using a POKESFR, either to disable it or to increase its delay time.
I assume it's not do-able on the 20X2/18F1XK22...
Code:
[COLOR=blue]
      peeksfr [/COLOR][COLOR=navy]$d1[/COLOR][COLOR=black],[/COLOR][COLOR=purple]b0
      [/COLOR][COLOR=blue]sertxd (cr[/COLOR][COLOR=black],[/COLOR][COLOR=blue]lf[/COLOR][COLOR=black],[/COLOR][COLOR=red]"Initial WDTCON="[/COLOR][COLOR=black],#[/COLOR][COLOR=purple]b0[/COLOR][COLOR=blue])
      pokesfr [/COLOR][COLOR=navy]$d1[/COLOR][COLOR=black],[/COLOR][COLOR=navy]0
      [/COLOR][COLOR=blue]peeksfr [/COLOR][COLOR=navy]$d1[/COLOR][COLOR=black],[/COLOR][COLOR=purple]b0
      [/COLOR][COLOR=blue]sertxd (cr[/COLOR][COLOR=black],[/COLOR][COLOR=blue]lf[/COLOR][COLOR=black],[/COLOR][COLOR=red]"New WDTCON="[/COLOR][COLOR=black],#[/COLOR][COLOR=purple]b0[/COLOR][COLOR=blue])[/COLOR]
The SWDTEN bit changes - but the issue remains.

Code:
Initial WDTCON=1
New WDTCON=0
The datasheet implies that if WDTTEN is set in CONFIG2H, SWDTEN has no effect. Unsurprisingly, I appear to have no access to CONFIG2H :(
 

AllyCat

Senior Member
Hi,

I don't know because I have never used X2s. But have you tried changing the delay counter bits beyond the default 2 seconds delay?

In principle it should be possible (as it is with M2s), but I do remember a recent thread that indicated it's impossible to use the FVR in the 20X2 because the PICaxe OS "stamps all over" the relevant SFR (even though there seems to be no reason why it needs to).

However, as technical said, there's not often much need to use low clock frequencies: For lowest power consumption, a "burst" mode with intermediate sleep/naps between normal (or even elevated) clock frequiency appears to be more efficient. Or to measure the execution time of individual (or small groups) of instructions, I prefer to use the "Timer 1" method (post #12 here) that I devised several years ago (again only tested with M2 SFR commands, but probably adaptable to X2s).

Cheers, Alan.
 
Top