Designing a Comparator
- TYelectronics
- May 25, 2023
- 3 min read
Updated: May 26, 2023
What the plan was.
1: Make a comparator that compares an input voltage to a set voltage.
2: The output needs to be inverted.
3: The voltage needs to be stable with a changing Vcc (as will be battery powered at some point.).
4: Needs to be made with BJT’s and not with op-amps.
5: Be able to integrate with a boost circuit.
Where to start. I thought to look and see what other people had come up with and came across this post by “uart” which gave me the basic concept for a comparator.
The next is to draw a schematic to and figure out what we think is going to happen

In the Green box is a potentiometer (setup as a voltage divider) which allows me to easily vary the input to the comparator.
In the Blue box is another potentiometer (setup as a variable resistor) this is in series with a 10k resistor so that we can set the voltage and current supplied to the Q₁ BJT's base, which allows us to set Vce (collector emitter voltage).
This means the threshold voltage for the comparators input is Vcc(5v)-Q₁Vce(2.5v)+Q₂Vbe(0.7v The forward voltage drop of most pn junctions) which equals 3.2v.
So we expect to see the LED light up when the input voltage is greater then 3.2V.
Now that we have the design we need to build it on a bread board and do some testing

I have built and tested it and this is what happens.
The Green line is the input voltage.
The Blue line is the threshold voltage.
The Orange line is the LED's state.
This is a good first start, and lets me know that something is working. But for my use case I would like the output to be inverted. So its back to the drawing board to see what I can come up with.

One of the problems I was having was that face that the Q₂ emitter was not connecting to ground but to 2.5v which was by design but is causes issues when trying to pull down a NPN transistor. so I thought of using an PNP (Q₃) which was pulled high with a 40k resistor, which would mean when the comparator input is greater then 3.2v Q₃ Base would be pulled low resulting int 5v being supplied to the LED. This worked but it had the same output as the previous design, so if input greater than 3.2v LED ON, if input less then 3.2v LED OFF. (Green line represents current)
So we need to add another stage.

I added another PNP Q₄ transistor which was pulled LOW, which means it is by default it is out putting voltage/current. The base of which is connected to the Q₃ emitter through a 40k resistor.
The out come of this is, the LED turns off when the input voltage to the comparator is greater then 3.2v.

After building the circuit and running the tests, this is the output graph.
The Green line is the input voltage.
The Blue line is the threshold voltage.
The Orange line is the LED's state.
OK now the circuit work. Its time to see if it can be made with less components, as there is a lot going on at the moment.

Here I have removed the original Q₁ as I realized all I needed was a voltage divider to set my threshold voltage. As I do not want the threshold voltage to be able to change once it has been set. I have also removed the Voltage divider potentiometer as it will be replaced with a feed back voltage for the boost converter. Some of the resistor values have also changed to increase the performance of the circuit. And the output now goes off to another part of the boost converter.
There is still lots of testing to be done, but for now it seems to be working.

This is what it looks like on the bread board.
Comments