1
\$\begingroup\$

I am stripping this problem down to the bare minimum.

I have KY-040 Rotary Encode, When it is turned clockwise I want a blue LED to blink for every increment it is turned. When it is turned anti clockwise I want a red LED to blink for every incremented is turned.

I can have anything between them (but not a PI or arduino type barebone computer)

I have looked at flip flop chips but with the wave signal that comes out of the KY-040 Rotary Encoder I got quickly confused.

\$\endgroup\$
  • 3
    \$\begingroup\$ If you already have the code, why wouldn't you just flash the LEDs from the code? \$\endgroup\$ – Dave Tweed Mar 6 '17 at 12:57
  • \$\begingroup\$ Easy. It has 2 outputs. One leads the other turning one way, and lags when turning the other way. If that's not enough hint, any rotary decoder interface circuit should show you how to do it. \$\endgroup\$ – Brian Drummond Mar 6 '17 at 12:57
  • \$\begingroup\$ Hate to shock you Brian, but I have never knew rotary decoder interface circuit were a thing. \$\endgroup\$ – Ashley Kilgour Mar 6 '17 at 13:05
  • 5
    \$\begingroup\$ cardinal rule: No datasheet ⇒ No sale \$\endgroup\$ – Nick Alexeev Mar 14 '17 at 17:15
  • 1
    \$\begingroup\$ Well, you seem to understand rotary encoders as you could do this in software eight days ago http://electronics.stackexchange.com/questions/290679 - albeit with a yellow LED instead of a red one. \$\endgroup\$ – Finbarr Mar 14 '17 at 17:21
3
\$\begingroup\$

probably the 2 outputs have a quarter pulse lenght shift. Use one output as the known amount rotation indicator (=every rising edge means a known angle increment) and the other is the direction; checked when the angle increment occurs.

Your led flashing circuit:

enter image description here

ADDENDUM: The fi2 output of the rotation sensor states how long the led light pulse is ON. Of course you might want to limit that in case the rotation stops just when fi2=High. For that you can add a monostable multivibrator between fi2 and the nand gates to limit the on-state lenght.

\$\endgroup\$
  • \$\begingroup\$ Yeah that was what I was wanting to do. I dont care how many times it has been turned. So how would you do what you have stated usiing the two LED example I gave in the question? \$\endgroup\$ – Ashley Kilgour Mar 6 '17 at 13:19
  • \$\begingroup\$ @AshleyKilgour the circuit is added \$\endgroup\$ – user287001 Mar 6 '17 at 14:21
  • \$\begingroup\$ Cheers for that, so would i just need a maplin.co.uk/p/4013-cmos-logic-hcfhef-qx07h between the rotery enocode and the LED's? \$\endgroup\$ – Ashley Kilgour Mar 6 '17 at 16:59
  • \$\begingroup\$ @AshleyKilgour 4013 is ok. But it needs a proper operating voltage (usually 5VDC) and its unnecessary inputs must be connected to gnd. You need also 4011 nand gate - same for its operating voltage and unused inputs. Your sensor, the rotary encoder must have 4000-series CMOS compatible output signals (if not, you need the proper buffer circuitry). Note that I know nothing excact numeric about your rotary encoder, only the general operating principle. 4000 series CMOS outputs can give only a weak current to leds. The resistors should be at least 1000 Ohms. \$\endgroup\$ – user287001 Mar 6 '17 at 20:34
1
\$\begingroup\$

schematic

simulate this circuit – Schematic created using CircuitLab

  • R! is negative logic input.
  • A Leads B for Up
  • Alternatively using S with positive logic and Q bar outputs.
  • SIM
\$\endgroup\$
0
\$\begingroup\$

I don't think it'll come as a surprise when I tell you that you'd often just write a bit of software that runs on a microcontroller to do exactly that.

However, the encoder logic is so simple that you can write it down as boolean combination of the sensors. So, with a very minimal amount of discrete logic gates, you can do that.

