Counting for a specified time?
Hello all! I was wondering if it is possible to count highs and lows on a certain I/O pin for a specific time in the same method. I would like to count low to high transitions for 10 seconds. Thanks in advance.
pub counter
repeat until (10 seconds pass)
waitpeq(%000000000,|<8,0)
waitpeq(%100000000,|<8,0)
counter1:=(counter1+1)
lcd.tx(158)
lcd.dec(counter1)
pub counter
repeat until (10 seconds pass)
waitpeq(%000000000,|<8,0)
waitpeq(%100000000,|<8,0)
counter1:=(counter1+1)
lcd.tx(158)
lcd.dec(counter1)
Comments
You would use one of the cog counters to count low to high transitions and read the PHS register for the counter after a wait of 10 seconds. It will take a few microseconds to read PHS after the 10 second WAITCNT finishes, so there's the possibility of low to high transitions happening (and being counted) during that time, but I suspect that's not a problem.
You'd use counter mode %01010 to increment on low to high transitions something like this:
(CLKFREQ / 10) = clocks per 1/10 second. And 100, 1000, etc... do other units of time.
So, if you want, say 5.5 seconds, you could do something like:
time := (CLKFREQ / 10) * 5.5 'total number of clocks in delay
Once you've got that done, then just add that to the counter, when you want your delay to start:
delay := cnt + time
Then do something like:
repeat until cnt > delay
put your high / low checks inside this loop, and it will tally them up, while the system counter also counts toward your delay value, exiting the repeat loop after the right amount of time has passed.
Look at P 219 of the Propeller manual. Time delays and such are detailed there, and are probably what you need.
You might want to download the application note on the counters (AN001).
Potatohead, that way of doing it is very interesting, and I played around with it a little.
Mike, thanks for the link I didn't realize those app notes were there. Printing it off now.
As you can both tell I don't know much about spin, and believe me I tryed many different attempts after browsing the prop manual, the Prop edu lab, and the official guide. Sometimes a guy needs a little push in a new direction. Things are getting a little clearer. Thanks again, much reading to do now.