restart counter CNT
Fab
Posts: 3
Hello,
Is it possible to restart to zero the counter cnt of the propeller, or I should use the ctra or crtb ?
I measure a duration in a repeat loop and i have some problems. I think that sometimes i'm at the end of the counter
thank you
Post Edited (Fab) : 7/13/2010 7:54:14 AM GMT
Is it possible to restart to zero the counter cnt of the propeller, or I should use the ctra or crtb ?
I measure a duration in a repeat loop and i have some problems. I think that sometimes i'm at the end of the counter
thank you
Post Edited (Fab) : 7/13/2010 7:54:14 AM GMT
Comments
startCnt:= CNT
' do your stuff
endCnt := CNT
ticks := endCnt - startCnt
time := ticks / clkfreq
You start having problems, when the part in 'do your stuff' takes longer than ~52 seconds because then the counter will overflow and start from the beginning again.
The counters and CNT are nicely explained not only in the manual but also in the application note about the counters (AN001 ?). But what MagIO2 wrote may just what you need. Do not forget the overhead that reading the CNT register has (you get that value just reading two times the CNT in a row).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
pPropellerSim - A propeller simulator for ASM development sourceforge.net/projects/ppropellersim
I have 2 sensors and I want to compare the duration between two rising edges ( on "pin" ) on each sensor[noparse][[/noparse]code]
Post Edited (Fab) : 7/13/2010 5:10:04 PM GMT
I actually found my error, during the calculation I had to use floats variables and I did not define the object FloatMath.
effectively the counter restart but don't affect the difference between start and end.