Connect with us

How to count pulses per second ?

Discussion in 'Electronic Basics' started by Mike C, Feb 13, 2007.

  1. Mike C

    Mike C Guest

    Hi, I'm hoping someone could help me create a very basic circuit which
    would:

    Count the number of pulses it receives per second (from a 555 timer,
    or a switch, for example) and if the number of pulses per second is
    equal to, or greater than 10 it turns on a transistor.

    So basically it should check every second if a clock frequency of 10Hz
    is being met - if so, a transistor should turn an LED on and keep it
    on for as long as 10Hz a second is hitting the circuit. As soon as the
    clock stops, or the frequency goes below 10Hz, it should turn off the
    LED.

    Thanks so much for your help !

    MC
     
  2. Aly

    Aly Guest

    <SNIP>

    Microcontroller sounds like the best bet. A PIC 16F628 would be ideal for
    this. Much easier than messing about with lots of inflexible logic. Also a
    good grounding too for future projects. With a 4Mhz 628 you could
    realistically count upto about 100Khz with some decision making in there
    too. (actually runs at 1MIPS though).

    A programmer (suitable for the 628) will set you back say £20 tops. One of
    the easier chips to program. MPLAB is also free.

    Lots of examples on PICLIST (type it into Google)
     
  3. Mike C

    Mike C Guest

    Thanks for your help. I actually considered that option, but I was
    under the impression that a simpler circuit could do this job.
     
  4. John Fields

    John Fields Guest

     
  5. Mike C

    Mike C Guest

    JF:

    I dont need this to be too accurate... I'm collecting the number of
    times an IR beam gets broken, and if it gets broken faster than 10
    times a second, I need to trigger a transistor and keep it on for as
    long as the beam is broken at a rate of 10Hz or above.. (this beam
    gets broken with human intervention, so freq could be variable,
    anywhere from 0Hz to 20Hz, and may not necessarily have an even duty-
    cycle)

    Thanks so much for your help !!
    MC
     
  6. John Fields

    John Fields Guest

    ---
    Nonsense. I can do it with one chip, one resistor, one capacitor, no
    programmer and no learning curve.

    Not only that, I can build it, test it, tweak it and post the
    schematic in a few hours while you'd still be struggling with source
    code.
     
  7. Mike C

    Mike C Guest

    :)

    I'd have to agree w/ JF. Learning curve would be big (at least for
    me).. the "one-chip in a few hours" would just work so much better :)
    JF: would you be able to shed some light on what I should do. (A
    schematic would be simply amazing)

    MC
     
  8. John Fields

    John Fields Guest

    ---
    Basically, what you do is set up a retriggerable monostable
    multivibrator (one-shot) so that as long as the edges which trigger
    it keep coming in before the one-shot times out, they start a new
    timeout period, which should be precisely 100 milliseconds plus or
    minus whatever slop you can tolerate. That way, as long as the
    inputs occur quickly enough, the output will always be stable and
    the LED will never come on.

    Which brings up another point:

    If the signal drops below 10Hz and then goes back to >= 10 Hz, would
    you like the LED to stay on forever (Until it gets manually reset
    or something like that) or to go off automatically if/when the input
    signal goes back to >= 10Hz?

    Be aware that if the latch is what you want it'll probably take more
    than one chip to get there.
     
  9. I learned to program PICs _once_, it took every bit of a few days. I don't
    understand why the "PIC haters" all use this as their primary argument; as
    if it's something you go thru for every project. Electrical theory is way
    harder IMO.
    The OP said that you can't depend upon duty cycle or pulse regularity.
    Sounds like the circuit will literally have to count the actual number of
    pulses that occur in one second to meet his requirements. The OP hasn't
    stated if this kind of latency would be acceptible, but he didn't say it
    wasn't either.

    I could have working code to do this in about 1 hour. Given that, I'm going
    with the micro on this one for a solution with the smallest number of parts
    (1 PIC, some juice and an input buffer (a resistor may be more than enough).
    AFAIK, a discrete solution to do the above described work would require
    allot more parts (a one second clock, resettable decade counter, output
    compare and latch).

    OTOH, if a 100mS retriggerable timer will do, then you win. Or I could just
    change the code. ;-)
     
  10. Bob Eld

    Bob Eld Guest

    Yes but an 8 pin PIC could do this without a timing resistor and capacitor
    and do it in an absolute counting way that handles irregualr pulse timing
    like from a person pushing a switch. It would require writing some simple
    code and programing, of course, but would be cheaper and more stable and
    have a lower parts count and a smaller footprint than the one shot. The 25mA
    output current will drive LED's better than a one-shot. The clock is
    internal, no other parts required except a bypass cap and LED resistor that
    you have to have anyway. The one shot is OK for a do it once solution but
    is not the best for even moderate production of a few units. Besides, once
    one learns how to program and blow parts, there is no limit to what else can
    be done. That's a much more valuable learning curve than screwing with a
    one-shot.
     
  11. Mike C

    Mike C Guest

    Guys, thanks alot for your responses, all excellent & informative
    posts. I will most definately attempt this solution with a pic at a
    later time, convincing arguments in favor of the pic... and any
    suggestions with regards to obtaining a good and relatively
    inexpensive pic starter kit are definately appreciated.

    In the meantime, I'd like to attempt a temporary quick-fix to my
    problem, as i'm working with limited components in a relatively short
    time-frame.

    JF: I'm not sure if a monostable would fix the problem (but correct me
    if im wrong)
    Two conditions need to be met:

    1. If and only if the pulse train coming in >=10Hz (10 "up" cycles
    per second with no particular duty-cycle pattern) only then turn on a
    transistor.
    2. Otherwise, if the pulse train count goes below 10 cycles at any
    point, turn off the transistor at once.

    So the output should be HIGH only if 10 cycles per second (or higher)
    are counted, otherwise output is LOW.

    I'm afraid I still dont have a working solution (PIC programming
    aside :)

    Guys, thanks for all your help again.
     
  12. bg

    bg Guest

    Mike C wrote in message
    If available, there is an 8 pin chip called the 567 that is a tone decoder.
    It doesn't count pulses it compares frequencies. Might be of use.
    bg
     
  13. John Fields

    John Fields Guest

    ---
    Please bottom post.

    That's a horse of a different color, I think.

    Duty cycle usually refers to the percentage of time a pulse is
    active compared to the sum of the active and inactive time of the
    pulse, but it seems like what you're asking for is to detect the
    occurrence of 10 or more pulses in one second regardless of the
    pulse width and separation between pulses, no? That's a little
    trickier, but still easily doable in hardware. Also, I asked
    earlier whether you wanted the LED to go off permanently if the
    pulse train dropped below 10pps or to come back on automatically if
    it subsequently rose to >= 10pps, but I haven't seen your reply.
    Which would you prefer?
     
  14. Mike C

    Mike C Guest

    JF: Correct, i need to "detect the occurrence of 10 or more pulses in
    one second regardless of the pulse width and separation between
    pulses", and the LED to "come back on automatically if it subsequently
    rose to >= 10pps" .... so the only time the LED would be off if pps
    <10.

    Please see http://tiberian5.googlepages.com/home for an example of
    what the input is, and what the output should be.

    Thanks alot for your time.

    MC
     
  15. John Fields

    John Fields Guest

    ---
    Try this (View in Courier)

    Vcc--------------------+--------+------+
    | | |
    +---+ | |
    | | | |
    [1M]<-+ | |
    | |3 |
    14+--------+ | 15+---+---+2 |
    PULSE>---|CPO | +----|RC R B|--+
    13|___ ___|12 | 1|_ |13
    +-O|CP1 5-9|----|---O|A Q|--+
    |15| | | +---+---+ |
    +--|MR | [4.7µF]HC123|14 [1K2]
    | +--------+ | | |A
    | HC4017 | | [HLMP4700]
    | | | |
    GND>--+----------------+--------+------+

    An HLMP4700 is a 2 mA high-efficiency red LED which you can drive
    directly from the HC123's output.

    If you cant get one, or any other low-current LED, or you'd rather
    use a 20mA LED, do this:


    Vcc--------------------+--------+------+------------+
    | | | |
    +---+ | | |
    | | | | [120R]
    [1M]<-+ | | |
    | |3 | [LED]
    14+--------+ | 15+---+---+2 | |
    PULSE>---|CPO | +----|RC R B|--+ |
    13|___ ___|12 | 1|_ |13 C
    +-O|CP1 5-9|----|---O|A Q|---[1000R]---B 2N3904
    |15| | | +---+---+ E
    +--|MR | [4.7µF]HC123|14 |
    | +--------+ | | |
    | HC4017 | | |
    | | | |
    GND>--+----------------+--------+-------------------+

    Also, you won't be using the other one-shot, so connect the unused
    inputs (pins 9,10,and 11) to ground.

    I haven't shown the power pins either, and +5V goes to pin 16 and
    ground goes to pin 8 on both packages.
     
  16. John Fields

    John Fields Guest

    ---
    I just noticed on sed that you've multiposted this thread instead of
    crossposting. It would be better if you crossposted, since that way
    everybody gets to follow the thread and post to it without having to
    jump back and forth from newsgroup to newsgroup.

    I'm going to crosspost this one over to sed even though it'll repeat
    here. (seb)
     
  17. Mike C

    Mike C Guest

    JH: Excellent suggestion. I truly appreciate all your help,
    especially the schematic. I will be ordering the HC4017 to do the
    trick.. hopefully it'll be here in a few days... in the meantime, i'm
    trying to simulate in orcad pspice and cant find the an HC4017
    equivalent in the library, what did you use to simulate (if
    anything) ?

    many thanks again.

    MC
     
  18. CptDondo

    CptDondo Guest

    Does someone sell a pic-for-beginners kit?

    I'd like to get into it but I really don't want to take the time to
    build my own cable and put together my own programmer....

    (It's not that I am lazy; I literally don't have the time. I am an
    embedded programmer by profession and do this all the time at work - so
    I don't want to spend my hobby time building cables and debugging the
    development environment; I want to be able to program the thing....)

    I am really looking for a linux-based solution as well.

    I am willing to buy a homegrown kit - if an individual has one to sell
    or if someone is building these semi-commercially.

    Thanks,

    --Yan
     
  19. John Fields

    John Fields Guest

    ---
    I didn't, but I think your library has a 4017 in it, no?
    ---
    ---
    You're welcome but, unfortunately, the circuit doesn't work
    properly.

    Consider: What's supposed to happen is that the one-shot is set to
    time out in one second if it doesn't get retriggered by the 5-9
    signal from the counter, which goes high when the counter rolls over
    from 9 to zero, and goes low when the counter counts to 5.

    The plan was that as long as ten pulses enter the counter in less
    than a second then the 5-9 signal would continually retrigger the
    counter and keep the LED on. That part works.

    But... Consider this:

    What if, say, no pulses were coming into the counter at all? Well,
    the one-shot might flash for a second, but then it go out and stay
    out, which is good. But now, let's say pulses come in at the rate
    of one per second. As soon as the 10th pulse comes in, the 5-9
    signal will trigger the one shot and it'll come on for a second. So,
    it seems that any rate less than 10 pulses per second will cause the
    LED to flash instead of going out completely.

    What needs to happen in the circuit is that if the one-shot times
    out it starts an astable with a one second period which keeps
    resetting the counter once every second until the 5-9 signal comes
    out and starts the one-shot again.

    The plan there is that if the 5-9 signal didn't go true before the
    astable reset the counter it was because the pulses were too slow,
    and resetting the counter will get rid of what the counter's
    accumulated and start from zero once a second until the pulses speed
    up enough so that the 5-9 signal can get out and trigger the
    one-shot.

    I see you're on Google groups, so you can't access
    alt.binaries.schematics.electronic, so I'll email you a schematic
    when I'm done as well as post one there for anyone who's interested.

    BTW, what kind of accuracy are we talking here? 5-10% ?
     
  20. If I can throw in my two cents, I'd recommend checking out the AVR
    series of microcontrollers by Atmel. They are in a similar price range,
    are much faster, have a greater feature set and are much easier to
    program. Atmel's own high quality development environment AVR Studio is
    free, along with a complete suite of open source stuff including the GCC
    C / C++ compiler.

    The best part is that AVRs can be programmed in circuit with a parallel
    port cable and a pair of wire cutters. If you don't want to mess around
    with that you can get some cheap programmers at
    http://www.sparkfun.com/commerce/categories.php?cPath=1_7 but I prefer
    the slightly more expensive AVRISP Mk II from Atmel, which is about $30
    from Digikey. It's USB and is supported by AVR Studio and all the open
    source programmers.

    I like the ATMega8 as a good starting point and prototyping
    microcontroller. It's got 8K of program Flash, 1K of SRAM and 512 bytes
    of EEPROM along with a ton of peripheral features. A simple circuit to
    get one running requires only power, ground and a 10k pullup on reset.
    The ATMega8 has a built in RC oscillator up to 8MHz (8 MIPS!) and you
    can get em for a few bucks on Digikey.

    I hate to sound like an advertisement but I used to work with PICs and
    then I found AVRs. When I was working with PICs (about 4 years ago) they
    were a big pain in the butt. Programmers were complicated, there was no
    good, free C compiler and Internet resources were limited. Maybe the PIC
    scene has gotten better but AVRs just keep getting nicer and I see no
    reason to go back to using PICs.

    Here's an instructable on getting started:
    http://www.instructables.com/id/E5H5UDWB5UEUKIKV8V/
    Don't know if it's any good or not but it looks like it covers the basics.

    </gushing>

    Jason von Nieda
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-