In nature, there are various electrical signals like analog, which means the time varying continuous signal. In such signals, the first quantity of the signal is a voltage, whereas the next quantity of the signal can be anything like pressure, force, temperature and light accelerations. Most of the microcontrollers available in the market are digital in nature. They can only recognize high or low-level input pins. For example, if the input is greater than 2.5 volts, then it will be treated as high, and if it is less than 2.5 volts, then it will be treated as low. So, we cannot directly measure voltage from microcontrollers.
To overcome this problem, microcontrollers use an A/D (analog to digital) conversion unit that helps change a voltage to a number. This permits to interface all kinds of analog devices with microcontroller unit. Some of the analog devices are light, temperature and touch devices, microphone and accelerometer.
Analog to Digital Converter in PIC Microcontroller
The short-term of the programmable interface controllers is PIC, which can be pre programmed to carry out a vast variety of tasks.The production line can be controlled by a pre programmed microcontroller with timers. The PIC microcontroller can be used in various electronic devices like alarm systems, electronic gadgets and computer control systems.These microcontrollers are somewhat low-cost and can be bought as kits or pre-built circuits that can be designed by the user.
Analog to Digital Conversion
In an embedded system, A/D conversion is very important as embedded systems deal with digital values; their surroundings usually occupy various analog signals. Analog signals need to be altered into digital before being treated by the microcontroller. At present, we can observe how to read an external analog signal using PIC microcontroller and exhibit the digital o/p conversion on an LCD display. The i/p signal can be a varying voltage between 0 to 5v.
The most important requirement of analog to digital conversion is the resolution. This states how exactly the A/D conversion measures the analog i/p signals. The common A/D conversions available in the market are 8-bit, 10-bit &12-bit. For example, if the reference voltage of A/D conversion is 0-5V, then a 8-bit A/D converter breaks this voltage into a number of parts (256 parts). So it can calculate the voltage exactly up to 5/256v= 19 mV approx. On the other hand, a 10-bit A/D converter breaks the voltage into 1024 parts. And hence, this converter can calculate the voltage accurately up to 5/1024= 4.8mV approx. Therefore, you can notice that the 8-bit A/D converter cannot tell the difference between 1mV & 18mV. The A/D converter in PIC microcontroller are 10-bit.
The other requirement of the A/D conversion is the sampling rate, which identifies how fast the analog to digital converter can receive readings. The Microchip that maintains the A/D converter of the PIC microcontroller can go as high as 100k samples/Sec.
Analog to Digital Converter in PIC Microcontroller
The module of the analog to digital converter in PIC microcontroller usually consists of 5 inputs for 28-pin devices and also 8 inputs for 40-pin devices.
The analog signal change to the PIC A/D module effects the value, which is equivalent to 10-bit digital number. The A/D module with PIC microcontroller includes a software selectable low & high voltage reference input with some combination of VDD, VSS, RA2 and RA3. The following project discusses about how to convert an analog i/p to digital number with high voltage & low voltage reference. The output of this project will be shown using LEDs. The reference voltage can be changed by arranging the ADCON1 register.
A/D Converter in PIC Microcontroller Circuit Diagram
The circuit diagram of the 10-bit analog to digital converter in PIC microcontroller is shown below. The test input voltage of the A/D converter is received from a 5k potentiometer allied across the potentiometer; it joins the two pins of the PIC microcontroller, namely AN2 and RA2. For A/D conversion, the power supply is chosen as the reference voltage. Thus, the 10-bit A/D converter can change any analog voltage to a digital voltage. The o/p is shown on the LCD display.
The programming of analog to digital converter in PIC microcontroller includes positioning the registers like ADCON0, ADCON1 and ANSEL.
- The register ADCON0 is used to select the analog input channel; start the exchange and verify the conversion is finished or not, and also to switch ON/OFF the module.
- The register ADCON1 is used to select the voltage reference, and to arrange ports as analog to digital
- The register ADCON2 is used to select the analog to digital data format, fix an A/D clock and setup acquisition time.
Here, AN2 or RA2 is used as an analog i/p – the equivalent register ANSEL must be set. In ADCON0 register, clear HS0 and CHS2 & set CHS1, to connect AN2 channel with the internal S&H circuit (sample & hold). In the register ADCON1, clearing the VCFG bit will decide the voltage supply for A/D conversion. This register is used to select the clock source in A/D conversion. Though the MikroC Pro for PIC microcontroller has got a built-in library function known as ADC_Read(), by default, it uses the internal RC CLK for the operation of the ADC. Therefore, there is no need to rearrange the ADCON1 register.
This is all about analog to digital converter in PIC microcontroller including what is a PIC microcontroller, A/D conversion, analog to digital converter in PIC microcontroller and the required software. We hope that you have got a better understanding of this concept. Furthermore, for any queries regarding this concept or electrical and electronic projects, please give your valuable suggestions by commenting in the comment section below. Here is a question for you – what are the applications of A/D converter?