Go Down

Topic: Rotary encoders, 74LS14's and 74LS74's (Read 6 times) previous topic - next topic

MarkT

Does you application require absolute repeatability of position?
[ I won't respond to messages, use the forum please ]

neema_t

#6
Apr 22, 2011, 01:16 am Last Edit: Apr 22, 2011, 01:26 am by neema_t Reason: 1
No, I probably should have explained what I want to do with it. All I really want it to do is tell the Arduino which direction the user is rotating it, that's all, in pseudo (not at all accurate) code it would be something like:

if (encoder == increased){
digitalWrite (outputUp, HIGH);
} else if (encoder == decreased){
digitalWrite (outputDown, HIGH);
}

All that matters is which way it's going, not where it starts and ends up.


Edit:
Originally I was hoping to have a variable for the current value of the two encoder pins, then when the encoder is rotated the Arduino would read the pins and decide which direction it was going. With Mike's circuit that would be made a bit easier in that it would just read a 'step' variable and wait for a pulse, then write the result of the direction pin to the required output.

Grumpy_Mike

Quote
and the Q with a line over it (in fact each of those are overlined)

When a logic name has a line over it it means NOT or negative logic. That is to say the name is true when the signal is a logic zero (or false). So an input named clear would clear the output (set to zero) when the input was at a logic one. However, clear with a bar over it would indicate that the output would be cleared only when there was a logic zero on the input.
The preset and clear lines should in this circuit be connected to a logic one (that's 5V). The flip flop has two outputs Q and Q bar, these are always the inverse of each other, so what ever state the output Q is then Q bar is the inverse of this.

Your rotary encoder is fine for what you want to do.

The problem you are making for your self is that you are not looking for an edge you are looking at the level. To see an edge you have to remember what the level was like last time you read it (use a variable) then only when last time was a zero and this time is a one you have a step.

neema_t


The problem you are making for your self is that you are not looking for an edge you are looking at the level. To see an edge you have to remember what the level was like last time you read it (use a variable) then only when last time was a zero and this time is a one you have a step.


I think I'm following you, but I don't understand how to actually implement it. Going back to one of your earlier posts:


The step output is simply one of the encoder's outputs and will change directly with it.


This is the bit that confuses me the most. I understand that you mean the change from low to high on one encoder output basically 'clocks' the Arduino to tell it there has been a step, but if my encoder's outputs only switch from low to high on every other physical rotation step, how can it tell when there has been a step in between? If you refer to the encoder's data sheet, you can see the 2-bit model has one pin that goes low, high, high, low and the other is one step out of phase and goes low, low, high, high, so it would only 'clock' the Arduino once per two steps.

I kind of understand what you said directly after that, though I think I totally missed it the first time I read it:

Quote

On the rising edge of this signal the state of the other output from the encoder is latched or remembered. This will be always the same for the same direction of rotation.


However, I don't understand how to make the 7474 actually do that. It makes sense, though, I just can't quite get my head around it, but I feel like I'm getting close...

Grumpy_Mike

A 74LS74 is a latch. Its function is to transfer and hold the logic level on the D input to the Q output (and inverse on the Q bar output) when the clock signal goes from a zero to a one. That it it is an edge latched memory, it takes a snapshot of the D input every transition of the clock.

Quote
but if my encoder's outputs only switch from low to high on every other physical rotation step, how can it tell when there has been a step in between?

With that circuit you only get a sample on the positive edge, that is every other click for your encoder. If you want to get a sample every click then you need two of these circuits (remember there are two D-type latches in one package and six inverters). On the second circuit you need to feed it with the inverse of the signals (put them through a spare inverter). Then you have two steps and two direction signals, these could be combined with another gate (an OR or NOR gate) or fed directly to the arduino.

Or you can use interrupts generated off each edge like in these links:-
http://www.arduino.cc/playground/Main/RotaryEncoders
http://arduino.cc/playground/Main/RotaryEncoderAcceleration

Go Up