Spread the love

ADC of PIC18F458 ___________________________________________________________________________________________________

  • What is ADC ? – An analog-to-digital converter (abbreviated ADC, A/D or A to D) is a device that converts a continuous physical quantity (usually voltage) to a digital number that represents the quantity’s amplitude.

ADC of PIC18F458

  • How ADC work – Most real world data is in analog form. Whether it be temperature, pressure, voltage, etc, their variation is always analog in nature..so we have to convert this analog data into digital format so that computer or microcontroller can understand it and process on it. Sensor gives analog data in form of variation in current and voltage, ADC read this variation and process a digital data according to analog input and send to microcontroller to process it further.
  • Terms used in ADC
  • Resolution – The resolution of the converter indicates the number of discrete values it can produce over the range of analog values. A computer is a digital machine that stores a number in binary. If you are storing a digital 2-bit number you can store 4 different values: 00, 01, 10, or 11. Now, you can say ADC have 2-bit resolution and you have a device which converts an analog voltage between 0 and 10 volts into a 2-bit digital value for storage in a computer. This device will give digital values as follows :

Voltage

2-Bit Digital Representation

0 to 2.5

00

2.5 to 5

01

5 to 7.5

10

7.5 to 10

11

Higher the resolution smaller the step size Smaller the step size better accuracy

  • Step size – small amount of change in analog input that can understand for example 8-bit ADC, step size=Vref/2^8 = Vref/256 Vref – used to detect step size
  • Conversion – Dout=Vinput/(step size) Dout – decimal output digital data Vinput – analog input voltage For example – for 8 bit ADC, Vref = 2.56 V, calculate digital output for 1.7 V input. step size=(2.56 V)/256=10 mV Dout=(1.7 V)/(10 mV)=170=10101010
  • Feature of ADC in ATmega32
  • 10bit ADC inbuilt
  • 8 analog input channel (ADC0 to ADC7 = PORTA)
  • 7 differential channel input
  • 2 different input channel with gain of 10X and 200X
  • 3 option of Vref 1). internal 2.56 V 2). AVcc (pin 30) 3). AREFF (pin 32)

2_19_6_1_eng

  • Applications– used to read analog input data from sensor in our application.

Click Here : Program point of view understanding of ADC

1. CIRCUIT DIAGRAM OF ADC of  PIC18F458  WITH LCD AND VARIABLE RESISTANCE 

CIRCUIT DIAGRAM OF ADC of  PIC18F458  WITH LCD AND VARIABLE RESISTANCE    ________________________________________________________________________________________________

1. PROGRAM OF ADC OF PIC18F407  DATA IS DISPLAYED ON LCD CONNECTED 

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- ADC DATA IS DISPLAYED ON LCD CONNECTED WITH PIC18F458
******************************************************/

/* header file used in this program is already included in software microC pro for pic*/

#define lcd PORTD     // data of lcd at port d
#define rs portc.f5     // rs pin at 5 pin of portc
#define rw portc.f6     // rw pin at 6 pin of portc
#define en portc.f7     // en pin at 7 pin of portc

void delay();     // for delay
void cmd(unsigned char);       // lcd in command mode
void display(unsigned char);   // lcd is in display mode
int lcd_pos(int x,int y);
void lcd_str(unsigned char *);
void lcd_ini();
void dec_hex(unsigned long);
unsigned long int adc_re();


void main()
   {
       TRISC=0X00;
       TRISD=0X00;
       TRISA.TRISA0=0;
       ADCON0=0X81;
       ADCON1=0XCE;
       lcd_ini();
       lcd_str("VALUE OF ADC IS");
       while(1)
        {
           dec_hex(adc_re());
           delay_ms(300);

        }
    }

unsigned long adc_re()
   {
      float x;
      ADCON0.GO=1;
      while(ADCON0.DONE==1);
      x=ADRES;
      return x;
   }
   
void cmd(unsigned char x)
   {
       unsigned char i;
       lcd=x;
       rs=0;
       rw=0;
       en=1;
       for(i=0;i<2;i++);
       en=0;
       delay();
    }
    
void display(unsigned char x)
  {
      unsigned char i;
      lcd=x;
      rs=1;
      rw=0;
      en=1;
      for(i=0;i<2;i++);
      en=0;
      delay();
  }
  
void delay()
  {
     unsigned int i,j;
     for(i=0;i<100;i++)
     for(j=0;j<153;j++);
  }

int lcd_pos(int x,int y)
   {
      if(x==0)
           cmd(0x80+y);
      else if(x==1)
           cmd(0xc0+y);
   }
   
void lcd_str(unsigned char *x)
   {
     while(*x!='\0')
       {
           display(*x);
           x++;
       }
   }

void lcd_ini()
  {
     cmd(0x38);
     cmd(0x0e);
     cmd(0x01);
     cmd(0x06);
     cmd(0x80);
  }
   
void dec_hex(unsigned long temp)
   {
                unsigned char first,second,third,fourth;

                first=temp%10+'0';
                temp=temp/10;
                second=temp%10+'0';
                temp=temp/10;
                third=temp%10+'0';
                temp=temp/10;
                fourth=temp%10+'0';
                temp=temp/10+'0';
                lcd_pos(1,0);
                lcd_str("    ");
                 lcd_pos(1,0);
                display(fourth);
                display(third);
                display(second);
                display(first);
  }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

_____________________________________________________________________________________________

Content for the tab VIDEO