You Are Here: Home » AVR ATmega Projects » Development Board - Kits Projects » Working with the Comparator Circuit

Working with the Comparator Circuit

Sometimes in the embedded system world we need to process the analog world and sending the signal to the microcontroller when the analog signal exceed some predetermine limit we’ve set. Some example of this situation is to send the interrupt signal to the microcontroller operation when the temperature is already exceeds certain limit or the light intensity exceeds certain bright level. This is when the comparator circuit becomes handy as it’s designed specially for this purpose.

Today the modern comparator is easily found in the form of integrated circuit such as the popular National Semiconductor LM339 quad (four) comparator 14 pins dual in line (DIL) package bellow:Diagram Working with the Comparator Circuit

When you look closely to the comparator symbol, some of you will recognize it as the Op-Amp (Operational Amplifier) symbol, so what make this comparator differ from its big brother; Op-Amps is designed to accept the analog signal and outputting the analog signal while the comparator only outputting the digital signal; although the ordinary Op-Amp could be used as the comparator such as the popular National Semiconductor LM324 quad Op-Amps, but the real comparator is designed to have a faster switching time comparing to the multipurpose Op-Amps. Therefore you could say that the comparator is the modified version of the Op-Amps which specially designed to give the digital output.

1. Basic Comparator Circuit

The comparator circuit work by simply taking two analog inputs, comparing them and produce the logical output high “1” or low “0“.

By applying the analog signal to the comparator + input called “non-inverting” and – input called “inverting“, the comparator circuit will compared this two analog signal, if the analog input on + input is greater than the analog input on – input (inverting) then the output will swing to the logical “1” and this will make the open collector transistor Q8 on the LM339 equivalent circuit above to turn ON. When the analog input on + input (non inverting) is less than the analog input on – input (inverting) then the comparator output will swing to the logical “0” (the Q8 transistor turn OFF). Furthermore on this tutorial, I will use the term non-inverting and inverting instead of + input and – input on the comparator analog input.

As you’ve seen from the LM339 equivalent circuit picture above, the LM339 use an open collector transistor Q8 for its output, therefore we have to use what is called “pull-up” resistor connected to the Q8 collector lead with the Vcc in order to make this Q8 transistor work. The maximum current that could flow on this Q8 transistor (output sink current) according to the LM339 datasheet is about 18 mA.Working with the Comparator Circuit

The testing circuit simply connects the comparator inverting input to the voltage divider R1 and R2, with 5 Volt voltage supply the V- could be calculated as follow:

V- = (R2 / (R1 + R2)) x Vcc
V- = (10 / 20) x 5 volt = 2.5 volt

For more detail: Working with the Comparator Circuit

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Using Transistor as a Switch
Using Transistor as a Switch

Most of microcontrollers work within 5 volt environment and the I/O port can only handle current up to 20mA; therefore...

Scroll to top