You are on page 1of 5

designideas

EditEd By Martin rowE and Fran GranvillE

readerS SOLVe deSIGN PrOBLeMS

Simple battery-status indicator uses two LEDs


Abhijeet Deshpande, Peoples Education Society Institute of Technology, Bangalore, India

DIs Inside
46 Hardware watchdog timer accepts range of frequencies 48 Get four colors from 2 bits 50 Implement trapezoidal velocity profiles in software
to see all of EDNs design ideas, visit www.edn.com/ designideas.

Properly maintained rechargeable batteries can provide good service and long life. Maintenance involves reg-

ular monitoring of battery voltage. The circuit in Figure 1 works in most rechargeable batteries. It comprises a reference LED, LEDREF, which operates at a constant current of 1 mA and provides reference light of constant DZ intensity regardless of battery voltage. It accomplishes this task by con+ necting resistor R1 in series with the diode. Therefore, even if the battery R2 R1 VBATT voltage changes from a charged state 10k 10k to a discharged state, the change in current is only 10%. Thus, the intensity of LEDREF remains constant for a LEDREF LEDVAR battery state from a fully charged state to a fully discharged state. The light output of the variable Figure 1 This circuit works in most LED changes with respect to changes rechargeable batteries. It comprises in battery voltage. The side-by-sidea reference LED, LEDREF, which operates mounted LEDs let you easily comat a constant current of 1 mA and provides pare light intensities and, thus, batreference light of constant intensity regardtery status. Using diffused LEDs as less of battery voltage. crystal-clear LEDs can damage your eyes. Instead, mount the LEDs with sufficient optical isolation so that the S1 light from one LED does not affect DZ2 DZ1 9.1V 9.1V the intensity of the other LEDs. The variable LED operates from 10 D3 D1 mA to less than 1 mA as the battery + voltage changes from fully charged to R1 R2 D2 10k 10k fully discharged. Zener diode DZ in VBATT series with resistor R2 causes the curR4 R3 100 100 rent to change with battery voltage. The sum of the zener voltage and LEDREFR LEDREFG the drop across the LED should be LEDVARG LEDVARR IG IR slightly less than the lowest battery voltage. This voltage appears across R2. As the battery voltage varies, it Figure 2 This circuit can withstand 13V produces a large variation of current because it has a 10-mA margin. If the LEDs in R2. If the voltage is approximateare bright, quickly release pushbutton ly 1V, then 10 mA will flow through switch S1. LEDVAR, which is much brighter than

LEDREF. If the voltage is less than 0.1V, then the light intensity of LEDVAR will be less than LEDREF, indicating that the battery has discharged. Immediately after the battery has charged, the battery voltage is more than 13V. The circuit can withstand this voltage because it has a 10-mA margin. If the LEDs are bright, quickly release pushbutton switch S1 to avoid damage to the LEDs (Figure 2). The figure uses a 12V lead-acid battery indicator as an example, but you

TABLE 1 LED INTENSITY


Light output of LEDVARG Much brighter than LEDREFG Equally as bright as LEDREFG Off Light output of LEDVARR Much brighter than LEDREFR Much brighter than LEDREFR Brighter than LEDREFR Equally as bright as LEDREFR Off Battery status (%) 70 to 100

60

50 to 30

Off

20

Off

0 to 10

AUGUST 12, 2010 | EDN 45

designideas
1 shows how LED intensity indicates batLEDREF tery charge. The following equation calculates LEDVAR the variable intensity for the green LED: VBATT=IG100+VD1+ Figure 3 Both variable-intensity LEDs are brighter than VD2+VLEDG+VDZ1. For the reference LEDs, indicating that the battery is 100% a green-LED current charged. of 1 mA, VBATT=103 100+0.6+0.6+1.85+ can extend the design to accommodate 9.1=12.25V. The selected LEDs have a other types of chargeable batteries. You drop of 1.85V at 1 mA. can also use it for voltage monitoring. It If the LED has different characterisuses two green LEDs to indicate wheth- tics, then you must recalculate the reer the battery has charged above 60%. sistor values. At this voltage, the LEDs A set of red LEDs indicates whether have the same intensity, and the batthe battery charge drops below 20%. tery is 60% charged. See Reference 1 LED REFG and LED REFR feed through for lead-acid-battery voltages. 10-k resistors R 1 and R 2. For the The following equation calculates variable-intensity LEDs, a zener diode the variable intensity for the red LED: works in series with 100 resistors R3 V BATT=I R100+V D3+V LEDR+V ZD2. For and R4. Diodes D1, D2, and D3 provide a green-LED current of 1 mA, VBATT= the required clamping voltages. Table 103100+0.6+1.85+9.1=11.65V.

