calculate time between pulses


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Posts
    37

    Default calculate time between pulses

    Hi!
    I want to know how to calculate exact time between two pulses.Input is a pulse train with variable frequency.just want to calculate time between rising or falling edge of one pulse and the second one then second one and third one continously.
    thnx

  2. #2


    Did you find this post helpful? Yes | No

    Default Not enough information

    If the pulse train is slow, an all-Basic approach could be something like

    Loop:
    Counter = 0
    input sensepin
    if sensepin = 0 then Loop
    TimeHigh:
    counter = counter + 1
    pauseus 1000
    if sensepin = 1 then TimeHigh
    TimeLow:
    counter = counter + 1
    pauseus 1000
    if sensepin = 0 then TimeLow
    Done:
    Serout Tx232, 2, ["Pulsewidth = ", #counter, ", mSecs"]
    GOTO Loop

    This will need tweaking (by reducing the pauseus period) to get the timing exact. An oscilloscope needed.

    If your target pulse rate is too fast for the above you will need to setup Timer1 or Timer3 then invoke the CCP register which will give you the number of ticks of Timer1/3 between events on the defined CCPx pin. This will give you microsecond speeds and very high accuracy which can be defined by analysis rather than measurement in the Basic approach above.

    HTH
    Brian

  3. #3
    Join Date
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default ccp not working

    Ok here is a code for CCP but for some reason it is not working:
    Define LCD_DREG PORTD ' Define LCD connections
    Define LCD_DBIT 4
    Define LCD_RSREG PORTD
    Define LCD_RSBIT 2
    Define LCD_EREG PORTD
    Define LCD_EBIT 3



    Lcdout $fe, $80, " Pulse Reader"

    Pause 2000
    Lcdout $fe, $1





    Period var Word
    Capture var PIR1.2
    Overflow var PIR1.0 CCP1CON = %00000100
    T1CON = %00000001
    Loop:
    While Capture = 0 : Wend

    Period.lowbyte = CCPR1L Period.highbyte = CCPR1H
    If Overflow = 0 Then Lcdout $fe, $80, "Input Period: " , #Period , "uS"
    Endif
    Capture = 0 ' Clear the capture flag
    Rst:
    While Capture = 0 : Wend
    TMR1L = 0 TMR1H = 0
    Capture = 0
    Overflow = 0
    Goto loop

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


    Did you find this post helpful? Yes | No

    Default

    I've used the PULSEIN command as a tachometer for years.

    One trick is to employ a flip-flop in the signal chain that acts as a frequency divider. This has the effect of generating a single high pulse between two succesive edges, allowing the PULSEIN command to work, without having to switch context to time the high portion of the period and then the low portion of the period.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Smile some more infos ... please

    Hi, Hell_pk

    << I want to know how to calculate exact time between two pulses. >>

    The question 1 ) is : How exact must be your "exact time" ??? : +/- 1 ms ? +/- 1µS ... better accuracy ???

    The Question 2) is : Which is the period ( approximate ... ) of your signal.

    Could you also tell us what is your "signal" ???


    Then we will be able to show you ideas ...

    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 " !!!
    *****************************************

  6. #6
    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.

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 : 1

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