Design: Ideas
Design: Ideas
Design: Ideas
ideas
a two-byte binary integer, which converts to decimal for display. A third byte in the protocol indicates any decimal points or colons. This data format allows the easiest interface from binary measurement or calculation. A second protocol accepts four bytes that directly control the segments and decimal points, allowing the display of a variety of characters and symbols possible on a seven-segment display. You can download the source code and hex object file for the ATtiny12 from the Web version of this Design Idea at www.edn.com. The code provides a two-wire I2C interface for a four-digit Lumex (www.lumex.com) LCD-S401C52TR display.
Seven-segment LCD uses two-wire interface ..........................................89 Open-collector output provides fail-safe operation..........................................90 Low-battery indicator uses fleapower ......90 Indicator has electronic lens ....................92 Thermal switches provide circuit disconnect............................................98
of 16 msec followed by shifting the same data complemented, as well as the complement of the LCD common terminal with another 16-msec delay, provides the second half of the required ac waveform. Because field-effect LCDs takes tens of milliseconds to respond, the rapid datashifting and display-common changing does not affect the displayed image. You can use the two 16-msec delays per cycle for application processing. Directly driving the segments allows the display of not only the numbers zero to nine, but also any combination of segments and decimal points. You can use the eight-pin ATtiny12 with a built-in, 1MHz clock oscillator to produce the described two-wire signal and to provide a two-wire I2C application interface. The dedicated use of the microcontroller for display control and its I2C interface frees the application hardware and software from timing and resource restrictions. The implemented I2C interface operates at 0 to 40 kbps and is bit-synchronous. One data protocol allows for the input of
VCC IC1 ATTINY12 8 VCC 7 PB2 6 PB1 5 PB0 1 RST 2 PB3 3 PB4 4 GND R1 10k BACKLIGHT CONTROL SCK
DSD
VCC 9 CLR
QA QB QC QD QE QF QG QH 3 4 5 6 10 11 12 13
QA QB QC QD QE QF QG QH 3 4 5 6 10 11 12 13
QA QB QC QD QE QF QG QH 3 4 5 6 10 11 12 13
Figure 1
37 36 5 6 7 34 35 8 32 31 9 10 11 29 30 12 2G 2F 2E 2D 2C 2B 2A 2DP 27 26 13 14 15 24 25 16 3G 3F 3E 3D 3C 3B 3A 3DP 23 22 17 18 19 20 21 28 4G 4F 4E 4D 4C 4B 4A COL CM2 CM1 40 1
A minuscule 8-bit microcontroller lets you use a two-wire interface to drive a seven-segment LCD. www.edn.com
1G 1F 1E 1D 1C 1B 1A 1DP
IC6 LCD40
design
ideas
the circuit draws 1.4-A current. At the indication-threshold voltage, 6.5V, the circuit draws 1 A. Assume that the average operating current is 1.2 A. The circuit uses 42 mAhr in a four-year period, less than 10% of the batterys rated energy. A red LED, D2, flashes periodically when the battery voltage drops below 6.5V. IC1, an LTC1540, is a nanopower comparator with a built-in 1.18V reference. A battery-voltage divider comprising R1and R2, and a positive-feedback
network, R3, feed the positive input of the comparator. The positive feedback generates hysteresis in the comparator. The negative input of the comparator receives bias from the reference voltage, through the R4-C1 delay circuit. During normal operation, the voltage at the positive input is approximately 1.62V when the battery is at 9V. The output of the comparator is at a high state, such that no current flows through D1 and D2. When the battery voltage drops
www.edn.com
design
ideas
R5
2.2k below 6.5V, the voltage at the positive input drops below the reference voltage at D1 R6 1N4148 20k the negative input. The output of IC1 switches from high to low, thereby lightR3 20M ing the LED, D2. The switching R1 D2 Figure 1 changes the voltage at the positive 20M LED 7 input to 0.58V and causes C1 to discharge V+ through D1 and R6. Because the value of 3 + R6 is much smaller than that of R4, the IC1 8 LTC1540 voltage at the negative input drops 4 _ 9V quickly, according to the time constant R4 5 HYST that C1 and R6 set. Once the voltage at the 10M 6 REF negative input falls below 0.58V, the R2 comparator switches back to a high state. 2.2M GND C1 This change sets the voltage at the posi2 1 0.33 F tive input to 1.18V, turns off the LED, and reverse-biases D1, so the reference charges C1 through R4. When the voltage at the negative input again reaches This fleapower low-battery indicator draws just 1.2-A operating current. 1.18V, the cycle repeats. The LEDs ontime is a function of C1 and R6, and the times are 20 msec and 10 sec, respective- 1.8V)/2.2 k2.1 mA. The average LED off-time is a function of C1 and R4. With ly, at 6.5V threshold voltage. At this point, current is (20 msec2.1 mA)/10 sec4.2 the values in Figure 1, the on- and off- the LEDs on-state current is (6.5V A.
www.edn.com
design
ideas
A
ter with a measured-voltage range of 0 to 50 40 60 30 70 5V. You need to magnify the portion of 20 80 100 2 VOLTS 3 10 90 the input from 2 to 3V, from 20 to 70%, 1 4 a 100 90 0 leaving 10% at the beginning and 20% at A 0 5 80 50 the end of the scale (Figure 2, character40 60 30 70 a 70 20 80 istic c). Table 1 shows the steps of the calc VOLTS 10 90 b 1 60 b 2 culations, which you execute as follows: 0 3 100 CURRENT 45 1. Choose a number (N) and the val50 0 (A) A . ues of the measured input voltages, VIN 50 40 d 40 60 30 70 These parameters depend on the desired 20 80 30 VOLTS 10 90 3 accuracy of the meter scale. As an examc 0 100 20 4 2 1 5 ple, assume voltages with increments of A 0 10 50 40 60 0.5V for the low slope (Figure 2) and 30 70 20 80 0 0.1V for the high slope (Table 1, column VOLTS 10 90 0 1 2 3 4 5 d 0 100 2). Therefore, N19. VIN 34 2 5 01 2. Calculate the 8-bit ADCs Figure 2 digital output, NIN, for the seBy selecting slopes and breakpoints, you can expand the bottom (b), the middle (c), or the top (d) lected input voltages (column 3): NIN portions of a linear meters response. (256/5)VIN51.2VIN. 3. Transform NIN from decimal to microcontrollers time intervals is a func- ponents R20 k and C10 pF should hexadecimal format (column 4). The er- tion of the accuracy of its oscillator fre- yield a frequency of approximately 4.5 rors arising from the 8-bit quantization quency, which for the MC68HRC908K1 MHz. The measured frequency is 5.75 are insignificant for an analog indicator. depends on the external RC circuit. The MHz. With the timer/counter prescaler 4. Choose the PWM period, T. This data sheet for the IC recommends a tol- set at 64, the timer-clock period is 44.5 value depends on the rapidity of the in- erance of 1% or less for these components sec. Hence, you can calculate the numput-voltage change and should be rela- to obtain a clock tolerance of 10% or bet- ber of timer cycles for any time interval as tively short to prevent needle chatter. As- ter. But it is difficult to find a 10-pF1% Nt(t in milliseconds)/(44.5103) sume T10 msec for easy Table 1 capacitor, so this design uses a less ex- 22.5(t in milliseconds). Thus, for T10 calculations. pensive 5% capacitor and measures the msec, N10225 or NHEX$E1. 6. Determine the duty cycle () of the 5. Calculate the number of timer cycles oscillation frequency. According to the for the PWM period. The accuracy of any microcontroller manual, the timing com- PWM signal for each chosen input voltage, VIN, as well as the scale-expansion pattern (column 5); (IV/IMAX)100%. RESET You could either read the current value directly from the diagram in Figure 2 (charINITIALIZATION acteristic c) or calculate it for three linear parts of the scale with the following equaMAIN tion: IVITiSi(VINVTi), where IV is the current for the given input voltage VIN, ITi CLEAR X-REGISTER is the current for the threshold voltage VTi CONVERT VIN TO (i{1,2,3}), and Si is the slope of each linHEX FORMAT BY ADC ear portion of the scale in Figure 2 (characteristic c). The expressions for the three START piecewise-linear segments are as follows: COMPARE VIN WITH VX 10 VT1 = 0; IT1 = 0; S1 = = 5 A / V. FROM THE C MEMORY 2
DOES IT MATCH? ARE ALL VX CHECKED? COMPARE VIN WITH THE NEXT VX YES
YES
YES VINV0? SET PWX FROM MEMORY GENERATE PWM SIGNAL STOP GENERATING PWM
Figure 3
This flow chart shows the steps in the scale-expansion process.
VT 2 = 2 V ; IT 2 = 10 A; 80 10 S2 = = 70 A / V. 32 VT 3 = 3V ; IT 3 = 80 A; 100 80 S3 = = 10 A / V. 53 7. Determine the pulse width of the PWM signal: PWT (column 6). 8. Calculate the number of timer cycles, NOUT, for this pulse width by using
www.edn.com
design
ideas
TABLE 1EXAMPLE OF MIDSCALE EXPANSION
1 x 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 2 VIN (V) 0.04 0.5 1 1.5 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3 3.5 4 4.5 5 3 NIN 2 25.6 51.2 76.8 102.4 107.5 112.6 117.8 122.9 128 133.1 138.2 143.3 148.5 153.6 179.2 204.8 230.4 250.9 4 NIN (hexadecimal) $2 $1A $33 $4D $66 $6C $71 $76 $7B $80 $85 $8A $8F $94 $9A $B3 $CD $E6 $FB 5 (%) 0 2.5 5 7.5 10 17 24 31 38 45 52 59 66 73 80 85 90 95 99 6 Pulse width (msec) 0 0.25 0.5 0.75 1 1.7 2.4 3.1 3.8 4.5 5.2 5.9 6.6 7.3 8 8.5 9 9.5 9.9 7 NOUT 0 5.6 11.2 16.87 22.5 38.25 54 69.75 85.5 101.25 117 132.75 148.5 164.25 180 191.25 202.5 213.75 222.75 8 NOUT (hexadecimal) $0 $6 $0b $11 $16 $26 $36 $46 $55 $65 $75 $85 $95 $A4 $B4 $BF $CB $D6 $DF
the equation for Nt and transform the number into hexadecimal format (columns 7 and 8). 9. Enter NIN and NOUT Listing 1. You can use any microcontroller with a PWM function and built-in ADC. The one in Figure 1 has a 12-channel, 8-bit ADC and the capability to generate a PWM signal. This microcontroller has 15 I/O pins, which are necessary for executing other functions. If your application needs only to effect the meter-scale expansion, then the eight-pin 68HC908QT2 is probably a better choice. This microcontroller has a built-in oscillator and costs less than $1.You can download Listing 1 from the Web version of this Design Idea at www.edn.com. Reference 1. Raynus, Abel,Expanded-scale indicator revisited, EDN, Aug 8, 2002, pg 112.T
www.edn.com
design
ideas
www.edn.com