Interfacing circuit

21,435

Circuit Image

After conducting experiments with a rotary encoder connected directly to keyboard switches, it was found that the keyboard controller IC (an Intel P8049AH in this case) is unable to detect pulses that are too narrow. Testing involved rotating the encoder quickly and observing the key output in Notepad. Key ON pulses shorter than 20 milliseconds are ignored or unstable. Additionally, the time interval between two key presses must exceed 20 milliseconds; thus, the rotary switch outputs require pulse width modification before interfacing with the keyboard. As the keyboard switches lack a common ground, it is advisable to use a relay or opto-coupler for driving. Relays are too noisy for repeated switching, making opto-couplers the preferred option. The circuit diagram illustrates the rotary switch action (both slow and fast) and the necessary keyboard switch action for stable key recognition. A buffer circuit maintains the speed for the keyboard controller to follow during rapid rotary encoder turns. The D-flip-flop (one-half of the CMOS HEF4013 IC) determines the direction of rotation. Depending on the direction, the HEF4013 Q output will be high while Q is low, or vice versa. These outputs enable upper and lower one-shot circuits built with the HEF4538 IC. These one-shot circuits reshape the pulses from the rotary encoder as depicted in the drawing. Since Q and Q are inverses, only one section drives the keyboard through one opto-coupler based on the turning direction. The first one-shot has a longer duration than the second, with both triggered by pulses from one of the rotary encoder switches. The first negative-going pulse produces output pulses at both Q outputs, with the pulse duration determined by the resistor-capacitor (R*C) combination connected to the timing pins. The Q output pulse from the first one-shot lasts 0.07 seconds, while the second lasts 0.033 seconds. As long as the first one-shot output remains high, neither one-shot can be retriggered by additional rotary encoder pulses. Even with rapid encoder rotation, the opto-coupler receives a pulse that is at least 0.033 seconds high and 0.032 seconds low. Given that CMOS ICs have limited current output, an emitter follower was added to drive the opto-coupler, utilizing a BC548C (or BC547) standard small-signal NPN transistor. The circuit is not flawless, as occasional false pulses may occur from the other section while tuning in one direction. Adding 1 nF (0.001 µF) capacitors at the rotary switches may mitigate some issues, although they were not employed in this instance. The performance for elevator trim was found to be satisfactory. This circuit can also be adapted for rudder trim, where rotation is typically slower, allowing for some simplifications. The trigger inhibit after the initial ON pulse can be omitted, saving one IC. The rotation direction detection can be accomplished using the other half of the HEF4013 IC. The circuit is illustrated below. Although some pulses from the original encoder output may be lost, the final pulse count is optimized for keyboard interfacing and performs significantly better than without the pulse-shaping buffer.

The circuit described integrates a rotary encoder with a keyboard interface through pulse width modulation techniques to ensure reliable key presses. The rotary encoder, when turned, generates pulses that are processed by a D-flip-flop, which determines the direction of rotation. This information is then utilized to trigger two one-shot circuits that reshape the pulses to meet the keyboard controller's requirements. The choice of using an opto-coupler instead of a relay minimizes noise and allows for cleaner signal transmission. The use of timing components, such as resistors and capacitors, ensures that the output pulses are of adequate duration to be recognized by the keyboard controller, thereby maintaining stable operation. The addition of an emitter follower transistor enhances the current drive capability for the opto-coupler, ensuring that the circuit can handle the demands of rapid rotary encoder operation. The potential for false pulses indicates the need for further refinement, possibly through the incorporation of capacitors to filter out noise. Overall, this design demonstrates a practical application of digital logic and signal processing techniques in interfacing mechanical components with electronic systems, providing a reliable solution for applications requiring precise control inputs.After doing some experiments with the rotary encoder directly connected across the keyboard switches, I found that the keyboard controller IC (an old Intel P8049AH in my case) cannot detect too narrow pulses. (I checked this by rotating the encoder fast and checking with Notepad to see the key output). If key ON pulses are less than 20 msec, the k ey press is ignored or unstable. I also found that the time between two key presses cannot be too short either: The OFF time between two ON pulses needs to be more than 20 msec as well. This means that the rotary switch outputs need to undergo some pulse width modification before they can drive the keyboard.

As mentioned before, the keyboard switches do not have a common ground, and therefore are best driven by means of a relay or Opto-coupler. For repeated switching, relays are too noisy. In this case, Opto-couplers are preferred. The drawing above shows the rotary switch action (slow and fast turning) and required keyboard switch action to maintain stable key recognition.

When the rotary encoder is turned very fast, the buffer circuit in between maintains the speed that the keyboard controller still can follow. In the above circuit, the D-flipflop (one-half of CMOS HEF4013 IC) determines which direction the rotary encoder turns.

When turning in one direction, HEF4013 Q output will be high and Q will be low. When turning the other direction, the situation reverses. When high, these outputs Q and Q enable upper and lower one-shot circuits build with IC HEF4538. These one shot circuits are used to re-shape the pulses from the rotary encoder as shown in the drawing. Since Q and Q are each others inverse, only one section will drive the keyboard via one opto-coupler, depending on the turning direction.

For info on the IC ’s do a search at. The first one-shot has a twice longer time than the second. Both are triggered by the pulses of one of the switches of the rotary encoder. The first negative going pulse will produce a pulse at both Q outputs. The pulse time duration is equal to R*C as connected to the timing pins. The Q output pulse of the first one-shot lasts 0. 07sec, that of the second 0. 033sec. As long as the first one-shot output is high, neither one-shot can be re-triggered by additional pulses of the rotary encoder. Even if the encoder is turned very fast, the opto-coupler is driven with a pulse that is at least 0. 033sec high and 0. 032sec low. Since CMOS IC ’s cannot deliver a lot of current, I added an emitter follower to drive the Opto-coupler.

BC548C (or BC547) is a standard small signal NPN transistor. (see ) The circuit is not perfect, as there are occasionally false pulses from the other section while tuning one direction. Adding 1 nF (0. 001uF) capacitors at the rotary switches may help somewhat. (I did not use them). For elevator trim, I found the performance satisfactory. In principle, the same circuit can be used for rudder trim. Since rudder trim is normally not rotated very fast, some simplifications can be made: I deleted the trigger inhibit after initial ON pulse, thereby saving one IC.

The rotation direction detect circuit can be made from the other half of the HEF4013 IC. The circuit is shown below. (Although you loose some pulses from the original encoder output, the final pulse count is the most you can get via the keyboard, and works much better than w/o pulse shape buffer). 🔗 External reference