Hi,
For part of my "project" I need to measure quite accurately the width of a pulse which occurs once every 48 seconds. Power consumption is very critical as it must run 24/7 on a pair of AA cells.
So, using PULSIN (and subsequently PULSOUT or COUNT) with a clock frequency of 31kHz, for the period between the pulses, seemed the obvious solution (since Sleep and Nap have such terrible tolerance timing errors). However, the code runs fine on the simulator and with a clock frequency of 2MHz and above, but crashes (repeatedly resets to the start address) at 1MHz and below.
I've found a couple of old threads which suggest that the watchdog timer is responsible. In those threads the terms "underclocked" and "hacked speed" are used, but 31kHz is a completely "legitimate" clock speed for the M2 series. I do see that the manual only explicitly refers to "Effect of Increased Clock Speed" for PULSIN, but I would have expected at least a comment if the command is flawed at lower frequencies.
Is it the Watchdog Timer that is responsible and are there any workarounds?
Thanks,
Alan.
For part of my "project" I need to measure quite accurately the width of a pulse which occurs once every 48 seconds. Power consumption is very critical as it must run 24/7 on a pair of AA cells.
So, using PULSIN (and subsequently PULSOUT or COUNT) with a clock frequency of 31kHz, for the period between the pulses, seemed the obvious solution (since Sleep and Nap have such terrible tolerance timing errors). However, the code runs fine on the simulator and with a clock frequency of 2MHz and above, but crashes (repeatedly resets to the start address) at 1MHz and below.
Code:
#picaxe 20m2
begin:
sertxd ("**START** ")
measure:
do
sertxd ("Loop ")
setfreq m1
pulsin b.7,0,delay
setfreq m4
sertxd (#delay," @m1 ")
loop
Gives an Output: **START** Loop **START** Loop **START** Loop 2503 @m1 Loop **START**
but at 2MHz: **START** Loop 0 @m2 Loop 0 @m2 Loop 0 @m2 Loop 5025 @m2 Loop
Is it the Watchdog Timer that is responsible and are there any workarounds?
Thanks,
Alan.