You are on page 1of 5

designideas

Edited By Martin Rowe


and Fran Granville

readerS SOLVE DESIGN PROBLEMS

Excel spreadsheet measures


analog voltages D Is Inside
32 Schottky diodes improve
Yury Magda, Cherkassy, Ukraine comparator’s transient response


You can use the parallel port, the data register. The status register 34 Algorithm keeps data safe
which many computers still has the address 0x379, and the unused
have, with some VBA (Visual Basic control register has the 0x37A address. 36 P-channel power-MOSFET
for Applications) code and Microsoft These settings are the defaults for most driver uses unity-gain op amp
(www.microsoft.com) Excel 2007 to motherboards. This design uses ad- ETo see all of EDN’s Design
measure, record, and analyze analog dresses 0x378 and 0x379. The parallel Ideas, visit www.edn.com/design
signals. The hardware comprises a 12- port sometimes uses hardware address- ideas.
bit Microchip (www.microchip.com) es in the range of 0x278 to 0x27A. The
SAR (successive-approximation-regis- hardware addresses may also vary when
ter) ADC (Figure 1). The binary code you apply a PCI (Peripheral Compo-
that represents this signal passes to the nent Interconnect) expansion board \system32 directory so that the VBA
parallel port through an SPI (serial- with a built-in parallel interface. You application can find it. You can down-
peripheral-interface)-compatible port, should check the hardware addresses of load Listing 1, the VBA code, from
which includes three signal lines. the selected parallel interface and set the online version of this Design Idea
The analog input signal on Pin 2 appropriate values in the source code. at www.edn.com/100121dia.
of the MCP3201 ranges from 0 to 5V. The program uses the inpout32.dll To write a VBA control program,
The ADC’s reference voltage is 5V, library, which is free and accessible for you should create a new Excel work-
which provides an LSB (least-signifi- downloading at www.logix4u.net. The book and open the Visual Basic edi-
cant bit) of 5/212, or 1.2207 mV. You inpout32.dll includes two useful func- tor where you enter the source code.
can substitute the MCP3201 ADC tions, Inp32 and Out32. The Inp32 After doing so, you must insert a new
with the Linear Technology (www. function reads a data byte from the user form (Figure 2). You need to drop
linear.com) LTC1286 chip, which is hardware register (port), and Out32 a button component from the toolbox
pin-compatible with MCP3201, but writes the byte into the hardware port. onto the user form. When the appli-
this replacement requires some chang- Before using the inpout32.dll, you cation is running, clicking the button
es in the source code. The circuit in- should copy the inpout32.dll into the causes the value of the analog volt-
cludes a 1- to 10-mF bypass age to appear in the cur-
capacitor that you should 5V rent cell of Column A of
place as close as possible to Spreadsheet 1.
the MCP3201’s power pin. You should declare
�C
You can improve perform­ MCP3201 1 LPT1 functions Out32 and
1 �F DB25 CONNECTOR
ance by placing a lowpass ADC I n p 3 2 from the in-
active filter between the 8 pout32.dll library with
signal source and the con- 1
VREF CS
5 BIT 7 OF 0x378 9 the Declare direc-
verter’s input (Pin 2). INPUT 2 6 BIT 3 OF 0x379 15 tive so that the applica-
IN� DOUT
The design uses the VOLTAGE 3 7 BIT 6 OF 0x378 8
tion can use them. The
PC’s default parallel in- IN� CLK Out32 (port, port-
terface, LPT1, which has 4 Val) holds the hardware
24
three hardware registers: address of the port to
data, status, and control. write data to. The value
Most PCs have only one of the byte goes in the
parallel port with the base Figure 1 An MCP3201 ADC digitizes the input voltage. portVal parameter.
address 0x378 assigned to The Inp32 function

january 21, 2010 | EDN 31


designideas

Figure 2 You can create a user form with a button to execute Figure 3 The VBA application collects data in an
the conversion. Excel spreadsheet.

Call Out32(dataPort, parallel port. The 12 bits of the result


takes the port parameter where the
&H80) are saved in the binData variable,
address of the port is held. When suc-
cessful, this function returns the byte Call Out32(dataPort, and the total variable holds the fi-
read from this port. &HC0) nal result. Figure 3 shows the main
The program realizes the timing di- Call Out32(dataPort, window of the running application.
agram of the conversion and outputs &H40) After you click the “get input volt-
data when the CommandButton1_ start the conversion. The for() age” button, the measurement result
Click event handler is called. The loop passes data bits beginning from appears in the next cell in Column A
statements the MSB (most-significant bit) to the of Spreadsheet 1.EDN

