Shop OBEX P1 Docs P2 Docs Learn Events
background time counting — Parallax Forums

background time counting

science_geekscience_geek Posts: 247
edited 2009-03-11 09:21 in Propeller 1
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.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-11 01:37
    For time intervals up to just under a minute, the best way is to simply use the system clock as in:

    <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
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-03-11 09:21
    And the last·digit is fixed again? Strange ... but without code it's just guessing.

    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
Sign In or Register to comment.