# Stepper motor control: Quadrature Enc. to step & Direction

#### qtron

Joined Aug 1, 2018
74
Am new to forum, couldnt find the right subject thread for my subject!
I wish to convert a quadrature encoder output to step & direction..
So 5 volt powered optical encoder with quadrature out (& an index pulse), to be converted to step & direction using simple cmos logic IC's.
i tripped over a schematic - well I thought it was, but turned out to be part of a PSoC, whatever that is.
Being undeterred I breadboarded the cct with 4000 series logic.
I couldnt find a Set/reset FF that didnt have a D input, so i built one using a quad, 2 input Nand gate, with a 4011B
( pls see http://hyperphysics.phy-astr.gsu.edu/hbase/Electronic/SRFFclock.html )
It's not normal step & direction! It also loses pulse in deciding direction..
Here is the reply upon asking the intended purpose of the setup:
"This circuit is made to read a quadrature encoder to detect rotational direction. And number of counts, it is not a cmos implementation, it is built with digital blocks on PSoC device"

i also looked at: https://www.allaboutcircuits.com/worksheets/flip-flop-circuits, was unclear to me from the logic offered as to which is correct.
Surely there must be a simple schematic that can do this, that MUST not lose a single step. - i cant be Robinson Crusoe here!
It must decide direction before 1 complete quadrature cycle too.
The output 'speed' , or RPM of the encoder is not going to be so hi as to cause propagation delays to need consideration ;-)
There is a commercial IC device avail, but buying it is becoming elusive, & it aint cheap (compared to CMOS).
Thanks HEAPS!

Joined Jul 18, 2013
21,630
Do you intend to use the signals and circuit to drive the stepper directly or input into a step/dir drive?
The difference is that driving directly you need use both Enc. quadrature signals the way they are, or at least amplified, if using a drive or other such method then the dir. signal requires to stay either 0 or 1 depending on direction.
A little more explanation of what you want to do would not hurt.
What is the resolution of the encoder?
Max.

Joined Mar 10, 2018
4,057
The PSOC has a multitude of components on its chip, a component being
an onchip resource. If you are generating stepper signals with PWMs the
PSOC can handle that as well as Quadec and other stuff like COM, LCD,
random logic, counters, timers, analog....

You can start with a $4 board on the low end, PSOC 4, highend board$ 10,
PSOC 5LP.

Regards, Dana.

#### qtron

Joined Aug 1, 2018
74
Do you intend to use the signals and circuit to drive the stepper directly or input into a step/dir drive?
The difference is that driving directly you need use both Enc. quadrature signals the way they are, or at least amplified, if using a drive or other such method then the dir. signal requires to stay either 0 or 1 depending on direction.
A little more explanation of what you want to do would not hurt.
What is the resolution of the encoder?
Max.
Thanks for fast response - yes will use a newly built (FET) stepper drive - just built one, full steps only, at this stage.
needs step & dir input.
...
VERY interesting that U should mention direct drive, amplified- I used an old chip, crappy darlington L298 stepper driver board, bought from Jaycar.com.au. [i had to provide some logic to invert signals for the four inputs on this board].
Unfortunately, after a LOT of time invested, the motor lost torque, even at quite slow speeds, despite trying to meet ALL the usual requirements for stepper driving. The interesting bit is that where the quadrature outputs overlap, ie when both signals are hi, that provides half stepping
see: https://www.jaycar.com.au/arduino-compatible-stepper-motor-controller-module/p/XC4492
..
I have set the encoder at a very low res, 128 ppr, according to CUI
see https://www.digikey.com/product-detail/en/cui-inc/AMT102-V/102-1307-ND/827015
its actually capacitive. [Their datasheet ppr table, & their view on interpreting ppr conflicts.. its actually only a low cost 500 line encoder!!]
the basic objective is to have a stepper follow precisely the encoders rotation, or at least at a suitable ratio.
if the encoder is set to 256 ppr, & the stepper is 200 steps per rev, then that ratio would be somewhere near the required amount, me thinks. But to be determined at a later date. - some sort of digital "gearbox" may be required, together with the right pulley ratios to get it all to work as required.

#### qtron

Joined Aug 1, 2018
74
The PSOC has a multitude of components on its chip, a component being
an onchip resource. If you are generating stepper signals with PWMs the
PSOC can handle that as well as Quadec and other stuff like COM, LCD,
random logic, counters, timers, analog....

You can start with a $4 board on the low end, PSOC 4, highend board$ 10,
PSOC 5LP.

Regards, Dana.
thanks,
but want to use basic logic at this point. Cant program code, amoung other issues!

Joined Jul 18, 2013
21,630
Interestingly a stepper motor can be used to drive an identical one direct, as in the original servo system!
One problem as you may know, using the rated volt/amp rating of the motor, it does not take many rpm's before you run out of torque.
An old method was to use a higher voltage supply with a series resistor for automatic compensation, now usually a higher P.S. voltage and PWM control is used in order to overcome this.
Max.

#### qtron

Joined Aug 1, 2018
74
Interestingly a stepper motor can be used to drive an identical one direct, as in the original servo system!
One problem as you may know, using the rated volt/amp rating of the motor, it does not take many rpm's before you run out of torque.
An old method was to use a higher voltage supply with a series resistor for automatic compensation, now usually a higher P.S. voltage and PWM control is used in order to overcome this.
Max.
yes, my first test. & yes, i tried that trick too
anyway, any ideas?

#### qtron

Joined Aug 1, 2018
74
the torque fell away at VERY low rpm, BTW.

#### ebp

Joined Feb 8, 2018
2,332
"Likewise, a clock pulse must have the reset NAND gate high to receive a high RESET pulse. Therefore all transitions are synchronized to the clock."

This is complete nonsense. As long as the clock is high, the state can be changed immediately by the R and S inputs.

#### qtron

Joined Aug 1, 2018
74
"Likewise, a clock pulse must have the reset NAND gate high to receive a high RESET pulse. Therefore all transitions are synchronized to the clock."

This is complete nonsense. As long as the clock is high, the state can be changed immediately by the R and S inputs.
Oh! thanks Mr ebp! funny how one can rely on those that "know more" only to be led astray.
I actually didnt absorb the text at all, just built the cct.

#### jbeng

Joined Sep 10, 2006
75
What you're looking for here is a phase detector. Here's a diagram of one we used years ago which doesn't have the NAND gate. See if this one works any better than the one you're using now. (no promises, though)

#### qtron

Joined Aug 1, 2018
74
What you're looking for here is a phase detector. Here's a diagram of one we used years ago which doesn't have the NAND gate. See if this one works any better than the one you're using now. (no promises, though)

View attachment 157379
Thankyou jbeng, U seem to have beaten others to the punch!
Wonderful! I assume the o/p doesn't change state until theres a change of phasing at the input..
The thing that puzzles me with these logic setups is, dreaming up the solutions! I cant.
- Is it out of a book of ingenious solutions, is it taught as part of a list of basic logic 'mechanisms' or..?