The Analog world with digital Electronics
Few years back the entire electronics devices that
we use today like phones, computers, Televisions etc were analog in
nature. Then slowly the landline phones were replaced by modern mobile
phones, CRT Televisions and monitors were replaced by LED displays,
computers with vacuum tubes evolved to be more powerful with
microprocessors and microcontrollers inside them and so on..
In today’s digital age we are all surrounded by
the advanced digital electronic devices, this might deceive us to think
that everything around us is digital in nature, which is not true. The
world has always been analog in nature, for instance everything that we
humans feel and experience like speed, temperature, air velocity,
sunlight, sound etc are analog in nature. But our electronic devices
which run on microcontrollers and microprocessors cannot read/interpret
these analog values directly since they run only on 0’s and 1’s. So we
need something which will convert all these analog values into 0’s and
1’s so that our microcontrollers and microprocessors can understand
them. This something is called the Analog to Digital Converters or ADC for short. In this article we will learn everything about ADC and how to use them.
What is ADC and how to use it?
As said earlier ADC stands for Analog to digital
conversion and it is used to convert analog values from real world into
digital values like 1’s and 0’s. So what are these analog values? These
are the ones that we see in our day to day life like temperature, speed,
brightness etc. But wait!! Can an ADC convert temperature and speed
directly into digital values like 0’s and 1’s?
No defiantly not. An ADC can only convert analog voltage values into digital values.
So which ever parameter we wish to measure, it should be converted into
voltage first, this conversion can be done with the help of sensors.
For example to convert temperature values into voltage we can use a
Thermistor similarly to convert brightness to voltage we can use a LDR.
Once it is converted to voltage we can read it with the help of ADC’s.
In order to know how to use an ADC we should first
get familiar with some basic terms like, channels resolution, range,
reference voltage etc.
Resolution (bits) and channels in ADC
When you read the specification of any
Microcontroller or ADC IC, the details of the ADC will be given using
the terms channels and Resolution (bits). For instance an Arduino UNO’s ATmega328 has a 8-channel 10-bit ADC.
Not every pin on a microcontroller can read Analog voltage, the term
8-channel means that there are 8 pins on this ATmega328 microcontroller
which can read Analog voltage and each pin can read the voltage with a
resolution of 10-bit. This will vary for different types of
Microcontrollers.
Let us assume that our ADC range is from 0V to 5V
and we have a 10-bit ADC this means our input voltage 0-5 Volts will be
split into 1024 levels of discrete analog values(210 = 1024). Meaning 1024 is the resolution for a 10-bit ADC, similarly for a 8-bit ADC resolution will be 512 (28) and for a 16-bit ADC resolution will be 65,536 (216).
With this if the actual input voltage is 0V then
the MCU’s ADC will read it as 0 and if it is 5V the MCU will read 1024
and if it somewhere in between like 2.5V then the MCU will read 512. We
can use the below formulae to calculate the digital value that will be
read by the MCU based on the Resolution of the ADC and Operating
voltage.
(ADC Resolution / Operating Voltage) = (ADC Digital Value / Actual Voltage Value)
Reference Voltage for an ADC
Another important term that you should be familiar with is the reference voltage. During an ADC conversion the value of unknown voltage is found by comparing it with a known voltage, this is known voltage is called as Reference voltage. Normally all MCU has an option to set internal reference voltage, meaning
you can set this voltage internally to some available value using
software (program). In an Arduino UNO board the reference voltage is set
to 5V by default internally, if required user can set this reference
voltage externally through the Vref pin also after making the required
changes in the software.
Always remember that the measured analog voltage
value should always be less than the reference voltage value and the
reference voltage value should always be less than the operating voltage
value of the microcontroller.