Full Stack Electronics · Stage Three · Experiment 3

Experiment 3: The Almost-Comparator

Build a comparator from one transistor and put it to the test.

In Experiment 2 you built a working timer from two chips and two transistors, and measured the signals between its blocks. The LM393 did the comparing, and it is still a sealed chip. Stage Three builds that comparison from transistors. Experiments 3 to 8 build the two comparators, and Experiment 7 also fits Experiment 2's divider on the transistor board. Experiment 9 measures that divider, and Experiments 10 to 13 add the latch and the reset. At the end, the whole 555 is separate parts on your breadboard.

A comparator switches its output when one input voltage crosses another. A transistor on its own does something similar. Below about 0.6 V on its base, the transistor is off. Above about 0.6 V, the base-emitter junction conducts, and current flows through the transistor. So a transistor is a simple comparator with one input, and it compares that input against 0.6 V. This experiment starts there: one transistor, two resistors and the oscilloscope on the collector.

You will need

Build the transistor switch

Start with the transistor and its two resistors. Figure 3-1 shows the circuit, which is called a common-emitter stage because the grounded emitter is common to the input and the output. The 10 kΩ resistor feeds the base. The 1 kΩ resistor connects the collector to +5 V. The emitter connects directly to ground. The input is the free end of the 10 kΩ resistor, and the output is the collector.

Schematic of the transistor switch. IN, the signal from the function generator, goes through a 10 kilohm resistor into the base of a 2N3904. A 1 kilohm resistor connects the collector to +5 volts. The emitter goes to ground. The collector is the output, OUT, which goes to oscilloscope channel 2.
Figure 3-1: The transistor switch: 10 kΩ into the base, 1 kΩ from the collector to +5 V, and the emitter to ground. IN is the signal from the function generator, and OUT is the collector.

Drive it with the function generator

Figure 3-1 has an input, but nothing drives it yet. In Experiment 2 you set a reference with power supply output 2 and read a meter. That method gives one voltage at a time. To measure a switch, you need its output at every input voltage: where the output changes, and how much input the change needs. A function generator sweeps the input for you. It makes a repeating waveform with the shape, frequency and levels that you set.

For this job, use a slow triangle wave from 0 V to 2 V at 100 Hz. Each input voltage then arrives in order, up and down, again and again. The two oscilloscope traces share one time axis. When the output switches, read the input trace at the same instant: that reading is the threshold. The keystrokes for the SDG1062X are in the function generator reference. Read it once before you start.

The output of the function generator must reach two places: the input of the circuit and oscilloscope channel 1. Then you can read the input and the output side by side. Figure 3-2 shows the connections. A BNC T-piece sits on the oscilloscope channel 1 input. One arm takes the BNC cable from the function generator. The other arm takes a lead that ends in two mini-hook wires: red to the input of the circuit, black to ground.

Oscilloscope channel 1 thus shows the voltage that the circuit receives, measured at the oscilloscope. The display of the function generator shows only the voltage that it intends to deliver. Oscilloscope channel 2 is an ordinary probe on the collector. All black leads and ground clips connect to the ground rails of the breadboard. The function generator and the oscilloscope already share a ground through their mains plugs.