Schottky diodes improve CIN, approximately 1 pF, is the input ca-


pacitance of the comparator. IC2 has a
comparator’s transient response BBM interval of approximately 3 nsec,
and any Analog Devices (www.analog.
Marián Štofka, Slovak University of Technology, Bratislava, Slovakia com) ADCMP608 and ADCMP609
comparators’ signal-propagation delays


In a previous Design are 10 times that value. Hence,
Idea, a circuit switches IDEAL
VIN
they cannot change their state
CROSSING
precision dc reference voltages in 3 nsec. Analog Devices
to the noninverting input of a has 10-times-faster parts, the
high-speed IC comparator (Ref- EFFECTIVE RISE ADCMP601 and ADCMP602,
erence 1). The circuit uses a 2- OF VREFH in the same family. Unfortu-
to-1 multiplexer that functions tPDCOMP tPDCOMP�tRCOMP/2 nately, these devices can sense
in a BBM (break-before-make) these spikes (Reference 2). The
fashion. Multiplexers have a voltage excursion over the high-
parasitic capacitance, whose in- GLITCH
level reference voltage, VREFH,
jection of charge, QD1INJ, into VQ�VOUT can result in an abrupt short-
the D1 drain electrode of the term elevation of the output
multiplexer might
Equation for cause
DI4525 errorin the 12 − 3 folder) tOFFA
(placed voltage.
voltages at the comparator’s ref- tONB
�VD1� When the high reference volt-
erence input (Figure 1). The VREFH
age exceeds the voltage at the
following equation
Equation 1 defines the tBBM comparator’s inverting input,
VD1
approximate peak error voltage: its output goes high again, or
Q D1INJ+
VREFL generates a glitch. As the com-
∆VD1+  , parator crosses an ideal level,
C D1OFF + CIN the comparator’s output goes
Figure 1 Charge injection can produce a glitch in a
voltage comparator’s output, and these glitches can low with a delay. The positive
where CD1OFF is the capacitance cause logic hazards. error voltage starts to evolve
of the D1 terminal of IC2, and with an additional delay of the
edn091126di45251 DIANE
(PLACED IN THE 12-3 FOLDER)

32 EDN | january 21, 2010


2.7 TO 3.6V

IN

VDD
IN2

S2A
D2

S2B CD
100 nF
VIN IC2
VOUT 2.048V VCC
SHDN ADG772
FORCE
IC3 �
ADR390B VOUT VREFH S1A 1 pF Q
OUT
SENSE D1 VD1
9R
1.8k � IC1
GND VREFL
0.2% S1B CD 1 pF ADCMP601 LE/
R VEE HYS
200 2.2 nF 2.2 nF
0.2% GND IN1

NC

VREFL=0.2048V

D1

D2

NOTES: NC D3 NC
FOR IC2, WHEN IN1 OR IN2 IS LOW,
THE B CHANNEL IS CONNECTED.
WHEN IN1 OR IN2 IS HIGH, IC4
THE A CHANNEL IS CONNECTED. HSMS-282L

Figure 2 Schottky barrier diode D1 damps positive voltage spikes that occur at the noninverting input of comparator IC1
shortly after the high-to-low transition of the output voltage. Diode D2 clamps the negative excursion of the reference volt-
age during a low-to-high transition of the output voltage.
edn091126di45252 DIANE
turn-off time of Channel A of IC2. The (Figure 2). Diode
(PLACED D112-3
IN THE starts to conduct
FOLDER) can also use a diode-pair IC.EDN
ADCMP601’s data sheet shows a whenever a positive voltage excursion
charge injection into the source elec- of approximately 200 mV above the R e fe r e nce s
trode. In this case, however, charge in- higher reference voltage occurs at the 1 Štofka, Marián, “Circuit uses
jection to the drain electrode plays a D1 terminal, whereas D2 conducts at two reference voltages to improve
role. As a rough estimate, you can use excursions of 200 mV below the lower hysteresis accuracy,” EDN, Jan 7,
the data on charge injection in Refer- reference voltage. Further, the nonlin- 2010, pg 43, www.edn.com/article/
ence 2. As the charge injection chang- ear junction capacitance of these di- CA6713705.
es its sign, depending on the value of odes rises with forward voltage from 2 “Rail-to-Rail, Very Fast, 2.5 V to 5.5

the common-mode voltage, the charge 0.7 pF at a forward voltage of 0V to ap- V, Single-Supply TTL/CMOS Com-
is about 0.8 pC at VD1, which equals proximately 1.05 pF at a forward volt- parators ADCMP600/ADCMP601/
the high-level reference voltage, and age of 100 mV. At input voltages close ADCMP602,” Analog Devices, 2006,
it is approximately 20.3 pC when the to the higher reference voltage, diode www.analog.com/static/
reference voltage is low. This voltage D2 is reverse-biased by almost 2V, and imported-files/data_sheets/
ceases with the delay of the turn-on its capacitance drops to approximately ADCMP600_601_602.pdf.
time of the channels in analog switch 2/3CD(0), where CD is the capacitance 3 “ADG772 CMOS Low Power

IC2, an ADG772 (Reference 3). The of the nonbiased diode. Diodes D1 and Dual 2:1 Mux/Demux USB 2.0 (480
inadvertent return of the comparator’s D2 have a combined capacitance of 1.5 Mbps)/USB 1.1 (12 Mbps),” Analog
output to high, although lasting no pF. This amount can increase the input Devices, 2007–2008, www.analog.
more than 5 nsec, might cause some capacitance. Because the charge injec- com/en/switchesmultiplexers/
logic circuits to respond unexpectedly. tion doesn’t exceed 0.8 pC, the volt- analog-switches/ADG772/
A similar situation might occur when age excursions at the D1 terminal are products/product.html.
the input ramp with a negative slope less than 160 mV. Diodes D1 and D2 4 “HSMS-282x Surface Mount RF

crosses the lower reference voltage. reside within diode trio IC4, an Avago Schottky Barrier Diodes,” Avago Tech-
To prevent these hazardous states, Technologies (www.avagotech.com) nologies, May 28, 2009, www.avago
you can add two Schottky barrier diodes HSMS-282L (Reference 4), but you tech.com/docs/AV02-1320EN.

january 21, 2010 | EDN 33


designideas
Algorithm keeps data safe
Luis G Uribe C, Caracas, Venezuela tions and ambiguous situations. You can
enter the power-up verification rou-


Many embedded systems must the status of each main variable and its tine at any time, interrupting the main
regularly update multibyte data mirrored value in the storage devices. flow of the program without losing any
to EEPROM, flash memory, or a data- The states run in a sequence that the data. Figure 1 shows the flow of the
base server. This Design Idea presents software driver can use to write data algorithm, which begins with a power-
a robust algorithm for this process that to both the main and the backup vari- up routine. Table 1 identifies and de-
prevents data losses and inconsisten- ables. The driver sets and resets two fines each of the possible states for the
cies due to program interruptions or variables, B0 and B1, as status bits. variables.EDN
power failures. You can avoid data loss- B0 is the main vari-
es by maintaining two separate memory able status bit, and Table 1 Possible states of variables
areas, duplicating critical variables in B1 is a mirror status Bit state Description
each. Memory can be battery-backed bit. Both bits are re-
RAM, magnetic disks, flash memory, corded in the same B0 B1
or local or remote storage subsystems. storage medium as 0 0 Both variables are in steady state.
You can use a simple FSM (finite-state the data. If the power-up routine finds this state, it may as-
machine) that uses three or four states This algorithm sume that everything is fine; both values are prop-
with appropriate Gray coding to track prevents race condi- erly stored in the main site and in the backup. Your
program may read and use the data as needed.
When it’s time to modify a value, the driver sets a
POWER-UP one at B0 to indicate a zero/one.
ROUTINE
0 1 Data begins to write to the main variable.

MAIN() {
If the power-up routine finds this state upon
verification, you can assume that the main variable
is corrupt and decide how to update it from the
mirroring site.
When the driver finishes updating the main vari-
INITSYS();
able, it sets a one at B1 and keeps B0 untouched
at one to indicate two ones.
1 1 Data has written properly to the main variable, and
VFYDATA();
the driver soon begins the next state to duplicate
main data into its backup storage.
This state is transient to avoid changing bit values
WAS DATA YES between zero/one and one/zero at once. Using this
CORRECTED? sequence, the two data repositories may be in dif-
RETRY TO
ferent local or remote physical subsystems.
NO NO
GET OLD If the power-up routine finds this state, it may as-
DATA?
sume that the mirror variable is corrupt, and it will
NO NEW DATA YES proceed (next state) to update the mirror site from
TO STORE? the main location.
D=GETOLDDATA();
YES At any convenient time from now on, the finite-state
machine may leave this state and enter the next
one, one/zero, which means:
D=GETDATA();
1 0 Data has properly written to the main variable state,
and the driver now begins to duplicate the main
DO data into backup storage (similar meaning to previ-
SOME STOREDATA(); ous state, one/one).
WORK
If the power-up routine finds this state, the verifica-
tion routine may assume that the mirror variable is
NOTE: TRYING TO RETRIEVE OLD DATA THAT WAS NOT STORED
IS HIGHLY DEPENDENT ON THE APPLICATION.
corrupt and update the mirror site from the main
variable.

Figure 1 This algorithm starts with a power-up routine and When the driver finishes updating the mirroring
variable, it clears B1, and the finite-state machine
then verifies that the data is properly stored. (For other
reverts to the first state, two zeros, in the
algorithms, go to www.edn.com/100121dib.) sequence.

edn090917di45281 DIANE
(PLACED IN THE 10-8 FOLDER)
34 EDN | january 21, 2010
designideas

P-channel power-MOSFET driver D1 and D2 alternately enhance the


switching speed of Q5 and Q4.
uses unity-gain op amp Unity-gain op amp IC1A, with its
high slew rate, fast settling, capaci-
Suded Emmanuel, Emmanuel’s Controls, Auckland, NZ tive-driving capability, and feedback


P-channel MOSFETs can sim- to 50V, which turns off Q7. Transistor of the gate voltage, enhances Q7’s
plify designs when you use them Q5 functions as an inverter that turns switching speed. Using this circuit,
as high-side switches on circuits with on Q6, which subsequently drives Q3 to you can achieve a rise time and fall
voltages exceeding 100V dc. When rapidly switch D3’s anode to 50V and time of approximately 500 nsec at Q7’s
driving a MOSFET, you must rapid- thus drives Q7’s gate. Schottky diodes output.EDN
ly charge and discharge the
input capacitance between
50V
its gate and its source to re- 50V 50V
duce heat losses. The circuit PN200
in Figure 1 can accomplish C2 Q3
R9
that task. Q7, an Internation- 100 �F
1k D3 R5
al Rectifier (www.irf.com) 10V 20k
IRF5305 power P-channel 50V
R10
MOSFET, switches 50V to a 24k R4
load. A series of pulses from FROM PULSE- R7 Q4
16k
GENERATOR/ 2N7000
a pulse generator or PWM 4.7k
PWM CIRCUIT R3
(pulse-with-modulation) Q5
Q6
4.7k
source drives the load at fre- 2N7000
R6 2N7000
quencies as high as 60 kHz 4.7k R8
with a variable duty cycle. 0.94k
D2
The circuit comprises Q4, R5,
D2, R4, D3, and R3; provides D1
a means of level-shifting; and
ensures that the voltage drop
between the gate-to-source
voltage of Q7 never exceeds
50V
10V. When Q4 is on, 10V de- 50V
velops across D3. This volt- 50V
age drop turns on Q7 through C3
Q7
C5
op amp IC1A, one-half of an BD135
0.1 �F
0.1 �F RL
MC33072 from On Semi-
D4 3 8
conductor (www.onsemi. 12V
Q 1 �
1
com). IC1A has a 13V/msec IC1A
2�
slew rate and can drive ca-
½MC33072
pacitances as high as 10 nF. C
R2 4.7 1�F
4
R1
The combination of D4, R1, Q 2 10k
7.6k
Q1, Q2, R2, and C1 provides BD136
“ground” for the op amp, C4
which is at 38V—that is, 38V
0.1 �F
12V below the 50V rail volt-
age. The positive voltage is 5
50V, and ground is 38V. The �
7
IC1B
anode of D3 connects to the 6 �
noninverting input of IC1A, ½MC33072
whose output drives Q7’s gate
at 40V, which is 10V below
the rail voltage of 50V. The
circuit comprising R6, Q5, D1, Figure 1 An op amp operating at 38 to 50V provides power to a load through power-
R7, R8, Q6, R9, R10, and Q3 MOSFET Q7.
rapidly switches D3’s anode

36 EDN | january 21, 2010


edn091112di45751 DIANE
(PLACED IN THE 10-26 FOLDER)

You might also like