What is meant by Analog to Digital Converter (ADC)? An ADC converts analog signal to it's corresponding digital signal.
How to convert analog signal to digital signal? CircuitsGallery.com has already posted ADC using LM324 IC, in that ADC tutorial I had already explained Analog to Digital Converter how it works.
While dealing with Microcontrollers we may face many situations where we have to use ADCs (Digital voltmeter, ammeter etc.). In such situations it's difficult to set up a separate ADC hardware circuit for our project.
So How to Use Analog to Digital Converter (ADC module) in PIC microchip microcontroller? PIC microcontrollers have inbuilt ADC module making easy Analog to Digital conversion.
In this article I’m gonna show you how to make use of ADC module in PIC16F877A microcontroller with the help of Mikro C Pro compiler and Proteus 8 simulator.
At the end of this tutorial, I did the video demonstration and simulation about analog to digital conversion using PIC16f877a.
After reading this ADC tutorial, I’m sure that you will be able to program a PIC microcontroller for manipulating the ADC module. Come on let's start PIC microcontroller programming.
Before going to the circuit diagram and embedded program, let me figure out some details about ADC in PIC and also ADC and inbuilt library functions in Mikro C.
What is the use of ADCON1 (Analog to Digital CONtrol Register)?
The ADCON1 register configures the functions of the port pins. The port pins can be configured as analog inputs or as digital I/O according to the value in ADCON1 register. In our program we have used ADCON1=0x80; because we are using PORTA as Analog input port.
adc = ADC_Read(1)
This will read analog value from channel 1 (PORTA.F1) and save in to a variable ‘adc’ after converting it into 10 bit digital value.
What is the use of CMCON (CoMparator CONtrol Register)?
PIC has two analog comperators multiplexed with PORTA, and these comparators can be operated in 8 different modes with respect to the values in CMCON register.
Here I’m showing only 1 mode that is disabled comparator mode, all other modes are out of our interest.
For ADC operation we don't need CMCON register. So we are turning OFF the comparator by setting CMCON=0x07;
0x07=0000 0111,
Thus the status of CMCON should be,
It will turn OFF the comparators.
If you got an idea of the above codes let’s start our Mikro C programming. The program is very simple and only the 3 codes are new to you.
(Read More: What is do--while loop?)
Downloads: Hex file for PIC ADC
How to convert analog signal to digital signal? CircuitsGallery.com has already posted ADC using LM324 IC, in that ADC tutorial I had already explained Analog to Digital Converter how it works.
While dealing with Microcontrollers we may face many situations where we have to use ADCs (Digital voltmeter, ammeter etc.). In such situations it's difficult to set up a separate ADC hardware circuit for our project.
So How to Use Analog to Digital Converter (ADC module) in PIC microchip microcontroller? PIC microcontrollers have inbuilt ADC module making easy Analog to Digital conversion.
At the end of this tutorial, I did the video demonstration and simulation about analog to digital conversion using PIC16f877a.
After reading this ADC tutorial, I’m sure that you will be able to program a PIC microcontroller for manipulating the ADC module. Come on let's start PIC microcontroller programming.
Before going to the circuit diagram and embedded program, let me figure out some details about ADC in PIC and also ADC and inbuilt library functions in Mikro C.
ADC Register in PIC MCU
- ADC (Analog to Digital Converter) module is offered in many of PIC MCU models.
- The Analog-to-Digital (A/D) Converter module has eight inputs for the 40 pin PIC Microcontrollers.
- In PIC16F877A, PORTA is multiplexed with ADC register, Comparator and Digital I/O operations. Due to the availability of ADC, PORTA is also known as Analog port.
- In order to work on ADC we must configure the ADC register in proper way.
- In PIC MCU, the conversion of an analog input signal effects in an equivalent 10-bit digital number (10 bit ADC).
Mikro C ADC Library and Important Library Routines for ADC Module
Micro C Library functions provide comfortable platform for working with ADC module in PIC. The only thing that we should add is the LCD library from the library manager.What is the use of ADCON1 (Analog to Digital CONtrol Register)?
The ADCON1 register configures the functions of the port pins. The port pins can be configured as analog inputs or as digital I/O according to the value in ADCON1 register. In our program we have used ADCON1=0x80; because we are using PORTA as Analog input port.
adc = ADC_Read(1)
This will read analog value from channel 1 (PORTA.F1) and save in to a variable ‘adc’ after converting it into 10 bit digital value.
What is the use of CMCON (CoMparator CONtrol Register)?
PIC has two analog comperators multiplexed with PORTA, and these comparators can be operated in 8 different modes with respect to the values in CMCON register.
Here I’m showing only 1 mode that is disabled comparator mode, all other modes are out of our interest.
For ADC operation we don't need CMCON register. So we are turning OFF the comparator by setting CMCON=0x07;
0x07=0000 0111,
Thus the status of CMCON should be,
It will turn OFF the comparators.
If you got an idea of the above codes let’s start our Mikro C programming. The program is very simple and only the 3 codes are new to you.
Circuit diagram of PIC Microcontroller ADC
(Click on the image to enlarge)
Components required
- PIC16F877A
- Crystal Oscillator (Select frequency according to you)
- Ceramic Capacitor (22pF x 2)
- LED x 10
- Resistors (100Ω x 10, 1/4 Watt)
PIC LCD Module Mikro C Program
In this program PORTB and 2 bits of PORTC (RC7, RC6) are used to display the output since ADC output is 10 Bit and the program works on do--While loop.(Read More: What is do--while loop?)
Downloads: Hex file for PIC ADC
How to burn this program to PIC MCU?
Before we had published tutorials related to building of .hex files and burning of the microcontroller.
Please watch the video for understanding more about bulding .Hex file and simulation.
i-St@r Video Lab
Here is the video simulation of ADC with PIC16f877A including programming steps.
Please like our Facebook page to get new PIC Circuits and updates.
No comments:
Post a Comment