Spin Language - Monitoring system clocks ticks
JoeFL
Posts: 10
I'm fairly NEW to Spin, but picking it quite quickly. I know about the waitcnt() function where one
can wait a certain amount of time before program execution is continued.
I would like to be able to monitor the amount of system clock pulses/ticks since a certain event has happened without pausing program execution.
For instance, if an event has happened, not necessarily a Port event, I would like to be able to execute another event at a certain number of clock cycles since that event.
Say ... Time_Mark := cnt
Time_Mark_1/4sec := cnt + clkfreq/4
I'd like to be able to test whether Time_Mark_1/4sec has been reached.
can wait a certain amount of time before program execution is continued.
I would like to be able to monitor the amount of system clock pulses/ticks since a certain event has happened without pausing program execution.
For instance, if an event has happened, not necessarily a Port event, I would like to be able to execute another event at a certain number of clock cycles since that event.
Say ... Time_Mark := cnt
Time_Mark_1/4sec := cnt + clkfreq/4
I'd like to be able to test whether Time_Mark_1/4sec has been reached.
Comments
or You can't do a simple "is-current-time-greater-than-target-time" because the clock only holds 32 bits, thus it rolls over, and it is signed, so you would get anomalous instantly true or always false problems.
if you don't want to wait by using waitcnt, you can simply poll the value of cnt as it is by definition the counter of system clock pulses.
So to your code above, you can use : if ( cnt >= Time_Mark_1/4sec ) to detect if that time has been reached