YOu caN uSe the deSIGN tO accOMMOdate Other tYPeS Of charGeaBLe BatterIeS. YOu caN aLSO uSe It fOr VOLtaGe MONItOrING.
At this voltage, both red LEDs have equal intensities, and the battery is 20% charged. LEDVARG is off. Figure 3 shows that both variable-intensity LEDs are brighter than the reference LEDs, indicating that the battery is 100% charged.EDN RefeRence
1 Lead Acid Battery Charging, Solar Navigator, 2005, www.solarnavigator. net/battery_charging.htm.

Hardware watchdog timer accepts range of frequencies


Robert Most, Ferris State University, Big Rapids, MI

Microcontrollers usually require a watchdog timer to bring high

INITIALIZE

currents or high voltages into a safe condition. Many microcontrollers have built-in watchdog timers for this purpose. You may, however, prefer that an external circuit be the judge. An external watchdog circuit checks the integrity of the microcontrollers code, bringing the outputs to a safe state when it
5V C1 D1 22 F 1N4001 R3 R1 R2 1k 220k 4.7k C2 47 F

judges that the microcontrollers firmware has gone awry. Conditions such as errant code or failed hardware can cause these issues. You have many options for designing an interface between your external timer and the microcontroller. For example, you can use a port pin, which yields a flexible and adaptable way to couple with almost any microcontroller. In applications that require energizing an output or series of outputs, you need an enable signal. You can use this

TOGGLE WATCHDOG

MAIN CODE

10-Hz TO 100-kHz, 0 TO 5V SQUARE WAVE

Q1 2N3906 R5 1k R4 10k

D2

TO ENERGIZING CIRCUITS

Q2 2N3904

Figure 1 A microcontroller must constantly generate a pulse to keep a watchdog timer from timing out.

Figure 2 Capacitor C2 remains charged enough to keep the circuit energized as long as a pulse stream of at least 10 Hz is present. If the pulse drops, the circuit removes power through the relay.

46 EDN | AUGUST 12, 2010

designideas
enable signal to energize a relay providing power to an output device. Turning the enable signal into a watchdog signal is therefore a wash in terms of portpin usage. The implementation of this watchdog circuit requires the output port pin to toggle, rather than stay at a constant state. Most microcontroller code has a main loop that is always either performing a task or calling larger functions and interacting with interrupt-service routines. If an errant task, unforeseen bug, or unintentional vector executes, the main loop either gracefully reinitializes or becomes stuck indefinitely. Either situation breaks the execution of the main loop. When that situation occurs, the timer needs to remove power from your circuits. You can implement the watchdog timer by toggling a port output whenever the main loop runs, provided that the main loop executes 10 to 100,000 times/sec. Figure 1 demonstrates this concept. You can implement this watchdog philosophy in several ways. You must allow for variability in the rate of the toggle signal because extraneous interrupts and other nondeterministic events may cause variability in the main loops execution loop time. If deems necessary, the recovery operation can disable the watchdog timers output. You can download Listing 1, a document containing sample code, from the Web version of this Design Idea at www. edn/100812dia. The circuit in Figure 2 uses two bipolar transistors. The second transistor is simply a relay driver. The circuit works by removing the dc component from the incoming toggling square wave, rectifying and creating an average dc value. This wave feeds transistor Q1, biased such that a prolonged absence of pulses turns it off, thus turning off Q2 and the relay. Changing the value of C2 also changes how quickly the watchdog timer reacts to an absence of pulses. The circuit accepts toggling frequencies of 10 Hz to 100 kHz. Changing the value of capacitor C2 changes the range of compliance frequencies that the main loop generates. The circuit also functions with a 3.3V processor, but either the relay must have its own 5V supply or you must use a lower-voltage relay.EDN

