20x2 timer function similar to one on 14m2

alhoop

Member
I use the code below on a Picaxe 14M2 to count seconds between switch closures. Time can vary fron 1 to 22 seconds.
Will loop around keeponw until pinc.2 goes true.
Can this be done on the Picaxe 20X2 and if so how?
Thanks
Al

Code:
Start:
setfreq m4
pulsout b.3,10  ;reset
if pinc.1 = 1 then east
if pinc.2 = 0 then start
time = 0
let b0 = time
keeponw:
if pinc.1 = 0 then keeponw
let b1 = time
b1 = b1 - b0
readtable b1,b4
goto calc
 

inglewoodpete

Senior Member
Yes. The X2 series have an enhanced capability when compared to the M2 series. Firstly, would a 20M2 do what you want?

For the 20X2, you would add the SetTimer command in your initialisation code. X2 chips have a variable 'tick' length that must be configured. You would need to use the internal timer. The default speed of the 20X2 is 8MHz: if using that speed you would use the t1s_8 parameter, which makes configuration easy.
 
Top