I need to generate a 10-100khz square signal freq. to simulate an encoder.

I'd like to be able to simulate CW and CCW, shifted by 1/4 th signal. I've thinked about a crystal with a pot and some logic gates. But don't have enought experience to create a circuit like this.

Can you redirect me to a sample schematic or components to start with?

Ex. https://www.allaboutcircuits.com/uploads/articles/rotary-encoder-waveform-v2.jpg

/* UPDATE */

10khz-100khz 24v

Why: it's becouse I'd like to have a tool to simulate motor encoder output to debug my system which has an encoder input.

A micro or develop kit it's too expensive and overkill. Also low cost micro have difficults at this freq.

  • \$\begingroup\$ You need to think this through a lot more and provide detail in your question. (1) Do you want a precise number of steps? If so, you'll need a counter. (2) Clarify if it's 10 Hz - 100 kHz or 10 kHz to 100 kHz. Your question could be read either way. (3) What voltage is your logic? \$\endgroup\$
    – Transistor
    Mar 18, 2019 at 11:28
  • \$\begingroup\$ You need to give a good reason why you need to emulate an encoder when it would be just as easy to use an actual encoder to generate your pulses. \$\endgroup\$ Mar 18, 2019 at 11:37
  • \$\begingroup\$ Thanks, Singed, for the update. This sounded very much like a motor encoder issue. (I worked on a system to calibrate and align infusion pump motors for medical use and the frequencies you mentioned were about right.) Do you already have access to a frequency generator? (Commercial or 555 timer based or any other source of some adjustable square wave?) Also, do you need to control the number of pulses for your tests? Or is it sufficient that it simply generates a forward/backward pulse train whose frequency can be only blindly varied (imprecise but variable?) \$\endgroup\$
    – jonk
    Mar 18, 2019 at 20:16

3 Answers 3


I'll assume you can work out the variable square wave oscillator. This might be a 555 timer based design (found everywhere), though you may need to put its output into a JK FF to divide the frequency by two in order to square it up to a clean 50/50 duty cycle.

The following circuit doesn't involve an MCU (which for many reasons might still be your better appraoch.) It's just a simple bit of logic that assumes you can supply it with a square wave at \$4\times\$ the actual rate you want. The counter is synchronous and so the output should be relatively clean.


simulate this circuit – Schematic created using CircuitLab

The above system requires two D-flops (in a twisted ring Johnson counter arrangement) and two muxes (to make the twisted ring Johnson counter reversible.) Shouldn't be difficult to select appropriate logic families and then wire it up. Something like the 74LS175 and 74LS157.

If my head is on straight, setting the UP/DOWN to 0 will have A leading B and to 1 will have B leading A.

EDIT: I liked the muxes shown above better because you can get quads of them in a single IC package and because I enjoyed the relative symmetry of it. And so I avoided writing the following, earlier. I've got a moment to add the other thought in my head (not as nice, though, in my opinion.)

So, if you don't like muxes for some reason or otherwise don't mind multiple IC packages with different gate types, then you could use the following schematic instead (or any of nearby varieties of it):


simulate this circuit

This also doesn't use the \$\overline{Q}\$ output of the D-type FF. (That may expand your options a little for the D-type FF devices.) But now you can't get everything into two packages (or at least, nothing comes to my mind where only two SSI/MSI ICs might be used.)

Your call.


Get the most simple microcontroller you can find, each evaluation kit should do. The code is just a few lines, plus you can easily change it afterwards if the need arises.


An MCU is likely the best approach, and far less expensive than you think. This also has the advantage that if connected to a PC you can integrate it into a test suite - not only inject signals, but evaluate the result as well.

However, another option would be a (plain) stepper motor sequencer chip with step and direction inputs, such as an L297. See the A and C signals in half step mode on page 5/11 of the data sheet, and notice how they resemble your encoder waveform. Just be sure not to use the chopping current control modes, as that would rather confuse things (though in theory in a way that should be rejected).

Ultimately the functionality you want is that of a two-bit Gray Code counter.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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