calculate time between pulses


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default here are details

    signal is ttl from spindle of an old CNC machine.i want to measure rpm.max rpm are 2400 so max frequency is 50 Hz.the code i wrote above is now working correctly to calculate period.now iwant to calculate rpm.
    rmp=60/period
    should do the trick i think
    but how to perform this division?
    accuracy is not a problem now.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    You were near it in your question ...

    rmp=60/period * 1 000 000

    But ...

    care to the units of "period" , and overflow issues ...

    if you Xtal is 4 Mhz, then, period will be in µS ... the minimum "correct" display will be ~ 1100 rpm due to an overflow of your timer ... ( Period > 65535 ...)

    Then, the simplest way is to use a prescaler value of 8 ( 137 rpm ) or, if possible, 16 ( 68 rpm minimum )

    period will be in 8µS ( or 16 µS ) steps

    so,your result will then be :

    rpm = 60*1 000 000 /period*prescaler_value

    due to PBP limitations you'll have to use the DIV32 "function"

    So it will be Written :


    intermediate = 60 * 1000 / prescaler_value ' Compulsory !!!
    ' ( no "intermediate CON xxx" allowed )

    ' Disable interrupts ... if some used !!!

    Dummyvar = 1000 * intermediate

    rpm = DIV32 period

    ' re-enable interrupts allowed

    Alain



    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Nov 2005
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    if your period counter has 1uS resolution

    asm
    move?cb 00h,r2 ; load dividend 60e6
    move?cb 87h,r2+1
    move?cb 93h,r0
    move?cb 03h,r0+1
    endasm
    TmpW = div32 Period
    lcdout dec Tmpw

    N.B. div32 is limited to 31bit / 15bit unsigned integer
    so Period must be < 32767

    Regards
    Gianni

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink addendum ...

    Hi,

    Gioppy is bright right ...

    so let's add :



    IF period.7 then

    Period = period/2
    scale = 2

    ELSE

    scale = 1

    ENDIF



    intermediate = 60 * 1000 / prescaler_value ' Compulsory !!!
    ' ( no "intermediate CON xxx" allowed )

    ' Disable interrupts ... if some used !!!

    Dummyvar = 1000 * intermediate

    rpm = DIV32 period

    rpm = rpm / scale

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default thanks guys

    thanks for ur help.
    I am also interested in what Mr. Wolf mentioned:using PULSEIN with flipflop.would u shed some light on it also.
    thanks

  6. #6
    Join Date
    Oct 2005
    Location
    Pinckney, Michigan
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    In short, what the flip-flop does for you, when measuring frequency, such as in a tachometer application, is it negates the need to measure the duration of the high portion of the period, then switch context and measure the duration of the low portion of the period. The time it takes to switch contexts (jump to another section of code) will be lost, and your measurement will be innacurate.

    The flip-flop makes one long pulse, spanning the entire period of the tach signal, so that a single PULSEIN command can accurately measure the duration of the period.

    For an explanation of the flip-flop idea go to the following Parallax URL:

    http://www.parallax.com/dl/appnt/stamps/bs1appnotes.pdf

    Scroll down to the "Practical Pulse Measurements" section.

    For the complete blow-by-blow as to how I implemented rotor tachometers on my helicopter go to the following URL:

    http://www.basicmicro.com/downloads/docs/RRPM.pdf

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I have a PIC reliably reading 10 fan tachometers while it is doing other things. Something to keep in mind is that if your input signal is at all noisy, a simple period measurement may not result in a stable reading, since noise can easily affect a single reading. It is best to take a an average over a period.

    My method involves running a timer interrupt with a period shorter than the shortest expected "high" or "low" tachometer time. The interrupt service routine reads the port bits, and XORs them with the last reading of those bits. If the bit has changed, a counter is incremented. There is one counter for each fan to be monitored. The interrupt service routine keeps track of how many times it has run, so after a period of time (say a quarter or a half-second) it stores the individual counts. Simply multiplying the number of counts by a fixed value yields the RPM.

    The ISR is written in assembly, but this approach has several advantages:

    It doesn't require any external hardware
    It averages the counts over a short period, so the readings are stable even in the presence of noise.
    It works when the duty cycle is far from 50%.
    It runs in the background, so you can process other tasks at the same time.

    If you choose this approach, I can send you the code.
    Charles Linquist

Similar Threads

  1. Count pulses between VARIABLE TIME
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2007, 12:44
  2. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  3. Replies: 1
    Last Post: - 18th April 2006, 19:11
  4. How to calculate machine time in basic code?
    By chai98a in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd February 2006, 23:44
  5. anyone knows how to calculate muslim prayer time?
    By luqman83salleh in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 6th September 2004, 09:54

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts