A=detA;
B=detB;
deltaA = A ^ prevA;
deltaB = B ^ prevB;
if (deltaA || deltaB) // any change
{
if (deltaA && deltaB)
{
// overrun
}
else if (A ^ prevB)
{
// count up
}
else
{
// count down
}
}
prevA = A;
prevB = B;
I didn't hear yet a clear statement about deviation from an ideal quadrature signal. The OP wants 4 counts per quadrature cycle, which is a reasonable requirement. The previously suggested D-FF circuit can't provide it, and it also tends to produce false counts with bouncing inputs or incremental back and forth rotations, that can occur in some applications. Decoding the quadrature signal like a gray counter gives exact count results in all situations.Perhaps your circuit can not deliver 50% duty cycle ??
D-FF does not count anything, it's purely used to indicate direction .....D-FF circuit can't provide it, and it also tends to produce false counts with bouncing inputs or incremental back and forth rotations, that can occur in some applications...
I think, your intentions are unclear. To refer to your previous statement:I have already tried similar code. It works fine for upcounting. But down counting will not work properly. Further, this type of coding doesn't actual counts if the change in pulses is too fast, even if are deteting the edges in interrupt mode. This is what I have observed.
There's no such thing as a D-FF in C. Furthermore you would need FFs acting on both edges to implement the requested 360 steps counter in hardware.But I am using a microcontroller to detect the angle, not flip flop or counters.
Could you explain how to achieve 360 deg bidirectional angle measurement using C, if we implement both D flip flop and up/down counter in C programming?
The problem is, that the direction information is only updated on the rising edge of one channel. I'm sure, you can figure out yourself, why the said solution produces false counts with "unsuitable" decoder moves.D-FF does not count anything, it's purely used to indicate direction ..
Surprizing.... But good news anyway.It is working fine with a pull up resistor of 5.1k at the output
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?