Connect with us

How to count pulses per second ?

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

Scroll to continue with content
  1. Mike C

    Mike C Guest

    JF: Sorry, I forgot to answer your question: "what kind of accuracy
    are we talking here? 5-10% ? " Yes, 5-10% sounds about right ... And
    I'd love to see your "solution which uses a 555 made retriggerable"
    after you're done simulating..

    Thanks !
  2. John Fields

    John Fields Guest

    You are.
    Now who's sounding rabid? You are.

    First off, I'm not a PIC hater, I just don't much care for their
    architecture, so I stick with the gorgeous Motorola (Freescale)
    offering and bypass Microchip completely.

    Second off, sometimes I don't think its the PICs that people hate,
    it's smug, self-righteous, proselytizing PIC-lovers that put them
  3. John Fields

    John Fields Guest

    No problem.

    It'll be sometime today I think and It'll be an LTSPICE circuit

    The problem with the garbled schematic (from your other post)is
    something I don't understand.

    Over the last few days I've sent three schematics to three different
    individuals with gmail accounts and they all report the same thing,
    a text file instead the schematic. Here's the beginning of it:

    begin 644 10PPS-Model.pdf
    M(#$*/CX*96YD;V)J"C,@,"!O8FH*/#P*+U1Y<&[email protected]+U!A9V4*+U!A<F5N="`R
    M(#`@[email protected]]N=&5N=',@[email protected],"!270HO365D:6%";[email protected]@6S`@,"`W.3(@-C$R

    UUencoded? I don't know.

    Anyway, I emailed the schematic to myself and to another completely
    different system here and they both came out fine.

    Any clues?

  4. John Fields

    John Fields Guest

    And you knew precisely what he wanted from a less than precisely
    worded statement? You're fulla shit, Fremont. You remind me of
    the kid who learned a magic trick one day and then pretended he knew
    it all along. Kinda like "Positively Fourth Street."
    If you think being brusque is slapping someone around you've got a
    lot to learn. And who the hell are you to tell me what's proper and
    what isn't? I'm sure you've got enough on your hands just
    controlling your own nasty ass than to worry about anyone else.
  5. CptDondo

    CptDondo Guest

    Thanks Jason.

    It looks like I can get set up for < $100, which certainly sounds

    And I like the idea of setting up a cross-compile environment in
    linux.... That has merit.

  6. There you go again John, making untrue statements. I have never even begun
    to insinuate something as stupid as that. Other solutions are fine as long
    as the limitations are fine too. As I stated before, this particular
    problem can be done with less parts by using a PIC, and so far we all know
    that it can, including you John. Why is that so disturbing to you?

    Suggesting the use of a PIC is a far cry from "ramming it down someones
    throat", now isn't it John? Should I never suggest one? Have I ever
    suggested one in an inappropriate way? You make it sound like I'm some kind
    of Java nut that can't see anything else. Nothing could be further from the
    truth, and I think you know that well. You just have to keep your perpetual
    battle going with someone, even if you have to "gild the lilly" as it were.
    Just because you can do it without a PIC doesn't make using one wrong.

    Actually that was exactly the point. I have written "bug free" code the
    first time, so what?

    And exactly what stimulated you to start this whole mess between us? It
    couldn't be that you jumped all over something I said that really wasn't
    even all that incorrect. Then when I clarified my answer instead of falling
    into your trap, you got all pissed and started ranting and raving, just like
    now. Picking on spelling errors and petty nonsense like that; you don't
    seem to like it being done to you, so why do you do it to so many others
    without cause?

    OK, here you go.

    Here's the entire thread:

    Here is the tail dragging post:

    And just so people don't have to hunt for it:

    "I will say one thing now, though, and that is that after having
    checked your posting history last night I found that you do seem to
    know what you're talking about, technically, most of the time, so I
    apologize for any inaccurate broad-brush slurs I may have made

    Ignite any brain cells yet?

    I've only been plonked a couple of times, you got two yesterday IIRC.

    Are you feeling ok? My statement has nothing to do with myself. The quotes
    are to set apart my statement.

    I meant thanks, not plonks. Sorry about the confusion.

    Enough is enough. Where did the OP say that exactly? Oh, that's right, he
    didn't. That's your misinterpretation of what he said.
    I'll go ahead and help you out then, I'd like to see .005%. Does that give
    you what you need?
    Oh does it look like I actually made an assumption? I know you've worked
    with micros..

    You say that now, but later on down........

    Then why did you bring it up John? Sounds like a typical response from you.
    What you can recall has little to do with what has taken place here, good
    thing we don't all rely on your recollection. Most of us don't even need to
    pin our name and address to our shirts before leaving home. :) Just
    kickin' it up a notch.

    Anything you want, except a micro, PEEL, PAL, GAL, FPGA ..... you get the
    idea, no programmable logic. Ready to commit yet?
    The irony here is that you already know that I'm right and so does most
    everyone else, you're now just hoping that I can't actually produce some
    code that works. You're absolutely incredible John.

    Come on over and watch me. How else will I prove it to you? This is a
    simple piece of code, it really doesn't get much easier. Why is it so hard
    for you to believe that it won't be hard to write.

    I have a user with a serious production problem right now (not my fault
    though, just trying to be a nice guy for them) so I may not have code posted
    until morning. I think that's fair enough, it took you 24 hours to get it
    right and you're the expert. I'm just a tinker.

    Before you get your mouth open too far here, remember that I came closer to
    interpreting his first post correctly than you did. I've been extracting
    what people want from what they say for more than 25 years, I have some
    experience at this.
    Are you taking some kind of medication that brings on these fanciful
    hallucinations? You put more words into my mouth than I do. Just wishing
    that my behavior was as you say won't make it true. You just can't resist
    making foolish accusations, without evidence, even though you have been
    proven wrong time and again.

    For God's sake John, I've been a "professional programmer" for more than 25
    years. Do you honestly believe that anyone proceeds like you described.
    Oh, I keep forgetting, you do it that way.
    Is that why you immediately proceeded to develop the wrong solution? The
    whole world saw it already John, you're just making a bigger fool of
    yourself with every post.

    Then please explain how his post wasn't clear on when to extinguish the LED,
    I still haven't figured out how that part confused you. I didn't want to
    say anything, but here we are.
    You're absolutely right, the shouting down was a bit harsh.

    You were the first to make a contest out of this with your smart remarks
    about having it done while the suggestor would still be struggling with his
    That doesn't answer the question. I've already submitted that I understood
    a proper solution before you did, or don't you believe that either? Will I
    have to prove that too?
    Wow, just happened to snip your part off huh, your such a cheat when it
    comes to debate.
    You absolutely changed the subject and you know it.
    Another lie. There have been a myriad of posts were people wanted help with
    PIC code. There have also been people that were willing to use a PIC even
    if they had to pay someone to flash it for them.

    Now, grow up, stop the hand waving, stop the creative snippery and just
    debate like a man. Can you do that John?
    And now you speak for all the past, present and future noobs that want some
    help? And exactly how are PIC lovers not real people John. You just can't
    alienate people fast enough, can you?
  7. Yan,

    You should be able to get going with AVRs for well under $20, even.
    I'd say a good "Starter Kit" would be:
    * A couple ATmega8s for $3.66 each at Digikey
    * Parallel port cable from your local electronics store, probably $5
    * WinAVR or the AVR GCC toolchain for Linux (free)
    * Various resistors, and at least 1 10k resistor (few bucks)

    Check out to see how to wire up the
    parallel port cable to use as an in circuit serial programmer.

    Since the ATmega8 has a good on chip oscillator you don't even need a

    Good luck! And feel free to email me if you've got questions. I really
    enjoy using AVRs and I don't mind blabbing about them :)

  8. Where is the ramming? My entire point was made in a post that you wouldn't
    even reply to. To solve this problem, IT TAKES LESS PARTS WITH A PIC,
    that's all I said. When you can prove that wrong, come on back.

    You know this isn't about Microchip PICs in specific. By PIC haters, I was
    referring to the "no micros at any cost" group.

    I'm afraid I have to agree with you on something. Even though I haven't
    programmed on it, the Motorola arch looks pretty decent. Of course the PIC
    Actually that's all just for your benefit. ;-) Now come on John, you know
    that it really isn't quite like that. OTOH, the anti-micro group (AKA PIC
    haters) do often come off like they're pissed at the mention, just look at
    Ed and how he went off.
  9. That wasn't my issue. My point was that "it wasn't simpler". Now I guess
    we can debate what that means, but I was thinking parts count.
    That will be interesting.
    WILL YOU MAKE UP YOUR MIND???? Yes, I will, but as I said I have allot
    going on today, but I will try to have something by the morning, otherwise I
    will get after it this weekend. I'm at a slight disadvantage in that I
    haven't tinkered with my PIC stuff for a while, so I have to dig it all out.

    If you've been snooping around Google, you'll know that I took up
    watchmaking as another hobby. Imagine that, a PIC lover that wears vintage
    wind-up watches. I have to convert my bench back to PIC development, but
    I've been wanting to switch back to tinkering with that stuff for a little
    while anyway.
    Less than a whole day (8 man hours), but finding 8 spare man hours is a bit
    tough these days. I don't mean to be tossing out excuses, but I have been
    way too busy lately.
  10. Mike C

    Mike C Guest

    John: I get the same garbled text in Gmail ... i just enabled POP and
    downloaded in outlook, it worked... I can see the pdf now... I guess
    its something with google. Thanks a bunch again ! I just downloaded
    LTSPICE so I could see your next circuit. is this the right one ?

  11. John Fields

    John Fields Guest

    It isn't, but I'd say that because of your constant whining about
    how good a PIC would be in this application that you're upset
    because the OP won't buy into it.
    Yes, but perpetually bleating that it's the right solution is.
    Don't ask questions you know are stupid.
    Dunno, don't care.
    LOL, it seems like you're the one following _me_ around.

    No, but when you've been specifically told "NO" and you keep begging
    for a change of mind, it's a little sickening.

    Never mind; you still don't get it.
    As I recall, the first time your name popped up where I was
    concerned was in a post where I was talking about the good service I
    got from and you came on strong about how stupid I was
    for all kinds of reasons, none of which I care to rehash.

    The second, as I recall, was in this thread where you couldn't stand
    me getting some compliments from Ed and had to start in with your
    "I'm better than you are" shit.
    If you think this is ranting and raving, you don't know what ranting
    and raving is.
    Who are you to determine what and what isn't cause for me to act as
    I choose? This all goes back to what I said before about that you
    want people to do what you tell them to. Face it, you're a control

    Vaguely, but it sounds like me in that if I find I'm wrong I don't
    mind owning up to it. You seem to think there's some shame in that.

    Probably that's why you're carrying on so.
    That's still not _everyone's_ killfile, is it?

    Anyway, it doesn't matter. Just fewer assholes I have to contend
    _You_ made the statement: "I think you should look at it like this,"
    which indicates that you think that the way I was looking at it is
    incorrect and I should go about looking at it in the way you

    As the designer _I_ get to choose.
    If he didn't say, how could I have misrepresented?

    Well, I've glanced through the rest of your replies and it all just
    seems to be frippery and evasion, much like the preceding, So I'll
    just disengage now and leave you to your own devices.

    Besides, I do have someone waiting for a schematic and a
  12. Just like the post I made less than around 9:30 pm Tuesday says Fields,
    you're the one making a mistake.
    ISTM, that I'm not telling you anything here, I was talking to Eric.
    Pot, kettle, black and all that, ya know.

    I guess I was right, huh?
  13. John Fields

    John Fields Guest

    Sounds like you want to smoke peace pipe. OK.

    Tell you what, I'm kind of busy too, so if you want to wait 'til
    next week I'll write some Motorola assembler to do it in one of
    their processors and we can compare.

  14. John Fields

    John Fields Guest

  15. I don't care if the OP "buys into it", and that's not the issue. The issue
    is you and your constant waffling crap.
    I never once said that it was the "right" solution, as if there is only one
    solution. I said it was valid, simpler (less parts) etc....., that's your
    own fantasy.

    You should since that was what most of your spewage was about.

    What are you talking about. I never even spoke directly to the OP about it.
    Where did he tell ME no? Where was I begging him. Just a bunch more lies,
    big surprise.

    I guess not.
    Aparently your memory is worse than I thought. The only thing I said
    regarding your stupidity was about installing the yellow disc and not having
    a seperate firewall. AIR, you got mad over my suggestion that if you were
    happy with SBC/Yahoo support, then you were easy to impress. I still stand
    behind that statement.

    Guess that means you've run out of lies to spread then. I'll take that as a
    win then.
  16. Mike,

    I'm neither a PIC-hater nor a PIC-lover. Nevertheless I'm a PIC-user
    (sometimes). As for the problem you mentioned I'd use the smallest PIC and
    write some code for it. That's not to say I'd advise you to do so. I fully
    agree with John that a electronic solution might be better in your
    situation. PICs *do* have a learning curve which is often underestimated by
    the "lovers".

    If you want to learn PICs I often advise to go to
    IMHO a clear explanation of pros and cons. You will find a programmer (kit
    or build) and a JAL compiler which may suit higher level language
    programmers better then assembler. You will definitively need the datasheet
    of the PIC you want to use. Free downloadable from Microchip.

    Small solutions that use small PICs are better done by assembler. Microchip
    has a complete development environment for free. You can also build your own
    programmer. I build one found on
    That one works for me but you can find many, many others.

    Likewise you can find other micros too.

    petrus bitbyter
  17. For the most part, I tend to treat people the way they treat me. I rarely
    go off on someone that didn't smack me first, but I must admit that I have
    done it. I can't help but to defend the underdog sometimes, and it really
    gets under my skin when someone comes down hard on a noob for no reason.
    Besides, you can't say that you don't enjoy a good flame war anyway, can
    you? ;-)

    AIR, my first encounter with Ed was him going off on me over being another
    "PIC lover". In that case, I actually did suggest one to the OP. That's
    when I find out about this whole anti-PIC (anti-micro) movement. I ended up
    having to post code for that one too. That's probably why I couldn't resist
    responding to him this time. Aly was just being funny and Ed took it all
    personal on your behalf. You have to admit, surely, that Aly was pretty

    There's nothing wrong with promoting PICs, just like there is nothing wrong
    with promoting the "Rube Goldberg" techniques. At least while parts are
    still available. ;-)
    It's a simple problem so there really shouldn't be much to compare, except
    the actual approach taken. I already have some code thrown together, but it
    hasn't been assembled yet. I like using interrupts, so I was just thinking
    I'd use a timer to generate 1 int/second and use an RB0 int to capture and
    count the pulses. The LED will be turned on or off once per second in that
    interrupt handler so it will remain on or off for that amount of time.
    Another main level with no code to execute. :)

  18. Since I have been going on about AVRs, here's my contribution.
    It's around 15 minutes of write/debug.
    Grab it at if it doesn't
    show up well here.
    The circuit for this would be an ATmega8 ($3.66 on Digikey), a 10k
    pullup to +5v on RESET, VCC = 5v, GND, input on pin 4 and output LED on
    pin 14.
    Total cost: ~$4.00
    Total time: ~30 minutes including building the circuit

    Chip Configuration
    ATmega8, 8MHz Internal RC Oscillator
    I/O Configuration
    Input pulse train on PD2
    Output LED on PB0
    Operational Theory
    When rising edges are detected on PD2 (input) a global variable
    called pulses is incremented. The main program runs in a infinite
    loop delaying for one second at a time, checking the number of
    pulses in that
    last second and then triggering power to an LED if the pulse count
    is equal to or greater than 10.


    #include <avr/io.h>
    #include <avr/interrupt.h>
    Most people have their own delay routines. If not, there are dozens
    available on the Internet that all basically amount to the same thing.
    #include "delay.h"

    int pulses;

    This interrupt handler is triggered each time a rising edge is
    detected on INT0, which on a ATmega8 is PD2

    int main(void)
    pulses = 0;

    // Enable PD2 as an input
    DDRD &= ~_BV(PORTD2);

    // Enable PB0 as an output
    DDRB |= _BV(PORTB0);

    // Make sure the LED is off
    PORTB &= ~_BV(PORTB0);

    // Configure INT0 to trigger on rising edge
    MCUCR |= _BV(ISC00) | _BV(ISC01);

    // Configure INT0 to fire interrupts
    GICR |= _BV(INT0);

    // Enable interrupts

    // Loop forever
    while (1) {
    // Delay for 1000ms (1 second)
    if (pulses >= 10) {
    // If there are more than 10 pulses in the last second turn on the LED
    PORTB |= _BV(PORTB0);
    else {
    // If not, turn the LED off
    PORTB &= ~_BV(PORTB0);

    return 0;

  19. // Did you forget this? :)

    pulses = 0;
  20. Would you believe me if I said I left that as an exercise to the reader? :)
    Okay, okay, I forgot it. Nice catch :)

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