Shop OBEX P1 Docs P2 Docs Learn Events
count both rising and falling edges of signal with single counter? — Parallax Forums

count both rising and falling edges of signal with single counter?

schillschill Posts: 741
edited 2011-05-23 09:37 in Propeller 1
Is there a way to use a single cog counter to count both rising and falling edges of a signal at the same time? I would like to know if there's a way to do this without adding extra hardware.

There is an encoder I am thinking about using that has a 50% duty cycle. I want to measure frequency. I can do this by counting either rising or falling edges. But, if I could count both edges, I may be able to get a more accurate measurement.

The encoder actually provides two signals, 90 degrees out of phase but both have a 50% duty cycle. This gives 4 potential triggers in a single period (A rise, B rise, A fall, B fall). To take advantage of this would require 2 counters if I can do what I ask above, 4 counters if I can't, or external hardware. I don't need direction info and just want frequency.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-05-23 08:54
    schill,

    If you're trying to read a quadrature encoder there is an object by Parallax which does this for you using a PASM routine launched into another cog. It is highly accurate at high speed and can read from 1-16 encoders at the same time.
  • schillschill Posts: 741
    edited 2011-05-23 09:00
    It is a quadrature encoder, but I don't want to use it that way. I want to take advantage of the 50% duty cycle to get a more accurate frequency measurement. I can write code to do it easily enough - sampling a pin and counting the transitions. I'm just wondering if I can do it with a counter directly.

    And, I'd like to avoid using a cog just for the encoder. I can combine this with other code that depends on it in a single cog (I think).
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-05-23 09:17
    schill,

    If you're willing to add some external circuitry, you can use an XOR gate with one input connected to the encoder's A output, and the other to the B output. That will give you an output at twice the frequency of either channel alone.

    -Phil
  • schillschill Posts: 741
    edited 2011-05-23 09:24
    Thanks. I like the XOR solution with external hardware. But, I'm also trying to figure out what my options are if I don't add external hardware.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-05-23 09:29
    You could use two counters: one to count rising edges and one to count falling edges, then add their counts.

    -Phil
  • schillschill Posts: 741
    edited 2011-05-23 09:37
    You could use two counters: one to count rising edges and one to count falling edges, then add their counts.

    That's what I was indirectly referring to (without being clear at all) when I mentioned using 4 counters to measure all 4 rises and falls.

    If I can't measure both rises and falls with a single counter (which I don't think I can), I will probably resort to the external XOR solution and a single counter. I will end up connecting 2 encoders and I want to keep this in a single cog.
Sign In or Register to comment.