setfreq test
I tried to use “setfreq” to measure low RPM, but I seem to be having problems with time.
To test the idea, I first tried to get baseline data at 4 MHz. I compared the “timer” variable with an external clock. It was fairly good, only losing a few seconds after about 5 minutes. I think playing with “settimer” and changing the preload around “t1s_4” may improve things, but I’m not really that interested in time (other than RPM).
Next, I sent the Picaxe a pulse about once a second. This should give an RPM of around 60. If my math is ok (??), then I should be able to measure RPM from the time between pulses (PulseTime) using the pulsin function:
Time (in secs) = PulseTime / 100000
RPM = 60 / Time(in secs)
so
RPM = 6000000 / PulseTime
Here’s the code I used:
SYMBOL RPM = w4
SYMBOL PulseTime = w5
SYMBOL PulseCount = W13
settimer t1s_4 ; timer = seconds at 4MHz
PulseCount = 0
rpmtest:
pulsin 5, 0, PulseTime ; PulseTime = time between pulses.
If PulseTime > 0 then ; is PulseTime valid (i.e. >0)
PulseCount = PulseCount + 1
endif
w0=PulseTime/100 ; I only need 3 digits for RPM
RPM = 60000/w0
if timer >= 60 then ; reset timer if >60 secs.
timer = timer - 60
endif
sertxd(13,10, #PulseTime, " ",#RPM, " ",#PulseCount," ",#timer)
goto rpmtest
A sample of my results:
PulseTime, RPM, PulseCount,Seconds
-----------------------------------------------
42812 140 2 2
41979 143 3 3
48176 124 4 4
47459 126 5 5
48332 124 6 6
42072 142 7 7
53686 111 8 8
41980 143 9 9
42981 139 10 10
39694 151 11 11
50256 119 12 12
45632 131 13 13
The measured RPM is about 2.2 times higher than I expected at 4 MHz. If I add the line
RPM = RPM * 10 / 22
then RPM hovers around 60, what I expected. Am I missing something here (i.e. math, software, circuit, …), or do I need to calibrate the “pulsin” function?