The bench for this experiment. Above the breadboard are two simplified front panels: the oscilloscope on the left and the function generator on the right. The oscilloscope screen shows the yellow input triangle and the magenta output square wave. The function generator screen shows a ramp at 100 hertz from 0 to 2 volts, with the load set to HiZ. A BNC cable runs from output 1 of the function generator to the right arm of a T-piece on the oscilloscope channel 1 input. The Output key for that output is lit. From the left arm of the T-piece, a lead runs down to the breadboard and splits. The red wire goes into 10c, the free end of the base resistor. The black wire goes into the top ground rail at column 7. The oscilloscope channel 2 probe runs down to the collector at 11i, beside the 2N3904 and its 1 kilohm collector resistor. Its ground clip goes to the bottom ground rail at column 14. A red wire at column 29 links the two +5 volt rails, and a blue wire at column 28 links the two ground rails.
Figure 3-2: The bench. The function generator feeds a T-piece on oscilloscope channel 1 and, through it, the base resistor at 10c. Oscilloscope channel 2 probes the collector at 11i. Both ground leads go to the ground rails. Click to enlarge.
  1. Prepare the board. Use another full-size breadboard (BB830), so that Experiment 2's board stays assembled. Figure 3-2 shows the left-hand 30 columns of the board.
  2. Link the rails. Link the top +5 V rail to the bottom +5 V rail with a red wire at column 29. Link the top ground rail to the bottom ground rail with a blue wire at column 28.
  3. Insert the transistor. Insert the 2N3904 at 9h, 10h and 11h, with the flat face towards the near edge of the board. The legs are then emitter, base and collector from left to right, as in Experiment 2.
  4. Insert the resistors and the ground wire. Connect a blue wire from 9j to the bottom ground rail at column 9. This wire grounds the emitter. Insert the 1 kΩ resistor from 11j to the bottom +5 V rail at column 11. Insert the 10 kΩ resistor across the centre channel, from 10f to 10e.
  5. Power the rails. Set the power supply to 5.00 V with a 50 mA current limit, as in Experiment 2. Connect its positive lead to the top +5 V rail at column 1. Connect its negative lead to the bottom ground rail at column 2.
  6. Connect the signal leads. Attach the T-piece to the oscilloscope channel 1 input. Connect the output of the function generator to one arm of the T-piece with the BNC cable. Connect the mini-hook lead to the other arm. Connect its red wire to 10c, the free end of the 10 kΩ resistor. Connect its black wire to the top ground rail at column 7.
  7. Connect the probe. Put the oscilloscope channel 2 probe tip on the collector at 11i. Clip its ground lead to the bottom ground rail at column 14. If a trace looks wrong, check the ground clips first. In my experience, a missing ground causes more strange traces than any other fault.
  8. Set the function generator. Select the connected channel of the function generator. Set its output load to HiZ before you enable it (see the caution below). Then set a triangle wave at 100 Hz from 0 V to 2 V. On the SDG1062X: Waveforms → Ramp (a ramp at its default 50 % symmetry is a triangle) · Frequency 100 Hz · press Offset twice so that it becomes LowLevel, and set 0 V · press Amplitude twice so that it becomes HighLevel, and set 2 V · Output on.
  9. Set the oscilloscope. Set the oscilloscope channel 1 probe factor to 1× for the direct BNC cable. Set the switch on the probe to 10×. Set the oscilloscope channel 2 probe factor to 10×. Use the 1 MΩ inputs, with both channels DC-coupled at 1 V/div. Set the timebase to 1 ms/div. Set an edge trigger on oscilloscope channel 1, rising, at 1 V. Oscilloscope channel 1 shows the triangle. Oscilloscope channel 2 should show an approximately square wave. It is high while the triangle is low, and low while it is high. The next sections examine its sloping edges.

Before you take readings, set the output load of the function generator to HiZ. On the SDG1062X, hold the Output key of the channel for two seconds, or use Utility → Output Setup → Load → HiZ. With a 50 Ω load setting, the function generator doubles its internal voltage to allow for that load. A breadboard draws almost no current, so each level that you set arrives twice as large. If the measured triangle is twice the range that you set, check this setting. Check it at the start of each session, because some settings changes reset it.

One transistor makes a comparison

With the function generator running, oscilloscope channel 2 shows what the transistor does with each input voltage. Watch the magenta output while the yellow input rises. At first, the output stays near +5 V. As the input passes through a small region above half a volt, the output falls towards ground. When the input falls again, the output rises again. So the transistor converts a smooth input into two output levels, with a transition between them.

This circuit is already a simple comparator. With the input below the switching region, the transistor is off and the output is high. With the input above that region, the transistor is on and the output is low. The decision is inverted: more input gives less output. But the circuit has no way to set where the switching region sits, or to hold it there.

Oscilloscope: input triangle in yellow and inverted output square wave in magenta. Cursors bracket the falling edge of the output, which spans 0.60 to 1.10 volts of input, 0.50 volts.
Figure 3-3: My capture. Yellow is the input triangle on oscilloscope channel 1. Magenta is the collector on oscilloscope channel 2. The cursors bracket the fall of the output, 1.24 ms of the ramp. The input at those two moments reads 0.60 V and 1.10 V. So the fall takes 0.50 V of input. The flaw 2 section measures that width.

What just happened?

