Shop OBEX P1 Docs P2 Docs Learn Events
restart counter CNT — Parallax Forums

restart counter CNT

FabFab Posts: 3
edited 2010-07-13 20:33 in Propeller 1
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

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2010-07-13 08:58
    You can't set CNT to zero - at least not without restarting your program ;o). And if you do your measurement correctly, you don't have to.

    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.
  • AleAle Posts: 2,363
    edited 2010-07-13 09:18
    What is that guy/gal Vikram talking about ?... I thought it was some sort of sarcasm... but looking at his posts counter... makes me think: spam !

    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
  • FabFab Posts: 3
    edited 2010-07-13 17:00
    It's ok, but i'm using CNT in a repeat loop and I think that in some cases between "start" and "end" the counter restarts.
    repeat 
         waitpne( |<pin, |<pin, 0)      
         waitpeq( |<pin, |<pin, 0)      
         start:=cnt                       
         waitpne( |<pin, |<pin, 0)      
         waitpeq( |<pin, |<pin, 0)
         end:=cnt                            
         T := (end-start)  
         
         if T<....
         .....
    
    




    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
  • mparkmpark Posts: 1,305
    edited 2010-07-13 17:30
    The counter may well restart but that won't affect the difference between start and end.
  • FabFab Posts: 3
    edited 2010-07-13 20:33
    Ok thank you
    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.
Sign In or Register to comment.