danners430
Member
Happy Friday!
I was wondering if someone on here would be able to confirm something for me:
I'm planning on using a relatively simple method for having timed functions carried out by the picaxe, while still scanning pins etc. For example, when a pin is detected to be high, 2 minutes later the picaxe sets another pin high. If the input pin is set to low, the output is immediately turned off, and the timer reset.
In my big program, I'll have multiple functions using the timer at once, so the functions store the value of the timer when the functions is originally called, then find the difference between the "realtime" timer value and the stored value.
My question is, however, if and when the timer overflows, would the calculations still work? From my reading, the maths should also simply overflow, so for example 10-245 = 20. Could someone confirm this?
I was wondering if someone on here would be able to confirm something for me:
I'm planning on using a relatively simple method for having timed functions carried out by the picaxe, while still scanning pins etc. For example, when a pin is detected to be high, 2 minutes later the picaxe sets another pin high. If the input pin is set to low, the output is immediately turned off, and the timer reset.
In my big program, I'll have multiple functions using the timer at once, so the functions store the value of the timer when the functions is originally called, then find the difference between the "realtime" timer value and the stored value.
My question is, however, if and when the timer overflows, would the calculations still work? From my reading, the maths should also simply overflow, so for example 10-245 = 20. Could someone confirm this?
Code:
'b0 = number of procedures using timer
'w2 = timer in multiples of 25ms
main:
if pinB.1 = 1 then
call sampleTimerFunction
else
call endTimeruse
end if
'insert additional functions here
call timer
goto main
end
timer:
if b0 = 0 then 'if no functions are using timer, reset to 0 and return
w2 = 0
return
end if
pause 25 'wait for 25 ms and add 1 to timer value
w2 = w2 + 1
return
sampleTimerFunction:
'b1 = has function passed the initial stage?
'w3 = repository for timer value when function is initially called
'b2 = latch
if b1 = 0 then
w3 = w2 'store initial timer value
b0 = b0 + 1 'add this function to the "list" of functions currently using the timer
b1 = 1 'skip this stage next time function is called
end if
if w2 - w3 = 4800 or b2 = 1 then 'have 120s elapsed?
high B.0 'do something
b2 = 1 'set latch - program will now always do the above until it is reset
end if
return
endTimerUse:
b0 = b0 - 1 'remove this function from the "list" of functions currently using the timer
b2 = 0 'reset latches from sampleTimerFunction
b1 = 0
w3 = 0 'clear stored time value
low B.0 'end whatever was started when the timer elapsed
return