Figure 3-3 shows three things: a high output, a fall and a low output. The currents in the transistor cause each one. With the input near 0 V, no base current flows, so no collector current flows. With no current through the 1 kΩ resistor, there is no voltage across it. So the collector stays at the supply voltage, +5 V. That is the high output level.

Now the input rises. When the base is about 0.6 V above ground, base current flows in through the 10 kΩ resistor. The transistor then passes a collector current about a hundred times larger. That current flows through the 1 kΩ resistor and, by Ohm's law, makes a voltage across it. So the collector is below +5 V by that voltage. More input gives more base current, more collector current and a larger voltage drop: the output falls.

The fall stops when the transistor is fully on. Even then, a small voltage stays between collector and emitter, and that voltage is the low output level. In Figure 3-3 this level seems to sit on the ground line. Set oscilloscope channel 2 to 500 mV/div. Put one voltage cursor on the ground marker and the other on the flat bottom of the magenta trace. The gap is then visible, and mine reads 0.15 V.

A transistor in this state is saturated, and a few tenths of a volt is typical. The 2N3904 datasheet specifies a maximum of 0.2 V at 10 mA collector current and 1 mA base current. The datasheet guarantees that limit only at those test conditions. This circuit operates at different currents.

Oscilloscope with channel 2 at 500 millivolts per division. The bottom of the magenta output trace sits just above the ground marker. Cursor Y1 is on the ground marker at 0.0 volts, and Y2 is on the bottom of the trace at 0.15 volts.
Figure 3-4: The same signals with oscilloscope channel 2 at 500 mV/div. Cursor Y1 is on the oscilloscope channel 2 ground marker, and Y2 is on the bottom of the magenta trace. The difference is 0.15 V: the saturated collector.

The three regions of a transistor

The high level, the fall and the low level are the three operating regions of the transistor. Each sweep of the triangle takes the transistor through all three, and the magenta trace shows each one. Datasheets and textbooks use these names.

A comparator should spend as little of its input range as possible in the active region. In that region, the output is neither high nor low.

Flaw 1: you cannot choose the threshold

The three regions describe how the transistor switches. The next question is what it compares against. A comparator such as the LM393 compares two input voltages: one is the signal, and the other is a reference that you set. In Experiment 2 the LM393 compared the capacitor voltage against 1.67 V and 3.33 V. Those levels came from the divider, which connected to the second input of each comparator.

Figure 3-1 has no place for such a level. The base is the only input, and the 10 kΩ resistor that feeds it carries the signal. So the reference of this comparator is fixed. It is the 0.6 V of the base-emitter junction, it comes with the transistor, and no terminal can change it.

Figure 3-3 already shows where the circuit switches. The fall starts at 0.60 V, the voltage of the junction itself, and ends at 1.10 V. The extra half volt is mostly the drop across the 10 kΩ resistor as the base current increases. Read your two values in the same way. Different transistors give different results, so the part sets the switching point. The next section measures how cleanly the output switches there.

Flaw 2: the transition is wide

Flaw 1 is about where the output switches. Flaw 2 is about how cleanly it switches. A comparator should give a yes or a no: high output on one side of the threshold, low output on the other, and nothing between. An ideal comparator needs no input change at all to go from high to low. In Figure 3-3 the fall of the magenta trace slopes. So, for a range of input voltages, the output is neither high nor low.

To measure that range, narrow the triangle to 0.4–1.2 V and keep it at 100 Hz. On the SDG1062X, set LowLevel to 0.4 V and HighLevel to 1.2 V. The fall then fills more of the screen.

Press the Cursors button on the oscilloscope. Set the cursor mode to Manual, the type to XY and the source to oscilloscope channel 1. Put X1 where the output starts to fall, and X2 where it reaches the bottom. Then move Y1 and Y2 onto the yellow trace where it crosses each X cursor. The Y readouts are the input at the start and at the end of the fall. Y2−Y1 is the width of the transition.

Use the same endpoints when you repeat this measurement on later circuits.

Oscilloscope with the input triangle narrowed to 0.4 to 1.2 volts. The fall of the magenta output spans 2.60 milliseconds between the X cursors. The Y cursors on the yellow trace read 0.60 and 1.06 volts, 0.46 volts apart.
Figure 3-5: The 0.4–1.2 V sweep. X1 and X2 bracket the fall, 2.60 ms of it, and the Y cursors read 0.60 V and 1.06 V of input at those moments. The ramp rises 0.16 V per millisecond, so 2.60 ms is 0.42 V. Both readings give a transition of a little under half a volt.

