Shop OBEX P1 Docs P2 Docs Learn Events
efficient counting — Parallax Forums

efficient counting

realolmanrealolman Posts: 65
edited 2007-10-28 17:51 in BASIC Stamp
What would be the most efficient method of counting the actual hi / lo transitions on a pin?

The COUNT command seems more useful for determining a frequency. The PULSIN doesn't quite seem to do it either.

I know I could count them, but it is important to me to use the fastest,· most efficient· method.

I am interested in knowing the actual number of transitions, in the least amount of time spent·executing the count, and having the accumulated count available for the largest amount of time.



thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-28 17:51
    The Stamps are single threaded processors. They only do one thing at a time. For example, when a Stamp is executing a COUNT or PULSIN statement, it's doing nothing else.

    You will need some kind of external components if you want to count signal transitions while the Stamp is doing other things. A lot depends on how quickly these are coming in. If they're slow (in relation to the Stamp's speed ... a few thousand instructions a second), you could just use an external flipflop (made from a quad NOR or quad NAND gate). The Stamp would periodically look at the output of the flipflop. If set, a transition occurred and the Stamp can reset the flipflop. A simple series capacitor can convert a transition into a pulse so you'll get two output pulses per input pulse (two transitions).

    If the transitions are coming in quickly, you may need to just count them with external circuitry and read the count with the Stamp.
Sign In or Register to comment.