So, the mechanism for this kind of problem is to write down your problem as state machine (you're a CS person – you should know state machines) and then implement these states in hardware, simplifying where possible.

\$\endgroup\$
  • \$\begingroup\$ So basically "Write down the problem and then implement it in hardware". \$\endgroup\$ – Bort Mar 6 '17 at 13:02
  • \$\begingroup\$ @Bort hehe, yes :) well, my impression of OP was that she needed the nudge in the direction of "boolean logic", "state machine" and "logic gate", nothing more :) \$\endgroup\$ – Marcus Müller Mar 6 '17 at 13:04
  • \$\begingroup\$ I don't want to have the code tied to the hardware, I could just as easily have two buttons one marked plus and minus. Being a c# I don't like things being tied together. \$\endgroup\$ – Ashley Kilgour Mar 6 '17 at 13:06
  • \$\begingroup\$ @AshleyKilgour I don't understand your comment, sorry, the least. \$\endgroup\$ – Marcus Müller Mar 6 '17 at 13:08
  • 1
    \$\begingroup\$ so, two things: a) my answer isn't only about software implementation. In fact, only the first sentence is. b) this is the ultimate web developer attitude. Seriously, your problem is to design a decoder for a specific kind of input. No surprise, with a different kind of input, you'll need a different decoder. What the hell were you expecting?! \$\endgroup\$ – Marcus Müller Mar 6 '17 at 13:22
0
\$\begingroup\$

Bi-Directional encoders usually give out two signals in quadrature. That is, two square waves 90 degrees out of phase. You can tell the direction by the state of the second line on the rising or falling edge of the first line.

____|----

BTW: Here is the Spec

Re your LEDS....

Simply feed one phase into the clock of a D-Type latch and the other phase into the D-Pin. The output Q will change with direction of rotation. Use that to enable power to high end of the appropriate LED (Resisitor). Use one phase to drive the low end of both LEDS.

\$\endgroup\$
  • \$\begingroup\$ Does not meet the Op's requirements. This solution won't blink for every increment of the state....it will only show the last direction of movement. \$\endgroup\$ – Jack Creasey Mar 14 '17 at 19:12
  • \$\begingroup\$ @JackCreasey, I was assuming the OP knew how to do that part..but you are right... never assume anything in SO-Land \$\endgroup\$ – Trevor_G Mar 14 '17 at 19:14
-1
\$\begingroup\$

Knowing direction for a quad encoder is a combo of knowing the OLD STATE, the NEW STATE, and having a lookup table to determine the direction.

For example, in the Figure in Trevor's Answer, lets say you start at the state of the top channel being zero, and the bottom channel being zero (i.e, "00"). If the next state is "10", you've moved forward, and if the next state is "01" you've moved backward.

So, \$00|10 \rightarrow \$ forward motion, meaning you add one to your count and \$00|01 \rightarrow \$ backward motion, and you subtract one. You'll find that there are 16 possibilities, and some of them can't exist unless you've skipped a tick.

The easiest way to implement this is probably a purpose-made integrated circuit, like this, which takes care of the whole thing. Second easiest is probably a microcontroller. Last would be writing out the state machine, generating a Karnough Map, and grunting out a flip flop implementation.

\$\endgroup\$
  • \$\begingroup\$ Or if you are just using it to count pulses with a basic up-down counter just use one phase as a clock and connect the other phase to the Up_Down pin. \$\endgroup\$ – Trevor_G Mar 14 '17 at 17:45
  • \$\begingroup\$ @Trevor, yes, but you lose half your resolution. \$\endgroup\$ – Scott Seidman Mar 14 '17 at 18:06
  • \$\begingroup\$ Yes I know Scott, well 3/4 loss really. But it depends on if you need that much resolution. It all depends on usage. \$\endgroup\$ – Trevor_G Mar 14 '17 at 18:12
  • 1
    \$\begingroup\$ @Trevor -- wasn't trying to invalidate the approach so much as to make the OP aware of the compromise. \$\endgroup\$ – Scott Seidman Mar 14 '17 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.