So the transition is about half a volt wide. Inside that band, the output passes through every voltage between high and low. A slowly charging timing capacitor would stay in that band for a long time. The next circuit must then decide which of those voltages counts as a switch. So the second requirement, after a reference that we can set, is a transition as narrow as possible.

Figure 3-5 reads the band from two traces against time. X-Y mode shows the same band as one line, with output plotted against input. On the SDS1104X-E, press Acquire and set the XY softkey to On. Set oscilloscope channel 1 to 200 mV/div, so that the input fills the width. Turn the oscilloscope channel 1 position knob to centre the curve. The line on the screen is the transfer curve of the circuit.

X-Y oscilloscope capture of the transfer curve: a flat saturation shelf, a sloped transition and a flat cut-off shelf. The cursors show 4.82 volts of output for 0.448 volts of input, a gain of about 11.
Figure 3-6: The transfer curve in X-Y mode. The input goes across, on oscilloscope channel 1 at 200 mV/div. The output goes up, on oscilloscope channel 2 at 1 V/div. The cursors read 4.82 V of output for 0.448 V of input. So the gain, the output change divided by the input change, is about 11.

Reading a transfer curve

Figure 3-6 is the transfer curve of this circuit. A transfer curve shows the output for each input voltage, without time. It has two settled regions, and the active region of the transistor joins them.

Voltage gain is the output change divided by the input change. With input on the horizontal axis, more gain gives a steeper transition. An ideal comparator would switch along a vertical line. Figure 3-7 marks these features on a drawn curve.

Diagram of a transfer curve with input voltage across and output voltage up. A high shelf is labelled cut-off, a sloping active region is labelled the slope is the gain, and a low shelf is labelled saturation. Blue arrows mark the input change and the output change, with gain equal to output change divided by input change. A red dashed vertical line marks an ideal comparator.
Figure 3-7: A transfer curve, input across and output up. The gain is the output change divided by the input change. So a steeper slope means more gain, and an ideal comparator is a vertical step.

Flaw 3: warmth moves the threshold

Flaws 1 and 2 are about where and how cleanly the output switches. Flaw 3 is about whether the switching point stays in one place. A comparator should keep its threshold where it was set, at any temperature of the room or the part. The timing of the 555 depends on its two references staying at one third and two thirds of the supply. So the third test heats the transistor and measures where the output switches.

Return the oscilloscope to its normal time display: press Acquire and set the XY softkey to Off. Set both channels to 1 V/div and the timebase to 500 µs/div, as in my capture. Restore the triangle to 0–2 V. Trigger on oscilloscope channel 1, rising, so that the input stays in one place on the screen. Then any movement comes from the output.

Persistence keeps earlier traces on the screen. Press Display/Persist, press the Persist softkey and turn the Universal Knob to select Infinite. For colour grading, press the Color softkey in the same menu and set it to On.

For this test, the threshold is the input voltage where the magenta trace leaves its high shelf. Put an X cursor there. Read oscilloscope channel 1 at the same instant with a Y cursor. Record that input voltage at room temperature.

Now warm the transistor for a few seconds. Use a heat gun on its lowest setting, or a hair dryer, from a hand's width away. Keep the air off the rest of the board. Stop before the plastic of the transistor softens. When the warm trace settles, put the X cursor where it leaves the high shelf, and read oscilloscope channel 1 again.

Then stop heating, and watch the fall return as the transistor cools. Persistence shows the movement. Compare the cold and warm readings at the same point, where each trace leaves the high shelf.

A small black hot-air gun with a red nozzle, on the bench. Its label reads hot air gun, 230 volts, 300 watts. The nozzle carries the warning that it may be hot.
Figure 3-8: The heat gun: a small 300 W hot-air tool. Its lowest setting, from a hand's width away, is enough.
Persistence capture with colour grading. The yellow input ramp rises across the screen. The falling edge of the magenta output forms a wide purple band. A red core on one side marks where the edge spent most of its time. Cursor X1 is where the warmest trace leaves the high shelf, and X2 is where the coldest trace leaves it. The Y cursors on the input read 0.42 and 0.68 volts, 0.26 volts apart.
Figure 3-9: My persistence capture, with colour grading on and the timebase at 500 µs/div. The purple band shows each position of the falling output while the transistor warmed under the heat gun and cooled again. Red marks where the edge spent most of its time. X1 is where the warmest trace leaves the high shelf, and X2 is where the coldest trace leaves it. The input at those two moments reads 0.42 V and 0.68 V. So the heat moved the start of the fall down by 0.26 V.

