Well, I was hoping for more of what the program needs to do, instead of why it doesn't work the way you have it. But if I make a few assumptions I guess we can go from there.
Assumption 1 - The only thing the elapsed timer will be used for, is timing the 500ms periods.
Assumption 2 - The on/off cycle times are the same. 500ms ON, 500ms OFF. And repeats continuously untill it's determined that it needs to stop.
I believe the key here is in Starting the Elapsed Timer at the beginning of the alarm cycle so that it always starts at 0. That way you don't have to subtract the starting Ticks count from the current Ticks count. Al you'll need to do is test if it's less than 50.
Something like this...
Code:
Clear
Include "Elapsed.pbp"
AlarmOUT VAR PORTB.0
AlarmON VAR BIT
;----------------------------
MainLoop:
; Somewhere in here determine when to turn on/off alarm
; and Gosub to either StartAlarm or StopAlarm
if AlarmON and (Ticks < 50) then
HIGH AlarmOUT ' Alarm ON
else
LOW ALARMOUT ' Alarm OFF
endif
Goto Mainloop
;----------------------------
StartAlarm:
Gosub ResetTime ' Reset Time to 0d-00:00:00.00
Gosub StartTimer ' Start the Elapsed Timer
AlarmON = 1
Return
;----------------------------
StopAlarm:
Gosub StopTimer
AlarmON = 0
Return
HTH
<br>
Bookmarks