I have been having trouble understanding the timer maths. I would like the timer to count in milliseconds at 8 MHz.
At 8Mhz a minor tick takes 32us so 1ms would need 1000/31 or 31,25 mnor ticks. So compromising on 31 ticks should give 0.992 ms which is good enough. So the preload value should be 65536-31 or 65505. So after 0.992 seconds i would expect the timer to read 1000. In order to achieve a 1 second loop the timer should read 1000/0.992 or 1008. Something must be wrong with this logic because the code below takes 1,2 seconds per cycle timing the Led flashing with a stopwatch over 20 cycles. I realise that there must be some overhead inbetween reading and resetting the time but 200ms seems excessive - where have I gone wrong !
' 28x1 timer experiment
setfreq m8
symbol looptime = 1008
autoloop:
settimer 65505
timer = 0
high 4
pause 100
low 4
do
loop while timer<looptime
goto autoloop
Â
At 8Mhz a minor tick takes 32us so 1ms would need 1000/31 or 31,25 mnor ticks. So compromising on 31 ticks should give 0.992 ms which is good enough. So the preload value should be 65536-31 or 65505. So after 0.992 seconds i would expect the timer to read 1000. In order to achieve a 1 second loop the timer should read 1000/0.992 or 1008. Something must be wrong with this logic because the code below takes 1,2 seconds per cycle timing the Led flashing with a stopwatch over 20 cycles. I realise that there must be some overhead inbetween reading and resetting the time but 200ms seems excessive - where have I gone wrong !
' 28x1 timer experiment
setfreq m8
symbol looptime = 1008
autoloop:
settimer 65505
timer = 0
high 4
pause 100
low 4
do
loop while timer<looptime
goto autoloop
Â