Duration counter
Hello,
i have another question
what I am doing is running a repeat for 1 second, during that one second i collect data, then break out using a repeat while, then I post a message and reset for the next second of reading
the issue that seems to be occuring is that most of the time, I get 1 second intervals, but every so off i get a burst of messages, as if the repeat while is being by passed.
I thinik it is the way I set up the one second interval. loop and the test are wrong
Here is the code
I tried different ways, but the results is usually the same. most of the examples I have seen are using waitcnt for delays, but I want to process during the second, and not delay
regards
Jeff
i have another question
what I am doing is running a repeat for 1 second, during that one second i collect data, then break out using a repeat while, then I post a message and reset for the next second of reading
the issue that seems to be occuring is that most of the time, I get 1 second intervals, but every so off i get a burst of messages, as if the repeat while is being by passed.
I thinik it is the way I set up the one second interval. loop and the test are wrong
Here is the code
{Object_Title_and_Purpose}
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
VAR
long Transition_counter
long pin_state
long previous_pin_state
long GPM
long GPM_temp
long Dt
long record_number
long t
OBJ
term : "FullDuplexSerial"
fMath : "FloatMath"
' fMath : "Float32full"
fString : "FloatString"
PUB Main
term.start(31, 30, 0, 115200)
record_number := 1
t := 0
dira[8]~ ' set to input := 0
dT := clkfreq
repeat
term.tx(13)
term.str(string(" Rec Num: "))
term.dec(record_number)
record_number++
t := clkfreq + cnt ' get next second
repeat while cnt < t ' loop until second is up
pin_state := ina[8] ' check high or low
if pin_state == previous_pin_state
'do nothing
else
previous_pin_state := pin_state ' make new pin state
transition_counter++ ' and count the transision
I tried different ways, but the results is usually the same. most of the examples I have seen are using waitcnt for delays, but I want to process during the second, and not delay
regards
Jeff

Comments
works fine now, no runaway output
New code
t := cnt repeat while (cnt - t) < clkfreq pin_state := ina[8] ' check high or lowold code (which did not work)
regards
Jeff