Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

ADC Module of PIC Microcontroller

ADC Module of PIC Microcontroller

Fig: Analog to Digital Conversion


 In this tutorial i will be discussing the ADC module of the PIC Microcontroller. You can also check my previous post on interfacing the 7 - Segment Display with PIC microcontroller .

The PIC microcontroller has an in-built ADC Module. Analog to Digital Converters are widely used devices for Data acquisition. The physical world is Analog (i.e. Continuous) but Digital Computers use Binary values (i.e. Discrete ) . Physical  quantities such as Temperature, Pressure , Humidity , Velocity etc. are converted to electrical signals (voltage and current) using a device called a transducer. Transducers are also referred to as Sensors. Sensors senses Analog quantities and there is need for an Analogue to Digital converter so that a Microcontroller can process the information gotten from these sensors.

Conversion Time

Conversion time is the time it takes the ADC to convert the Analog input into a Digital value , This time is determined by the clock source connected to the ADC, method used for data conversion and also the technology used in the fabrication of the ADC chip.

Several PIC MCU have different ADC inputs, PIC MCU with twenty-eight (28) pins has five (5) ADC inputs  while PIC MCUs with forty /forty-four (40/44) pins have eight (8) ADC inputs. The ADC module of a PIC MCU is a 10-bit ADC i.e. it converts the Analog signal into a corresponding 10-bit digital value. The positive and negative reference voltage (+Vref and -Vref) of PIC ADC is software selectable, which can be VDD, VSS, voltage at RA2 or RA3.

To learn more about the ADC module of the PIC MCU you can check out the data sheet of the popular PIC16F877A here

MikroC PRO for PIC Compiler has a set of built-in functions that makes it easy to interface tranducers with the PIC MCU via the ADC module.

Check out  these functions with descriptions here.

Circuit Diagram:




CODE:
/*
    Name     : ADC Module of PIC MCU
    Author   : Daniel Oluwole
                       (C) 2020 Danitronics
                       danieloluwole51@gmail.com, danieloluwole51@yahoo.com
    Mobile:    +234 8188508765.
   
  */

// LCD pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;


unsigned int  Read;       //variable to store ADC Value
char  Adc_txt[15];        //store string
float Adc_value;



void main() {
 TRISA  = 0xFF;              // PORTA is input

  TRISB  = 0;                 // PORTB IS OUTPUT
  Lcd_Init();                 //INITIALIZE LCD
  ADC_Init();                 // INITIALIZE ADC

  do {
    Read = ADC_Get_Sample(2);   // Get 10-bit results of AD conversion
    Adc_value = Read;
    FloatToStr(Adc_value,Adc_txt); //Convert float to string
    Adc_txt[4] = 0;
    Lcd_Out(1,1,"ADC VAL:");
    Lcd_Out(1,10,Adc_txt);
    delay_ms(300);
  } while(1);
}



Post a Comment

0 Comments

Ad Code

Responsive Advertisement