the IMPLeMeNtatION Of thIS watchdOG cIrcuIt requIreS the OutPut POrt PIN tO tOGGLe, rather thaN StaY at a cONStaNt State.
the watchdog circuit is not sufficiently forgiving, it may lead to false triggers, defeating its purpose. The recovery time of the watchdog timer is the maximum time between toggling events in duration. This scenario can happen when the system is in a recovery, or limphome, mode. This circuit can accommodate the recovery duration, but, if it

Get four colors from 2 bits


Marin tofka, Slovak University of Technology, Bratislava, Slovakia

Three-color LEDs contain red, green, and blue LEDs in one package. Using two digital control signals, you can drive these LEDs to produce four colors. The circuit in Figure 1 uses an Analog Devices (www.analog. com) ADG854 dual analog 1-to-2 demultiplexer that lets you select the current through each LED. The circuit uses a distinct current, I or 2I, to drive each LED. The demultiplexers determine the routes of the currents through transistors Q1, Q2, and Q3 in transistor array IC2 to the LEDs. These transistors act as both current sources and summing elements. The following equation yields the value of the current: I=(VREFVBE)/RE, where VBE is the base-emitter voltage of bipolar transistors Q1, Q2, and Q3. The base-emitter-voltage value varies slightly depending on the total collector current, but you can neglect this variation.
48 EDN | AUGUST 12, 2010

Refer to the data sheet of your transistor array for this information. One unit of current constantly flows through the green LED. Demultiplexer D1 routes another unit of current to either the red LED or the blue LED, and D2 routes the third unit of current to either the green LED (2I total) or the red LED. Table 1 shows the states and colors that this circuit produces. The sum of ter voltage with temperature, which is currents flowing through all LEDs is 3I approximately 1.42 mV/C, causes an at one time for all four combinations increase in current through the LEDs by of control variables. Thus, the gener- approximately 0.33%/C. It has a benated light is approximate- TABLE 1 DISTrIbuTIoN of currENT aND coLorS ly of the same IN1 IN2 IR IG IB Color intensity re0 0 I I I White gardless of 0 1 Off 2I I Aqua color. The decreas1 0 2I I Off Red-orange ing value of 1 1 I 2I Off Yellow the base-emit-

the deMuLtIPLexerS deterMINe the rOuteS Of the curreNtS thrOuGh traNSIStOrS q1, q2, aNd q3 IN traNSIStOr arraY Ic2 tO the LedS.

designideas
eficial effect because it compensates for the decreasing radiance of the LEDs as temperature increases. Drops in radiance are approximately 0.27%/C for the blue LED and about 0.35%/C for the green LED. The radiance of these two LEDs, which are both indium-gallium-nitride types, thus remains almost constant over ambient temperature. The red LED is an aluminium-indium-gallium-phosphorus type, having a radiance drop of approximately 0.77%/C, and the current source roughly halves this drop. The R0 resistors force the logic inputs to logic zero at manual control by connecting or not connecting the IN1 and IN2 control leads to VDD, the power-supply voltage. The maximum current flowing through the LEDs, about 26 mA, is far below the nominal current of 350 mA that Avago Technologies (www.avagotech.com) rates for the ASMT-MT00 power RGB (red/green/ blue) LED that this circuit uses. The radiance is sufficient, yet the junction temperature of the LEDs is low. Junction-to-pin thermal resistance for the green LED is 20C/W. IC1 dissipates approximately 0.1W. Therefore, you can estimate the junction temperature to be higher than the ambient temperature by less than 2C (Reference 1). Consequently, you increase the LEDs expected lifetime well beyond thousands of hours.EDN RefeRence
1 Oon, Siang Ling, The Latest LED Technology Improvement in Thermal Characteristics and Reliability: Avagos Moonstone 3-in-1 RGB High Power LED, White Paper AV02-1752EN, Avago Technologies, Jan 20, 2009, www. avagotech.com/docs/AV02-1752EN.

5V

IR

IG BLUE

IB IC1 ASMTMT00

1.8k

RED

GREEN

VREF 1.25V IC2

Q1

Q2

Q3

VDD IC4 ADR1581 IC3 ADG854 AT INPUT LOGIC 1 GND

S1A

S1B

S2A

S2B

D1 I

IN1

D2 I

IN2 I R0 470k RE 33

100 nF

