ELM402 Rotary Decoder - 2 wire 2x Interface Description Features The ELM402 is an 8 pin integrated circuit that is used to convert the signals from a rotary encoder into a series of up and down output pulses. The low power CMOS technology used ensures that only a very small current is required over the entire 2.0 to 5.5 volt operating range. There is no need for external filtering or debounce circuits with the ELM402, as this is all performed within the integrated circuit. After debouncing the encoder signals, the ELM402 then determines the direction of shaft rotation, and generates the appropriate pulses at the Up or Down output pins. The duration of these pulses can be selected for either 0.2 or 2.0 msec. The ELM402 provides 2x decoding of a rotary encoder signal. If your application requires 4x decoding, please see the ELM403 (it is identical to the ELM402 in every respect, except that it provides 4x decoding). • • • • • • • Low power CMOS design Wide supply range – 2.0 to 5.5 volts Complete debouncing of the encoder inputs No external filtering needed 2x decoding Startup delay timer High current drive outputs Connection Diagram PDIP and SOIC (top view) VDD 1 8 VSS A 2 7 Up B 3 6 Down Pulse Width 4 5 Output Invert Applications • • • • Digital audio potentiometer controls Variable voltage or temperature circuits Positioning controls Tuning circuits Block Diagram VDD A 2 VDD ELM402DSA Direction Decoding B 3 Rotary Encoder Debounce Circuit Up 6 Down Output Logic Debounce Circuit Pulse Width 7 4 Elm Electronics – Circuits for the Hobbyist www.elmelectronics.com 5 Output Invert 1 of 9 ELM402 Pin Descriptions VDD (pin 1) This pin is the positive supply pin, and should always be the most positive point in the circuit. Internal circuitry connected to this pin is used to provide power on reset of the internal logic, so an external reset signal is not required. Refer to the Electrical Characteristics section for more information. A (pin 2) This input should be connected to what is normally known as the ‘A’ signal from a rotary (quadrature) encoder. The signal at this pin should lead (ie change state before) the signal at pin 3 when the device is being moved in a clockwise or up direction. An external pullup resistor is required for the encoder (a typical value is 10 KΩ), but no external capacitors are needed (as the internal debounce circuitry provides the filtering). B (pin 3) This input should be connected to what is normally known as the ‘B’ signal from a rotary (quadrature) encoder. The signal at this pin should lag behind (ie change state after) the signal at pin 2 when the device is being moved in a clockwise or up direction. An external pullup resistor is required for the encoder (a typical value is 10 KΩ), but no external capacitors are needed (as the internal debounce circuitry provides the filtering). Output Invert (pin 5) This input can be used to invert the output signals at pins 6 and 7. If pin 5 is at a low level, the outputs will maintain a low quiescent level, with the pulses going to the VDD level. If pin 5 is set to a high level, the outputs will normally be at a high level, with pulses going low (to Vss). This input can be changed at any time. Down (pin 6) and Up (pin 7) These two outputs pulse as the rotary encoder moves. For a clockwise movement (the A input appears first, followed by the B), pulses will appear at the Up output, and the B output will remain at a constant level. For counter-clockwise movement, the Down output will pulse, and the Up output will remain at a constant level. See the Output Waveforms section (page 7) for a pictorial view of these outputs. VSS (pin 8) Circuit common is connected to this pin. This is the most negative point in the circuit. Pulse Width (pin 4) This input controls the width of the pulses which appear at pins 6 and 7. If the input is high, the pulse width will be 2.0 msec, while a low input sets the pulse width to 0.2 msec. This input can be changed at any time. All rights reserved. Copyright 2011 Elm Electronics. Every effort is made to verify the accuracy of information provided in this document, but no representation or warranty can be given and no liability assumed by Elm Electronics with respect to the accuracy and/or use of any products or information described in this document. Elm Electronics will not be responsible for any patent infringements arising from the use of these products or information, and does not authorize or warrant the use of any Elm Electronics product in life support devices and/or systems. Elm Electronics reserves the right to make changes to the device(s) described in this document in order to improve reliability, function, or design. ELM402DSA Elm Electronics – Circuits for the Hobbyist www.elmelectronics.com 2 of 9 ELM402 Ordering Information These integrated circuits are only available in either a 300 mil plastic DIP format, or in a 150 mil SOIC surface mount type of package. To order, add the appropriate suffix to the part number: 300 mil Plastic DIP............................... ELM402P 150 mil SOIC..................................... ELM402SM Outline Diagrams The diagrams at the right show the two package styles that the ELM402 is available in. The first shows our ELM402P product, which is an ELM402 in a 300 mil DIP package. This is a standard through hole type dual inline package. The ELM402SM is our surface mount version of the ELM402. The device package has a 3.90 mm wide body, and is commonly called a 150 mil SOIC package. The drawings shown here provide the basic dimensions for these ICs only. Please refer to the following Microchip Technology Inc. documentation for more detailed information: • Microchip Packaging Specification, document name en012702.pdf (7.5MB). At the www.microchip.com home page, click on Packaging Specifications, or go to www.microchip.com/packaging ELM402P 2.54 6.35 max 10.92 ELM402SM 1.27 3.90 6.00 • PIC12F508/509/16F505 Data Sheet, document 41236E.pdf (1.5 MB). At the www.microchip.com home page, click on Data Sheets, then search for 12F508. ELM402DSA Note: all dimensions shown are in mm. Elm Electronics – Circuits for the Hobbyist www.elmelectronics.com 3 of 9 ELM402 Absolute Maximum Ratings Storage Temperature....................... -65°C to +150°C Ambient Temperature with Voltage Applied..................................-40°C to +85°C Voltage on VDD with respect to VSS............ 0 to +6.5V Note: Stresses beyond those listed here will likely damage this device. These values are given as a design guideline only. The ability to operate to these levels is neither inferred nor recommended. Voltage on any other pin with respect to VSS........................... -0.3V to (VDD + 0.3V) Electrical Characteristics All values are for operation at 25°C and a 5V supply, unless otherwise noted. For further information, refer to note 1 below. Characteristic Minimum Typical Supply voltage, VDD 2.0 5.0 VDD rate of rise 0.05 Power on reset time 9 Average supply current, IDD Maximum Units 5.5 Conditions V V/msec see note 2 18 30 msec see note 3 0.6 1.1 mA VDD = 5.0V 0.2 0.3 mA VDD = 2.0V VDD = 5.0V 10 mA VOL = 0.25V VDD = 3.0V 5.0 mA VOL = 0.25V VDD = 5.0V 2.5 mA VOH = 4.75V VDD = 3.0V 1.7 mA VOH = 2.75V Debounce period 5.5 msec Startup time delay 50 msec Internal timing variation 1 Output low current (sink) Output high current (source) 4 % see note 4 see note 5 Notes: 1. This integrated circuit is based on a Microchip Technology Inc. PIC12F5XX device. For more detailed specifications, please refer to the Microchip documentation (www.microchip.com). 2. This spec must be met in order to ensure that a correct power on reset occurs. It is quite easily achieved using most common types of supplies, but may be violated if one uses a slowly varying supply voltage, as may be obtained through direct connection to solar cells, or some charge pump circuits. 3. The internal reset circuitry stops the ELM402 from doing anything during this period, so that the power supplies and oscillators have time to stabilize. During this time, all pins behave like inputs. 4. Typical only - the actual period varies with the amount of noise present in the input signal. 5. All filtering, delay, and output timing is based on an internal master oscillator. The frequency of this oscillator will vary with voltage and temperature. Values shown are typical maximums for 2.0V ≤ VDD ≤ 5.5V, and temperatures of -40°C to +85°C ELM402DSA Elm Electronics – Circuits for the Hobbyist www.elmelectronics.com 4 of 9 ELM402 Rotary Encoders A rotary encoder (sometimes referred to as a quadrature encoder) is a device that produces digital (on/off) outputs in response to rotary, or circular, motion. It is often constructed such that it looks very much like a potentiometer, or audio volume control (see the picture of a typical device, at the right). As the encoder shaft is turned, internal contacts open and close, creating two waveforms that are ideally separated in phase by 90 degrees (ie ‘in quadrature’). Actually, you need to provide external ‘pullup’ resistors and a power supply to create these waveforms, as the contacts themselves can not do this. An ideal waveform from a rotary encoder would look like this: A B Figure 1. Quadrature Waveforms Due to the 90 degree phase difference, when one waveform changes, the other is always stable. By noting the direction of the change and the level of the other input at that time, you can determine the direction of motion of the shaft. Rotary encoders are not ideal, however. Due to their construction, and variations in shaft speed, the A typical rotary encoder waveforms are not perfectly square with the 50% duty cycles shown. Figure 2 shows a captured trace from a real rotary encoder that is more representative of what you will typically find. Note that the two ‘scope channels (1 and 2) represent the encoder outputs A and B, respectively. The ch 1 (A) waveform leads the ch 2 (B) waveform, which usually means that the shaft is turning in a clockwise direction. The first rising edge of the channel 2 waveform shows another problem that occurs with moving mechanical contacts - multiple pulses due to bounce. When two contacts meet, the moving one will tend to bounce, like a ball does when it is dropped on the floor. Each bounce results in an electrical connection being made, then broken, which will look like multiple inputs to a fast electronic circuit. Various mechanical means are used to reduce the amount of bounce, but it can never really be eliminated. The following section discusses how the ELM402 uses electronic means to remove the bounce. Figure 2. Actual Rotary Encoder waveform ELM402DSA Elm Electronics – Circuits for the Hobbyist www.elmelectronics.com 5 of 9 ELM402 Debouncing Circuits Any time that two metal surfaces meet, as they do inside a rotary encoder, there will be a tendency for the moving one to bounce, which causes the electrical connection to make and break. The duration of this bouncing action may be very short, but it is usually fast enough to cause multiple counts to be recorded by connected electronic circuits. As the number of bounces can not be predicted, a means of removing them is necessary. Circuits that remove the bounce are usually called ‘debouncing’ circuits. Many debouncing circuits employ a simple timer to determine if an input is stable. This generally works well if the two contacts meet and then remain still. With a rotary encoder however, one of the contacts meets the other then usually continues sliding over the surface of the stationary contact. This will produce noise while the contact is sliding, occasionally enough to make it look like there are more inputs. The ELM402 employs a two stage system to remove the bounce and the sliding noise from the input signal. A block diagram of the stages are shown in figure 3. The first stage is a digital filter circuit that is used to determine the average value of the waveform over a time. If a long enough time is chosen, short duration pulses will have little effect on the overall average. If the time chosen is too long, however, the circuit will be slow to respond, and may in fact average out some legitimate inputs. Choosing the time period (or time constant of the circuit) is thus very important in determining how effective the filtering function will be. We have found that with typical rotary encoder specifications (usually 3.0 msec of bounce or noise, maximum), the ELM402 debounce circuit works quite well. After the signal has been filtered, it is compared to some reference levels, and the output of these comparators are used to control a simple timer. The timer is used to ensure that the output of the filter is stable, and not just a momentary transient, while the use of two comparator levels provides hysteresis, so that some variation in the filter output can be tolerated. Once the signals from the rotary encoder have been debounced, they may be used by the direction logic circuitry. The following section shows what the ELM402 is able to produce from these signals. rotary encoder input 3 msec timer to output logic tc = 1.7 msec filter timer Figure 3. Internal Debouncing Logic ELM402DSA Elm Electronics – Circuits for the Hobbyist www.elmelectronics.com 6 of 9 ELM402 Output Waveforms Once the ELM402 has some bounce-free signals to work with, it can generate outputs based on them. The logic to decode the motion of an encoder shaft is not as simple as it would first appear. Some authorities recommend simply monitoring an input and when it changes, provide an output based on the level of the other input. This does not always work, as the encoder can output multiple signals from only the ‘A’ or or only the ‘B’ contact if the shaft is moved ever so slightly when at the detent or at the mid-point position (between detents). Simply seeing one input change is not sufficient to say that there is any significant shaft rotation. The ELM402 monitors both ‘A’ and ‘B’ transitions, and determines the outputs based on the sequence in which the transitions have occurred. This is a better way to guarantee that the output signals are generated properly. The internal logic also performs some selfchecking, and monitors for problems such as an output pulse being initiated before the previous one had completed, which might occur for some very fast inputs (the second one will be ignored in this case). The output of the ELM402 is simply a series of pulses, as shown in Figures 4 and 5. When the shaft is moving in a clockwise direction, there will be pulses at the Up output, while a counter-clockwise rotation results in pulses at the Down output. This assumes that the encoder is a standard one, where the ‘A’ signal leads the ‘B’ for a clockwise rotation. Note that the Up output pulses are always a result of a change in A followed by a change in B, while the Down output pulses result from a change in B followed by a change in A. Figure 4 also shows what happens when the rotary encoder shaft is ‘wiggled’, generating pulses on only the A or only the B input - the logic detects this and ignores them. In order for an output to be generated, the ELM402 must see a change on one of the rotary encoder inputs followed by a change on the other input. The Up or Down output pulse width is set by the level at pin 4. If pin 4 is at a high level, the pulse width will be approximately 2.0 msec in duration, while a low level on pin 4 will result in 200 µsec wide pulses. Pin 5 can be used to invert the output, as shown in Figure 5. Note that the ELM402 uses what is known as 2x decoding of the signals. This means that for each motion of the shaft between the detents, when the ‘A’ and ‘B’ outputs go through one complete cycle, there will be two output signals. The other type of decoder that is very common is the 4x decoder, as used by the ELM403. We do not currently offer a product for 1x decoding - if you require that, you will need to use the ELM401 and decode the signal with your own logic. A ‘wiggle’ or vibration causes B to change, but A does not, so the pulse is ignored A Input B Input debounce delay Up Down Figure 4. Output signals (pin 5 = 0V) ELM402DSA Elm Electronics – Circuits for the Hobbyist www.elmelectronics.com 7 of 9 ELM402 Output Waveforms (continued) A Input B Input debounce delay Up Down Figure 5. Output signals (pin 5 = VDD) Design Considerations There are a few details to consider when using the ELM402 to interface to a rotary encoder. The first is the fact that the signals available from the encoder are usually only dry contacts closing and opening. You will need to provide pullup resistors for these signals in order to use them in a circuit. The size of the pullup resistor is chosen based on the encoder specifications. The main concern is the maximum current carrying capacity, which sets a lower limit for the pullup resistance. An upper limit for the resistance is set by the minimum current required for contact wetting. If you do not provide enough current through mechanical contacts when they are closed, they will tend to go open with time. A maximum current specification is usually in the range of 1 to 10 mA, while the minimum wetting current would be in the range of 1 mA. This means that with a 5V supply, a pullup resistor of 5 to 10 KΩ is typically required. The second concern is the use of capacitors on the ‘A’ and ‘B’ signal lines. Many encoder circuits show these as a way to provide some pre-filtering of the signal. That is fine, as long as you realize that the ELM402 inputs are CMOS and do not have Schmitt trigger waveshaping. This means that you should keep the rate of change of the input signal as high as possible to avoid problems (we usually try to maintain at least 1V/µsec). Typically, with a 5V supply, a 10 KΩ pullup, and TTL thresholds, this means capacitor values of no more than about 330 pF, while with a 2.0V supply, the limit would be about 100 pF. One other issue to consider is that during the initial circuit startup, there is a period (of about 20 msec) when the ELM402 is being held in a reset state, and ELM402DSA the outputs are in a tristate condition. During this time, the outputs will sit at the level they were at before power up (0V) due to stray capacitance having discharged through the protection diodes. If you are using the output invert feature, the outputs will not rise to their quiescent high state until after this reset period is over. If it is essential that they go high as quickly as possible, you may want to install a pullup resistor (of about 10 KΩ) on each output to ensure that the voltage goes quickly to VDD. After the initial 20 msec period, the ELM402 sets all pins to their quiescent levels, but does not change any outputs for an additional 50 msec. This ensures that the external circuits have had adequate time to initialize, before being presented with signals to process. Elm Electronics – Circuits for the Hobbyist www.elmelectronics.com 8 of 9 ELM402 Example Applications Figure 6 below shows how the ELM402 might be used with a microprocessor. Pullup resistors of 10 KΩ are used with the rotary encoder to provide voltages for the A and B inputs. Power for the ELM402 has been obtained from the microprocessor circuit, but a small capacitor has been added to ensure that the supply is filtered. The output is not inverted (pin 5 is at 0V), so pins 6 and 7 are normally at 0V, providing positive-going pulses only when the rotary encoder is turned. To allow the microprocessor plenty of time to poll the signals, an output period of 2.0 msec has been chosen, by setting pin 4 to VDD. The positive supply has been shown as VDD, as the ELM402 will operate with any voltage from 2.0 to 5.5 volts. The other schematic (Figure 7) shows how the ELM402 might be used with a digital potentiometer chip, in this case the Maxim MAX5128. Note that the ELM402 does not support the write function for chips such as this, so every time that the circuit is powered up, the wiper returns to the midpoint position. Since the Maxim data sheet specifies a rather large bypass capacitor (0.1 µF), we have shown it here, but you may not need a capacitor that big if there are no writes being performed. The ELM402 has been set for 0.2 msec positive going output pulses which are considerably more than the 80 nsec minimum time. As the MAX5128 requires positive-going pulses, we have not put any pullups on the ELM402 outputs, but this may be a consideration with other potentiometers. That’s about all there is to using the ELM402. Connect pullup resistors to your rotary encoder, connect the encoder signals to the ELM402, then connect the ELM402 to the controlled circuit. Use a common supply for all the devices, and add a bypass capacitor across the supply line. The controlled devices can be digital pots, microprocessors, or almost any circuit that will accept CMOS signals. Enjoy! VDD VDD your microprocessor VDD 0.01µF 10 KΩ 10 KΩ A port pins 1 8 2 7 3 6 4 5 VDD B rotary encoder C Figure 6. Connecting the ELM402 to a microprocessor +5V 10 KΩ A B rotary encoder +5V 1 8 2 7 3 6 4 5 8 7 6 5 MAX5128 H +5V C 0.1µF 1 2 W 3 L 4 Figure 7. Connecting the ELM402 to a MAX5128 ELM402DSA Elm Electronics – Circuits for the Hobbyist www.elmelectronics.com 9 of 9