Connect with us

How to count pulses per second ?

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

  1. Jason von Nieda wrote:
    <snip>
    Sorry, I didn't mean to just criticize your code and run. I accidentally
    hit the send button (f*&&$*% touchpads on laptops). I like to see C
    snippets that show how the micro and compiler work with ints and SFRs.
    Thanks for posting that. Is that GCC? Looks like it would probably work ok
    for the OP unless pulse rates got too high and started overflowing the pulse
    counter. High int rates would make the delay routine take longer to execute
    too, but probably wouldn't really matter. I think he's measuring people
    passing by so you're probably pretty safe. :)
     
  2. Like JF says, I'm an expert at nit-picking things. ;-) Actually, it really
    is a knack that I seem to have with software design. I may suck at
    electronics, but I'm pretty good at finding problems with program designs.
     
  3. Yep, it's GCC. I wrote and built that code using WinAVR from
    http://winavr.sourceforge.net/

    Good point on overflowing the pulse counter. Of course, it would take
    32,768 PPS (people per second) to do it! :)

    Good point on the delay routine as well. A better way to do that would
    have been to put the 1 second timer on an interrupt as well and just
    have the main loop do nothing. That way the 1 second timing could only
    be effected, at max, by the length of time it takes to run the INT0
    interrupt handler.

    Jason
     
  4. I was thinking (daydreaming?) that he might be measuring legs since they
    would tend to break the "beam" for a short period while they "swung" by,
    that's probably what I'd try anyway.

    But your right, even with two legs, it'd be impossible for that many people
    to travel thru some practical sensor that would only need to worry about
    10ppS.
    Right, and there are even ways to make this absolutely perfect (outside
    clock accuracy) in terms of measuring off precise 1 second intervals and
    firing the ISR without so much as 1 clock cycle of "jitter". Sometimes you
    have no choice but to be that picky. This wouldn't be one of those times
    though. ;-)

    Being an OCD kinda guy leads to tinkering with this stuff and then finding
    out why the most often uttered phrase during an epiphany isnt "Eureka!",
    it's more likely to be "hmm.....that sure is strange". I've found a couple
    of hardware bugs in PICs over the years like this, or were they really just
    "Obscure Undocumented Features".
     
  5. Mike C

    Mike C Guest

    Jason: Thanks for the example code. This looks (almost) simple. (I say
    almost because I'm sure there are a few things to figure out in terms
    of finding the necessary libraries and getting all the pieces together
    in the compiler/programmer).. pardon my lack of knowledge in these
    things... but to a total beginner in the microcontroller-programming
    field, what is the difference between the AVR and a PIC? only reason I
    ask is because it looks like Atmel is the only mfr of these things,
    and they are relatively pricey compared to the pic's ... are the
    libraries & code interchangeable between the pic programmers? I dont
    know much about this, but i'd like to pickup a starter kit and try
    this solution out... any guidance is appreciated.

    MC
     
  6. Hi Mike,

    There's actually very little to figure out and collect to get that
    running. If you are using Windows you just download WinAVR from
    http://winavr.sourceforge.net which includes the compiler, linker,
    assembler, libraries and programs for actually burning your code to the
    chips, along with a bunch of utility programs. If you are using Linux
    there are a few more steps... but then, there always are with Linux :)

    The biggest difference between AVR and PIC, to me, is the availability
    of quality development tools for the AVR series. The chips themselves
    have similar functions throughout the different families and I'd be
    willing to say you can probably solve any problem with one equally as
    well as the other, but the quality and availability of free development
    tools for AVR is much higher in my experience. GCC, which most people
    are familiar with, is an excellent compiler and is the default toolchain
    for AVRs. When I was working with PICs there was no free C compiler and
    while I can program assembler when needed, I prefer not to.

    Code and libraries are definitely not interchangeable. The IO is
    completely different on the two families.

    Atmel is indeed the only mfr. for AVR; not much more I can say on that.
    Hopefully Atmel doesn't die on us :)
    One thing to note on price is that the AVR I am using (the ATmega8) is
    actually a pretty beefy chip. I use them because I don't like to keep a
    bunch of different parts around the house and they almost always meet my
    needs. In many cases you can use a much smaller (and cheaper) chip.
    Check out the ATTiny series on Digikey. They start around $0.54 each and
    you'll be using the same code, compiler and routines. The code I wrote
    would run on an ATTiny just fine just by changing a few of the IO
    register names I used.

    For a starter kit check out the stuff at Sparkfun at
    http://www.sparkfun.com/commerce/categories.php?cPath=2_10
    If you want to use the Mega8 check out
    http://www.sparkfun.com/commerce/product_info.php?products_id=29 which
    is really nice. In the related components at the bottom of the page you
    can buy a few chips and a programmer.
    You can get started with the ATTiny series with
    http://www.sparkfun.com/commerce/product_info.php?products_id=33 but it
    looks like it's currently out of stock.
    I just do all my prototyping on a solderless breadboard but having a
    little board like the ones linked above that include a RS232 level
    converter and such would be great for getting started.

    Jason
     
  7. John Fields

    John Fields Guest

    ---
    No, the issue is your attitude.
    ---
    ---
    Do you not think it's the right solution?
    ---
    ---
    Nope, what I've been saying all along is that if the OP chose not to
    use a PIC, for whatever reason, then that's his decision and I'll do
    hardware designs until the cows come home to get him what he wants.

    You, on the other hand, even after having said how easy it would be
    to do a software version haven't even offered to supply him with a
    programmed chip he can try. What would it cost you? a couple of
    bucks and you would have proved your point. But no, all you want to
    do is bitch and moan about how wrong I am to do it the way I'm doing
    it. **** you. Getting the OP what he wants is what I want to do,
    not sit around and argue with the likes of you, although I must
    admit I got sucked into it this time because of the hard time you
    were giving Ed for no reason at all.
    ---

    ---
    No, it's intent. It's clear you think PICs are the greatest things
    since sliced bread and you get upset when your suggestion to use
    them is turned down for reasons you think inappropriate.
    ---
    ---
    And your purpose for saying that was what? To make a joke? No. To
    try to make a friend? No. To try to piss someone off by insulting
    them? Bingo! I'll tell you what, Anthony, if I was easy to
    impress, then I'd be impressed by you, but the fact is, I'm not. It
    seems to me you're little more than an argumentative troll with an
    unwarrantedly high opinion of himself, who's ready to tell everyone
    just exactly how they should live their lives.
    ---
     
  8. John Fields

    John Fields Guest

     
  9. Ok John, I'll try to work on it for you. Good thing you set such a shining
    example for me to follow.

    That, my dear friend, depends entirely upon how you define "right", doesn't
    it? For the OP here, maybe not. If it was for myself, of course. If it
    was for production, quite possibly. It will almost certainly use less
    parts, cost can be brought down to pittance, so it has those merits for
    someone looking in that direction.



    I'm not even in disagreement with that.
    gawd this is good.......
    LOL. That is probably the most self-serving emission you've put forth yet.
    The truth is that you are just pissed again and now you've got to start
    blaming me for wasting your time.

    Now that I've offered code, I'm a jerk because I didn't offer to burn a PIC
    and mail it to him? If I do that, then what will you find wrong? Man John,
    I didn't reply to the OP originally because I didn't really have time to
    write him some code. I'm going to do it though, if I ever get done
    answering to you. BTW, where exactly do you get off in telling me what I
    should do "with my life"? PKB
    Microcontrollers ARE the greatest thing since sliced bread IMO (cuz I don't
    know FPGAs), but it never upsets that someone chooses not to use one. What
    upsets me (for the ten millionth time) is people who go off over the mere
    mention of the word, why can't you understand that. Oh I know, you don't
    really have a problem with that per se, you just don't like me.

    Actually it was to make a joke, I really don't understand why you went
    ballistic over it. You got lucky, they solved your problem quickly, they're
    not gods. I've dealt with them far too many times to count. They're not
    any different than any other support line. Their first level support blows,
    just like everyones. Once you get past them, you can usually find the
    people that know what's going on. It's par for the course.

    You make it sound like I said all that in one post, but of course it was
    another volley just like this that escalated to that point. It is true that
    I said that it is STUPID for ANYONE to connect a PC directly to the internet
    with a public IP. I also briefly covered the implications of the "yellow
    disk". I can't call people stupid for installing that, because they think
    they have to. They don't know any better, so they get bent over by your
    heros at SBC/Yahoo right off the bat, before even getting on the internet
    the first time. I was just trying to educate you on that, but you know it
    all already, right?

    As far as making friends, I already showed you the thread where we met. Is
    that the proper way to do it?
    Just show one post where I "tell everyone just exactly how they should live
    their lives" liar. I liked the "argumentative troll with an unwarentdly
    high opinion" part though, even if you did spell it wrong. ;-)

    Always plenty of time to dish out more of your own though, isn't there?
     
  10. Mike, if your frequency rate limit is fairly sloppy and you
    just want simple, you might cobble up something with a
    frequency to voltage converter, an RC low pass filter and a
    comparator.

    Take a look at the data sheet for the LM2907:
    http://www.jaycar.com.au/images_uploaded/LM2907.PDF

    There may be a version that includes the comparator, but I
    can't remember the part number.
     
  11. Well, you likely didn't use the word expert, but you said something about my
    nit-picking things. It's a skill, why waste it? ;-)
     
  12. Phil Allison

    Phil Allison Guest

    ** Groper fool alert.




    ** So - do actually you want a pulse counter or a frequency detector ??

    Your first para asks for a pulse counter which totals over successive 1
    second increments and reacts to a count of 10 or more.

    Your second para asks for a pulse RATE detector that recognises a rate
    greater than 10 Hz.

    So which is it?




    ........ Phil
     

  13. Plonk.


    --
    Service to my country? Been there, Done that, and I've got my DD214 to
    prove it.
    Member of DAV #85.

    Michael A. Terrell
    Central Florida
     
  14. Good job Terrell, you just killfiled someone that stuck up for you in the
    past.
     
  15. Chris

    Chris Guest

    Hi, Mr. Fields. All this for a homework assignment! The OP should be
    as pleased as a clam.

    The idea above was that the pulses the OP is counting are going into
    the 4518, which is trying to count to ten before the first (left) half
    of the 556 briefly resets once every second. The second half of the
    556 is just responsible for outputting an indication (say, 1/2 second
    to drive an LED) if the count ever gets to 10. Retriggering shouldn't
    be an issue -- if the pulse rate is less than 10, the second timer
    should never go off.

    It is sloppy, but it should do most of what the OP asked for, I'd
    guess.

    Cheers
    Chris
     
  16. John Fields

    John Fields Guest

    ---
    I'm not telling you what to do, I'm offering you an alternative
    which would more closely conform to your -position.
    ---


    ---
    If that was supposed to be a joke, then I suggest you don't try your
    hand at stand-up comedy; you're likely to be killed.
    ---
    ---
    Then you don't understand that denigration isn't humorous.
    ---
    ---
    The polite way to try to educate on this medium is by questioning,
    not by name calling. For instance, which of the following seems less
    offensive to you:

    "Did you know that it's not a good idea to connect a PC directly to
    the Internet with a public IP."

    "It's STUPID for ANYONE to connect a PC directly to the internet
    with a public IP."

    And just look at your last paragraph. Full of disdain for SBC/Yahoo
    and then calling them my heroes certainly doesn't cast me in even a
    neutral light, does it? Of course not, but then your intent _was_
    to insult.

    But then I'm supposed to be all sweetness and light and respond to
    your posts as if you were supposed to be some superior sort of being
    and accept the insults as necessary for my "education"?
    ---
    ---
    Geez, I guess the apology wasn't good enough for you and since I
    apologized (which as far as you're concerned seems to be something
    that only shameful people do) the plan is for you to be nasty
    forever and for me to take it in order to atone for my shameful
    behavior? Again: **** you, Fremont.
    ---
     
  17. John Fields

    John Fields Guest

     
  18. John Fields

    John Fields Guest

     
  19. John Fields

    John Fields Guest

    ---
    In other words he's done something that you think he shouldn't have?

    That is, he's acted in a way which isn't in accordance with your
    wishes?

    That is, you want him to do things the way you want him to?
     
  20. John Fields

    John Fields Guest

    Hi, Mr. Foley,

    I think he wants the LED to stay on continuously as long as there
    are ten or more pulses occurring every second. That means that for
    no gaps to occur in the illumination of the LED the period of the
    timer must be longer than the time it takes for the counter to
    accumulate ten input pulses. However, since the 555 is normally not
    retriggerable, the "10" decode will occur while the timer is still
    timing out. This won't extend the timing at all, so the timer will
    time out and the LED will go out even though 10 pulses were counted.

    If you change the counter, though, and make it retriggerable it
    should work perfectly. I'm currently working on simulating a
    similar scheme but I'm having trouble with chattering around the
    switching point and low sensitivity, which I think your circuit will
    eliminate by making the LED timer retriggerable.

    So, what I'll do is take your circuit, (which is almost like mine)
    make the LED timer retriggerable, switch some parts around, and run
    it since I've got almost all of it done anyway.

    I'll post the LTSPICE circuit list when I'm done. (Whether it works
    or not... ;))
     
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

-