mS timer using a 20M2?

Armp

Senior Member
I have need to measure a pin delay of a couple of seconds with a 20m2. I need mS resolution but not mS accuracy.
If I had an X2 I could use timer3, but I don't - so how do I do it?

I tried using a pause statement, terminated by an interrupt.

In the case of the interrupted pause, wait, play or tune command, any remaining time delay is ignored and the
program continues with the next program line.
But I have found no way of reading the remaining elapsed time.

setint input,mask
pause 10000 ' times out at 10 secs, but drops on interrput
w3 = 10000 - whats_left

Its possible that 'whats_left' is in a register somewhere?

Also found:
The M2 series have an internal elapsed time counter. This is a word variable called
‘time’ which increments once per second.
Is there a readable prescaler that drives this timer? That would help a lot!

Any thoughts, tricks or suggestions?
 

hippy

Ex-Staff (retired)
You could try determining "what's left" by using shorter pauses and a loop, set a flag in the interrupt which terminates the loop. Might require some tweaking ...

timeLeft = 10000
flagVar = 0
Do
timeLeft = timeLeft - 100
Pause 100
Loop Until flagVar <> 0 Or timeLeft = 0
 

Armp

Senior Member
hippy - I had previously tried this, works but not mS and had to be 'calibrated'.

Ptime = 0
Do
Inc Ptime
Loop Until flagVar <> 0 Or Ptime = 0

I also tried LOOPing until pin=1, not using interrupts at all - but INTs gave a little more flexabilty for debug.

Technical - doesn't Pulsin require 2 edges? I need to catch the first transition.

I'll just have to dig out a map of the M2s SFR and play I guess...

Thanks anyway
 
Last edited:
Top