RE 33

R0 470k

RE 33

CONTROL IN1 IN2

Figure 1 A three-color LED IC emits mixtures of two or three spectrally pure colors. The human eye perceives the mixtures as special colors.

Implement trapezoidal velocity profiles in software


Adil Ansari, General Electric, Energy Division, Atlanta, GA

Trapezoidal velocity profiles provide smooth motion for starting and stopping motor-control systems.

Figure 1 shows a velocity-profile section to be implemented in software that you can use to provide digital or analog

control to a motor. In the figure, represents the desired motor velocity (trapezoidal velocity profile) and MAX represents the maximum motor velocity. You predetermine the velocity profile based on the load acceleration and deceleration requirements. A trapezoidal velocity profile has three regions: accel-

50 EDN | AUGUST 12, 2010

eration (Interval 1), constant velocity (Interval 2), and deceleration (Interval 3). Equation 1 shows the calculation of the desired position, D, or the distance the motor needs to travel, as the area under the curve of Figure 1, which is an integral of the velocity.
INTERVAL 1 INTERVAL 2

MAX t D = dt+ T1 (T2T1)

T2

T3 T2

MAX dt +

traPezOIdaL VeLOcItY PrOfILeS PrOVIde SMOOth MOtION fOr StartING aNd StOPPING MOtOrcONtrOL SYSteMS.

INTERVAL 1:

i =

MAX 2(T2T1)
(5)

t2 | (t = iT, i = 0..(T2T1)).
INTERVAL 2:

i = MAX
(6)

(tT2) | (t = iT, i = 0..(T3T2)).

In Equation 1, each integral term represents the areas under the curve for regions 1, 2, and 3, respectively. (1) To implement the velocity profile in a position-control loop, the DESIRED VELOCITY PROFILE software calculates the posiMAX tion input at 1 every sampling S period, T, by a point-by-point numerical inT1 T2 T3 T4 tegration of (Listing 1). You Figure 1 You can implement this velocity-profile section in software that you can use to provide digital or analog motor control. can download the code for a Matlab simulation of this algorithm from the onLISTING 1 PSEuDo CoDE line version of this Design Idea at // Interval I www.edn.com/100812dib. // T is sampling interval Equations 2, 3, and 4 give the value of for intervals 1, 2, and 3, Tint1 = T2 T1 // Interval I respectively: For t = 0 .. Tint1

INTERVAL 3
T4

MAX t dt, T3 (T4T3)

For Interval 3, you calculate the area under the curve (shaded region in Figure 2) as t goes from T3 to T4 by subMAX

T3

T4

Figure 2 You use subtraction to calculate the area under the curve (shaded region) as t goes from T3 to T4.

tracting the area of the triangle for the interval [t .. T4] from the area of the entire triangle for the interval [T3 .. T4]:
INTERVAL 3:

i =

i =A.t2

INTERVAL 1:

t=t+T

t = MAX t (T2T1)
(2)

MAX (T4T3t)2 |(t = iT, i = 2(T4T3) 0.t.(T4T3)) .

(T4T3) MAX 2

} // Interval II Tint2 = T3 T2 // Interval II For t = 0 .. Tint2 { i = i +B.t t=t+T } // Interval III Tint3 = T4 T3 // Interval III For t = 0 .. Tint3 { i = i+ D C.(Tint3 t)2 t=t+T }

FOR t = T1 TO T2.

(7)

INTERVAL 2:

= MAX
(3)

FOR t = T2 TO T3.

To simplify the implementation, you can define constants A, B, C, and D (D equals the area under the curve of Interval 3) such that MAX ; = MAX; C = 2(T2T1) MAX T4T3 ;D = MAX. 2(T4T3) 2 A= i = t2|(t = iT, i = 0..(T2T1)) + B t|(t = iT, i = 0..(T3T2)+(D C (T4 T3 t)2)|(t = iT, i = 0..(T4T3)).
(9)

INTERVAL 3:

MAX t (T4T3)

FOR t = T3 TO T4. (4)

(8)

Next, calculate the position input to the control loop i every sampling period for each of the inter vals by numerically integrating in equations 2, 3, and 4:

You can then express i as Equation 9 (above) shows.EDN


AUGUST 12, 2010 | EDN 51

You might also like