Design Idea
Three microcontroller ports drive 12 LEDs
Engine tachometer uses few components and I/O lines.
Nedjeljko Lekic and Zoran Mijanovic, University of Montenegro, Department of Electrical Engineering, Podgorica, Montenegro; Edited by Brad Thompson and Fran Granville -- EDN, 12/15/2006
Based on a previously published Design Idea (Reference 1), the circuit in Figure 1 uses only three I/O lines to drive 12 LEDs. In this application, the circuit serves as a tachometer for a motor-vehicle engine and displays relative engine speed on an array of LEDs arranged in a line or a circular arc. Three pairs of inverse-parallel-connected LEDs (D2 and D3, D4 and D5, and D6 and D7) receive drive current from IC1's ports through current-limiting resistors R5, R6, and R7. Two groups of three LEDs, D8, D9, and D10 and D11, D12, and D13) connect among IC1's ports and two voltage dividers that supply reference voltages VREF1 and VREF2. Varying the values of resistors R5, R6, and R7 adjusts the brightness of the middle six LEDs, and R1, R2, and R4 control the brightness of the outer six LEDs. In general, this circuit can use N of a host microprocessor's I/O lines to drive as many as N(N–1)+2N LEDs, or 2N more LEDs than the circuit in the original Design Idea could drive.
The circuit uses Microchip's PIC10F200 microcontroller, IC1, a small, inexpensive, six-pin device that provides only three I/O pins and one input-only pin. The I/O pins—GP0, GP1, and GP2—drive a 12-LED bar graph comprising four yellow LEDs, four green LEDs, and four red LEDs driven in multiplexed mode (Figure 2).
The microprocessor's input-only pin, GP3, serves as the input for pulses coupled from the ignition coil's primary terminal. Resistor R3 and diode D1 provide input-signal conditioning, and a software-debouncing routine removes ringing effects from the pulses. Given R3's high value of 390 Ωk, the circuit tolerates high-voltage input spikes and prevents latch-up of the PIC10F200. Port GP3, which serves as the processor's programming port, differs from the processor's other ports because it incorporates an internal protection diode. The 20-mA diode prevents GP3 from negative-going transient voltages. The circuit operates reliably, but you can add an external protection diode for enhanced protection against transient-induced latch-up. Connect the diode's anode to ground and its cathode to pin GP3 of IC1.
You can configure the bar graph to indicate engine speed by the number of LEDs turned on (bar mode) or by illuminating only one or two LEDs (dot mode). The color scheme in Figure 2 uses yellow LEDs to indicate too-low speed, green LEDs for nominal speed, and red LEDs for excessive speed. Figure 3 shows the indicator software's flow chart. The processor's internal clock drives Timer0 to overflow every 512 µsec, which represents one time slot—that is, a multiplexing phase. Of eight time slots, one drives the three upper LEDs, and a second drives the three lower LEDs. For software simplicity, the last six time slots drive the middle LEDs one by one. At the start of the main loop, the microprocessor counts clock pulses and waits for Timer0 to overflow. After overflow occurs, the output ports drive the LEDs according to their assigned time slots. After eight time slots elapse, the processor sets the ports to the same state. After 200 time slots, the processor counts incoming tachometer pulses and sets the LED pattern according to the incoming pulse count—that is, according to input frequency.
The tachometer indicates rotary speed as high as 120 cycles/sec. The accompanying software listings include files in C language (led12.c.pdf) and in assembly language (led12.asm.pdf). The source zip file contains a complete MPLab project. Figure 4 shows the waveforms, which a digital oscilloscope captured at ports GP0, GP1, and GP2.
| Reference |
|
















