count both rising and falling edges of signal with single counter?
schill
Posts: 741
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.
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
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.
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).
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
-Phil
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.