Same sweep, warmer transistor, lower threshold, and the threshold returns as the part cools. On my board, the start of the fall moved from 0.68 V of input down to 0.42 V: a shift of 0.26 V. My cold reading here is 0.08 V higher than the 0.60 V of Figure 3-3, and these two captures do not show why. A timer built on this comparator would run at a different rate on a warm day. So the third requirement is a threshold that stays in one place as the temperature changes.

The base-emitter junction is one cause. The base-emitter voltage needed for a given collector current falls as the transistor warms, typically by about 2 mV per degree Celsius. Changes in current gain can also change the drop across our base resistor. At 2 mV per degree, a 0.26 V shift needs about 130 degrees of warming. I did not measure the temperature of the transistor. So this capture cannot separate the junction from other causes, and it gives no drift rate in millivolts per degree.

The flaw list

The circuit makes a decision. But the transistor sets its threshold, its transition is wide, and its reference moves with heat.

#FlawWhat it meansFoundStatus
1No reference inputThe threshold is the transistor's own 0.6 V. Nothing outside the circuit sets it.Found hereOpen until Experiment 4
2Wide transitionThe output needs a band of input to travel from high to low: about half a volt with one transistor, about a quarter of a volt with the pair.Found hereOpen until Experiment 6
3Thermal driftThe base-emitter voltage falls about 2 mV per degree, and the threshold falls with it.Found hereOpen until Experiment 4

Going further

Much of the width in flaw 2 probably comes from the 10 kΩ base resistor, and one substitution tests this. Replace the 10 kΩ base resistor with a 1 kΩ resistor, and draw the transfer curve again. The band should be about a third as wide. The transistor needs about 50 µA of base current to reach 5 mA. That current makes 0.5 V across 10 kΩ, but only 0.05 V across 1 kΩ.

But the input must now supply ten times the base current. A function generator can supply it. A timing capacitor cannot: at 3.33 V, a 1 kΩ base resistor takes more than 2 mA from the circuit that drives it. In Experiment 1, the charging current of the timing loop stays below about 0.17 mA once the timer runs. So the fix for the wide transition must increase the gain without taking more current from the input.

Quick check

1. As a 555 comparator, this circuit's disqualifying limitation is that…

The comparison happens against VBE, fixed near 0.6 V by the silicon, plus the drop across the base resistor. The two thresholds of the 555, 1.67 V and 3.33 V, must come from outside the comparator. Experiment 4 arranges this. The latch of the timer accepts an inverted output, as it did from the driver in Experiment 2.

2. The band you measured corresponds to the transistor crossing…

The amplifier region is between cut-off and saturation. The gain of the circuit sets how much input it takes to cross that region. A gain of about 11 means about 5 V ÷ 11, or about 0.45 V of input. More voltage gain makes that input band narrower. Switching speed is a separate measurement.

3. Warming the transistor moved the threshold lower because…

At a given collector current, VBE typically falls by about 2 mV/°C. The drop across the base resistor can also change. A circuit whose reference is a VBE moves with the temperature. The fix is two matched transistors that drift together, so that much of their shared drift cancels. That circuit is the differential pair of the next experiment.

Before moving on

You built a comparator from one transistor and two resistors, and you examined three limitations. It switches where its own base-emitter junction sets the threshold: between 0.60 V and 1.10 V of input on my board. It has no way to set 1.67 V. Its output needs about half a volt of input to go from high to low. And warm air moved its switching region down by 0.26 V on my board.

So a comparator must do three things better. It must take its reference from an input, switch inside a narrow band, and stay in place as the temperature changes.

Experiment 4 fixes the missing reference input and should reduce the drift. It joins two transistors at their emitters and feeds them one shared current. The base of the second transistor becomes the reference input. When the two transistors share a temperature, much of the drift should cancel. Experiment 4: The Differential Pair compares two input voltages by sharing a current between two transistors.

Contents All experiments