Shop OBEX P1 Docs P2 Docs Learn Events
Reading frequency at very low pulse rate — Parallax Forums

Reading frequency at very low pulse rate

KERBSKERBS Posts: 26
edited 2004-11-28 21:19 in BASIC Stamp
I am really stumped!· This is my third shot on this forum to try to solve a problem I am working on. I am working on a rate meter that requires the stamp to read pulses and calculate a rate for me.· I will be using a gear tooth sensor that on a shaft that will turn as slowly as·2 rpm. The sprocket will have 10 teeth on it so the incomming rate of pulses will be 20 pulses/minute or .333/sec.· using pulsin I overflow the counter at this rate. the lowest I can get with pulsin is around 8 pulses/ second.· I would like to update the frequency reading at least every 3 seconds. Can anyone please give me some ideas on how to get a resonable frequency reading at these low pulse rates?· I've been working on this for quite a while now and am ready to give up.· Is there a way to keep a running average of the pulses comming in and compare them to a clock of some sort? please be specific, I have found that answers on this forum, as well meaning as people are, can tend to be rather vague.· thank you

Comments

  • SPENCESPENCE Posts: 204
    edited 2004-11-27 12:16
    Are you using magnetic or optical sensing of the gear teeth?

    A silvered panel on side of each tooth and a v beamed optical senser migh be the answer.

    Magnetics at slow speed may be the problem in your case.

    73
    spence
    k4kep
  • agentileagentile Posts: 101
    edited 2004-11-27 15:09
    Because you are dealing with such a slow device, I think you would be more successful using an internal counter.· I would write a little routine which counted the changing status of the tooth using PAUSE.· For instance, you can check the status of input pin every 10 ms (plenty fast enough for this system), when it goes high, set a flag =1,·and go into a counting loop using PAUSE.· The loop should be entered only if flag is less than 2.· Increment the counter, then pause for Xms, then go back to check on the status of the tooth.· As long as it stays high, you are on a tooth.· Then when it goes low, you are inbetween teeth.· Once it goes high a second time, let flag be incremented.· This indicates the beginning of a second period.· The resulting counter·value times the pause·will be a reasonably close approximation of·1/20 of the period of the total gear.· You can easily improve this by doing multiple periods (of a tooth) and averaging them.·

    agentile·
    ·
  • ionion Posts: 101
    edited 2004-11-28 09:38
    Kerbs,
    To calculate the rate, you need to specify, what stamp you use, because the speed of the stamp will define the max pulse width.
    Few suggestions:
    1 count the leading and falling edge of the sensors == you get 40 pulses instead of 20 ; still to much; 1.5 second length to count.
    2 Use two (word) variable. The first one will count the pulsin . ·Monitor this variable, and when the count > 50000 ( easy to manipulate) reset the pulsin variable to zero and increment the second variable by one
    With a Bs2PE at 40 pulses / minute, you will get approximately 15 counts on second variable, and 47872 counts on pulsin variable. Total pulses counted = (15 X 50000) + 47872 =·797872.·· 797872·X 1.88usec =·1.4999936 sec. From there is just plain math.
    I suggest to use greater then 50000 when you rollover, as I am not sure if you can catch the equal 50000 moment. However, in your case, few + or- counts will not make a big difference.
    Good luck
    Ion ·
  • John KauffmanJohn Kauffman Posts: 653
    edited 2004-11-28 18:14
    Another solution is to compare your count of teeth to real time using the PocketWatchB. You can time-stamp your start time and stop time and subtract to get an elapsed seconds, then divide count by seconds adn divide again by # teth in gear to get revolutions per second.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-11-28 21:19
    I have a couple of timing loops posted at this URL, and also links to external timer chips:

    owlogic.com/BS2speed.htm#longpulse

    To measure the period with the Stamp without an external chip, the PBASIC program waits for the input to change state, then counts tight loops until the input changes to that state again, one whole period. The count will not be exactly in milliseconds, but a simple conversion factor can make it so. Or, for your purpose, you may need to do a division to convert period to frequency. Something like this:

    DO
    LOOP UNTIL in0=1        ' wait for start
    DO
      ticks=ticks+1      ' a word variable
    LOOP WHILE in0=1      ' first 1/2 cycle
    DO 
      ticks=ticks+1
    LOOP WHILE in0=0     ' second 1/2 cycle
    myconstant CON 8000   ' to be determined
    frequency = myconstant/ticks
    DEBUG "frequency=", DEC frequency/10,".",DEC1 frequency
    



    On a BS2, the above loops will accumulate about 1200 ticks per second. So at 0.333 second, it would be about 400 ticks, corresponding to 2.0 rpm. So myconstant=8000. But each stamp will require a calibration step to determine the appropriate value for "myconstant".

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.