Half Second TImer

Rauwomos

New Member
Hi,

I am a newbie to the picaxe. I am trying to use the settimer funtion to jump out of a loop to make a beep sound every half a second. I have looked at some of the other posts, however none of them make any sense to me. I can use the settimer function before, so i know the basics. I would be delighted if anyone could help.

Thanks
 

nick12ab

Senior Member
The settimer function is just a command to turn on the timer and give it a pre-load value as described in the manual. The manual states constants: t1s_4, t1s_8 and t1s_16 which give the timer a 1-second interval at the speed in MHz shown after the _ (4, 8 or 16) so for half a second you just use the next constant down so that would be t1s_8 at 16MHz etc.

If the loop executes fast then a simple 'if timer >= 1 then : timer = 0 : goto whatever : end if' will do.

There's also a timer overflow flag which could be used with an interrupt, however it is for overflow of the timer variable itself so you'd need to calculate your own preload value to get that to happen every half second. Look for toflag under setintflags in PICAXE Manual 2.
 
Top