problem with d flip-flop rotary decoder

Thread Starter

razie1

Joined Jan 22, 2013
8
hello
I'm currently trying to make a rotary decoder using a d-flipflop,
for now all i want is that if flash Led1 for left rotation and led2 for right.
The problem im getting is that when i rotate right, led 2 will flash like it's supposed to but led1 with also flash but very dim.

I hope someone can help me solve the problem?

Thanks in advance,
Mike.


rotary decoder.jpg
 

GopherT

Joined Nov 23, 2012
8,012
Start by putting a 330 to 470 ohm resistor in series with your LED. The output of the chip must be current limited and the LED must be current limited too. The LED will drop about 2 volts (red LED) and you will want to drive them at about 5 mA (from a Logic chip).

I'll look at your logic later (or someone else will likely post in the mean time).
 

WBahn

Joined Mar 31, 2012
26,398
I'm assuming that the encoder is a quadrature encoder.

My quick gut reaction is that you are using one of the encoder outputs as your clock signal for your DFF and one of the reasons that quadrature encoders are used is that you can use the gray code behavior to deal with the bouncing outputs. But if you use a bouncing output as a clock signal, then your DFF will almost certainly see rising clock edges at both the rising and the falling edges of this signal.
 

Thread Starter

razie1

Joined Jan 22, 2013
8
ive added 330 resistors in series like you said which didn't have much effect on the rogue led flash just made it dimmer.

The encoder I'm using is a cheap mechanical quadrature and yes one one the outputs act as the clock.

so what would be the best way to remove or smooth out the bounce
 

WBahn

Joined Mar 31, 2012
26,398
I think this (second) circuit will avoid the problem of a bouncing clock signal.
I don't think so. If B is bouncing, then A is bouncing, too. The final outputs are generated by ANDing something with A, so if the other inputs is True and A is bouncing, then the output will bounce.

When I have used quadrature encoders it has been with a clocked system that sampled them periodically (fast enough to ensure that one of the phases wasn't missed). In that case, you don't care about the bouncing because it will resolve itself naturally. If you aren't sampling it, then it may be easiest to just debounce the signals. I'll have to think about that some more.
 

crutschow

Joined Mar 14, 2008
26,340
After some thought I was able to use just one 7474 dual-D FF with no additional logic to do the quadrature detection while ignoring any switch bounce of the output that is changing states. It uses the D and CK inputs to detect the quadrature phase direction and the Reset inputs to generate the pulses for the phase direction. "A" blinks when the phase is A\(\rightarrow\)B and "B" blinks when the phase is B\(\rightarrow\)A.

The 7474 can be any standard or CMOS version of the device, subject to the voltage and logic ratings of the device.

Edit: Note that if the 7474 is a TTL device, then the input resistor to ground would need to be a smaller value to insure a logic low when the switches open. That value depends upon which type of TTL it is (standard, low-power, Schottky, etc.)

Quadrature Detector.GIF
 
Last edited:

WBahn

Joined Mar 31, 2012
26,398
After some thought I was able to use just one 7474 dual-D FF with no additional logic to do the quadrature detection while ignoring any switch bounce of the output that is changing states. It use the D and CK inputs to detect the quadrature phase direction and the Reset inputs to generate the pulses for the phase direction. "A" blinks when the phase is A\(\rightarrow\)B and "B" blinks when the phase is B\(\rightarrow\)A.

The 7474 can be any standard or CMOS version of the device, subject to the voltage and logic ratings of the device.

View attachment 51232
I haven't looked at the details of the circuit yet, but my first reaction was, "Ugh. He's using asynchronous inputs and clocks together - recipe for disaster!". But as I was walking down the hall I was thinking about it and realized that this is an example of a situation in which playing this game can be both safe and elegant. The basic problem we are trying to address is that on the rising edge of each signal we don't care about bounces (multiple clock pulses don't hurt) but on the falling edge we don't want to see any of the bounces. But we can take advantage of the fact that the signals are in quadrature and use the other signal, along with state information, to hold the DFF in reset whenever we are at risk of seeing a falling edge in the other signal.

I'm not going to look at the details of your circuit until I use that notion to build my own and then compare the two.
 

crutschow

Joined Mar 14, 2008
26,340
There is one assumption I made about the bounce and that is, there is no bounce when the switch opens (which I believe is reasonable as bounce occurs from the contacts rebounding momentarily when they close). However if somehow there is a bounce when the switch opens then that would cause a circuit glitch (opposite LED turning on).
 

Brownout

Joined Jan 10, 2012
2,390
It really shouldn't because the D input should be stable due to the quadrature nature of the switch arrangement. So, you're double clocking a stable input, no glitch should result.

The only real hazzard was bouncing at release of the switch, when the input was in the opposite state, which you've fixed here.

Neither are the inputs and clocks asynchronous. The quadrature arrangement takes care of that.
 

Thread Starter

razie1

Joined Jan 22, 2013
8
Crutschow i tried the circuit yesterday and the leds chase each other, as if i just connected the leds directly to the encoder.

I don't know if it should be this way or that i just wired it wrong
 

crutschow

Joined Mar 14, 2008
26,340
Only one LED should blink for each direction of rotation. If not, then there is likely a wiring error or the encoder is outputting an incorrect signal.
 

Thread Starter

razie1

Joined Jan 22, 2013
8
Hi Crutschow I've double checked my wiring and still have the same outcome
so i think its down to the encoder
he is what the encoder outputs

left right
A-B A-B
0-0 0-0
0-1 1-0
1-1 1-1
1-0 0-1
 
Top