background time counting
science_geek
Posts: 247
im looking to count the clock cycles, i know that i have to use CNT so i have num1 := cnt, in the next line is the display output that runs to my display, but the display is showing a 2?0(the question mark is a flashing number that i cant read)
what i want to do is count the clock ticks between inputs from a sensor so that i can calculate rpm and other data, a friend and i converted a small gasoline engine to run on compressed air, and now we need to take measurements, i am going to have a prop collect sensor data, do some calculations and then send it wirelessly to the handheld i made from a seperate prop, but a timer is a must.
what i want to do is count the clock ticks between inputs from a sensor so that i can calculate rpm and other data, a friend and i converted a small gasoline engine to run on compressed air, and now we need to take measurements, i am going to have a prop collect sensor data, do some calculations and then send it wirelessly to the handheld i made from a seperate prop, but a timer is a must.
Comments
<initialization>
startTime := CNT
<do something>
elapsedTime := CNT - startTime
Now we have the time in clock ticks. You can convert it to any unit you want. For example, to
get the elapsed time in milliseconds, you divide by CLKFREQ/1000
In general:
Of course it might be rasonable to have an alternating time between two measurements. In such a case it is nonsense to display each and every result of your clock tick measurement. I'd only show the average in this case or only do updates of the displayed value if the deviation is bigger than a certain value. If the values are close, you could refresh the display each second· - even if you do the measurement more often for example for regulation.
Post Edited (MagIO2) : 3/11/2009 12:24:37 PM GMT