Count Pulses and duration


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1

    Default Count Pulses and duration

    Greetings,

    I have a project where i need to check 2 inputs but i have no clue how to do it... i will try to explain.

    --What i have--
    Both signals start and end at the same time
    One changes to high and stays high until the end
    The second has pulses

    --what i need--
    I need to count the number of pulses of the second input while the first input is on.
    The pulses ( high state ) are 35ms long but the low state may vary
    I also need to count how long is the first at the high state

    --math after input receive--
    I then need to compare the lenght of the first input and the number of pulses detected so i can check if there are any missed pulses.


    The math i can handle...what i cant figure out is how can i measure the time of a pin being high and at the same time count the pulses of the second pin.

    I thank in advance the help.

    Regards
    Rui

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: Count Pulses and duration

    Hi,
    Depends.....on what resolution you need, what else the PIC needs to do WHILE it times and counts pulses, if the PIC needs to other things while WAITING for that first signal to go high or if it can just sit there twiddling its thumbs, waiting, if you're "locked" to a specific chip, if the pulses are occuring even when the "solid" signal is NOT on etc etc etc etc.

    I'd look at a chip that incorporates the TMR1 Gate feature or wire up a bit of external logic that gates the pulses so that they are presented to the PIC only when the "solid" signal is HIGH (a simple AND gate). Set a Timer up as a counter, connect the pulsed signal to its input. Connect the "solid" signal to another input. Clear the counter. Do a PULSIN measurement on the "solid" signal, grab the counter value. Something like that perhaps.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Count Pulses and duration

    if the two inputs start and stop together ... the length of ch1 is the sum of all pulses @ ch2 ... ( M. de La Pallice )

    so, no need to care of ch1 ...

    aaaaa.......

    just need to log pulses @ ch 2 ...

    one "pulsin" followed by enough "RC Time"s will do it ...

    Alain
    Last edited by Acetronics2; - 12th February 2014 at 19:33.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Count Pulses and duration

    Hi there,

    @Henrik

    I was thinking of using a 12F615. The MCu will only have a tight loop where it's just waiting for the inputs to start.
    After stopping it will analise the results and can go back to wait for signals again or move forward.

    @Alain

    Yes... both start and stop together...the problem is that the pulses ( 35ms ) may vary in quantity in the same period of time.

    Regards
    Rui

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: Count Pulses and duration

    Hi,
    OK, so the 12F615 has the TMR1 Gate feature, I'd say you're good to go for an all hardware solution - and since there's no pulses on second line when the first line isn't high then it gets even easier.

    Set up TMR1 as a timer with the gate control enabled, clear it and feed the "long" pulse to the gate control pin, this will measure the duration of the long pulse. Set TMR0 up as a counter, clear it and feed the pulses to the counter input, this will count the number of pulses.

    If you use the comparator as the gate control for TMR1 you might be able to set an interrupt up to trip when the duration of the long pulse ends.

    /Henrik.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default Re: Count Pulses and duration

    Quote Originally Posted by ruijc View Post
    @Alain

    Yes... both start and stop together...the problem is that the pulses ( 35ms ) may vary in quantity in the same period of time.

    Regards
    Rui
    and ... Where's the problem ???

    the RCTime timeout feature will take care of that for you ...

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

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Count Pulses and duration

    Thanks guys,

    I still have some doubts on how to code this but i will use your tips, study them a bit and try some lines of code.

    Regards
    Rui

Similar Threads

  1. Can I use PWM and count pulses for feedback?
    By queenidog in forum General
    Replies: 1
    Last Post: - 30th January 2012, 17:31
  2. Replies: 1
    Last Post: - 11th June 2011, 08:22
  3. Pin max current - short duration?
    By kevj in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd January 2008, 12:53
  4. Count pulses between VARIABLE TIME
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2007, 12:44
  5. SOUND Command (duration is too long)
    By martarse in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th August 2004, 02:18

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