20M2 - using an idle timer

Chris Kelly

Well-known member
Hi guys

I'm using a 20M2 with an external clock input, which then triggers an output pin to light a few LEDs.

The clock is manually introduced to the circuit and so there might be long periods of time where I'd like the LED to remain off, when the clock isn't being used.

I'd like this time period to be at least 1 minute before the picaxe realises there has been no clock input.

Is the SET TIMER set of commands the most appropriate way of achieving this?

Thanks

Chris
 

Buzby

Senior Member
My solution would be something like this ...

Code:
if ext_clock_detected then
    do clocked LED stuff
    time = 0 ' reset time if ext_clock detected
endif

if time > 60 then ' i.e time has not been reset for 60 sec
   stop doing clocked LED stuff
   time = 60 ' this is to stop time overflowing if no clock pulse for 66536 seconds !
endif
Cheers,

Buzby
 

lbenson

Senior Member
On the M2 PICAXEs, you have the "time" variable available--a seconds counter which begins when your program starts.

So you can have something like this:

w6=time+60 ' one minute at 4mHz
do ' your main loop
if time => w6 then ' your time has expired
' . . . what you want to do
endif
' . . . your main loop code
loop

You can have as many of these "w6" time limits as you have variables (or available RAM if you need lots).

Just note that some commands interfere with time, so its utility will depend on what else you are doing.

(And note as Buzby alludes to, if time is free-running, you have to do something about the fact that time will wrap back to 0 after about 18 hours.)
 
Last edited:
Top