I have never used the M2 elapsed time counter. The following code is my attempt to understand and use this M2 feature. I believe that the code will consistently yield a 10 second timer. However there will be some additional amount of time (probably u seconds) while the chip recognizes that time is no longer <10 (when code on line 18 ends the loop); until time is set to zero (code line 19). Probably will be minute variations from chip to chip. Not sure how to calculate or measure this additional time. Will appreciate comments to help me understand this. Thank you, JimS
Code:
'***********************************************
'* 20m2 uses the internal 1 second "time" counter.
'* Sequence repeats every 10 seconds.
'***********************************************
symbol OLED = B.4
symbol RLED = B.6
symbol GLED = C.2
#picaxe 20m2
pause 1000 'Initialize system.
enabletime 'Enable & start the elapsed time counter.
time=0 'Reset "time counter" to zero.
main:
do
call do_stuff
serout OLED,n2400,(254,1):pause 30 'Clear OLED
do
pause 1
loop while time < 11 'wait until 10 seconds have elapsed. 'This is line 18.
time=0 'Reset "elapsed time counter" to zero. 'This is line 19.
loop
'* Simulates code doing something.
'* Bicolor RG/LED is red and OLED message
'* shows while doing "stuff".
do_stuff:
high B.6:low C.2 'Turn RED LED ON.
serout OLED,n2400,(254,128,"Doing STUFF")
pause 4000 'Waste 4 seconds here.
low B.6:low C.2 'Turn RED LED OFF.
return
Last edited: