Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F72A ADC Not reading

Status
Not open for further replies.

thannara123

Advanced Member level 5
Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,602
Helped
122
Reputation
244
Reaction score
116
Trophy points
1,353
Activity points
10,615
I am trying to read ADC value from AN0 pin of Pic16F72A but not reading the ADC below the cod e what is the problem
Am using interrupt meathod
C:
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#include"lcd.h"
#include<stdio.h>

#define _XTAL_FREQ 1600000
unsigned int  adc;


 __interrupt isr()
{
     if(ADIF==1)
        {
         adc = ADRES;
         GO_DONE = 1;
              
        }
}
    
    

void adc_initilize()
{  ADCON0 = 0x81; // 32 Tosc 7 ADC ON
   ADCON1 = 0x05; // all input makes analog input
   ADIE=1; //Enables the ADC interrupt
   ADIF=0; //clear the A/D Converter Interrupt interrupt flag
   __delay_us(40);
    
  
}
     void main(void) 
    {    unsigned char buffer[8];
         OPTION_REG &= 0x7F;
         TRISB =0x00; 
         TRISA=0x01;// for adc first channel as input
         unsigned int i; 
         TRISB =0x00;
         GIE =1;
         PEIE = 1; 
         LCD_init();
         adc_initilize();
         LINE1;     
         string("  ADC");
         LINE2;
         string("Stuck Here1");
         LINE1;
          
        
       while(1)
               { 
                    //  ADCON0 = ADCON0|(0X04); // ADC starting GO/DONE Bit setting
                    GO_DONE = 1;           
                    LINE1;
                    string("ADC Reading");                   
                    LINE2;                   
                    sprintf(buffer,"%d",adc);
       }
      }

Whener the GO_DONE = 1; works the ADC stuck .
what is the problem please help me
 

Hi,

".. but not reading the ADC .. " is no information at all.

--> Give details about:
* how you tested it
* what results you expect
* and what you see instead

Klaus
 

C:
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#include"lcd.h"
#include<stdio.h>

#define _XTAL_FREQ 1600000
unsigned int  adc;


 __interrupt isr()
{
     if(ADIF==1)
        {
         adc = ADRES;
         ADIF = 0;
         GO_DONE = 1;
        
              
        }
}
    
    

void adc_initilize()
{  ADCON0 = 0x81; // 32 Tosc 7 ADC ON
   ADCON1 = 0x05; // all input makes analog input
   ADIE=1; //Enables the ADC interrupt
   ADIF=0; //clear the A/D Converter Interrupt interrupt flag
   __delay_us(40);
    
  
}
     void main(void) 
    {    unsigned char buffer[8];
         OPTION_REG &= 0x7F;
         TRISB =0x00; 
         TRISA=0x01;// for adc first channel as input
         unsigned int i; 
         TRISB =0x00;
         GIE =1;
         PEIE = 1; 
         ADIE = 1;                  // Enable ADC interrupt
         LCD_init();
         adc_initilize();
         LINE1;     
         string("  ADC");
         LINE2;
         //string("Stuck Here1");
         LINE1;
          
        
       while(1)
               { 
                    //  ADCON0 = ADCON0|(0X04); // ADC starting GO/DONE Bit setting
                    GO_DONE = 1;           
                    LINE1;
                    string("ADC Reading");                   
                    LINE2; 
                   sprintf(buffer,"%d",adc);
                   string(buffer);
       }
      }
Sorry trail and error Code posted first some of data missed

1.jpg
 

ADCON0 | = 0X05; // ADC starting GO/DONE Bit setting
GO_DONE = 1;
__delay_ms(10);
while(1)
{
}
Nothing Happend .i havent debuger is there any other problem .
 

Your code structure is still wrong. I think you only ant to display the ADC reading after a conversion is finished, you try to display it continuously in the while() loop. I think you should set a variable in the ISR to say the conversion is finished then use it to display the result then reset it. If you want continuous readings, restart the ADC only when the display is finished.

Other points:
Setting ADCON1 to 0x05 makes RA0 and RA1 analog inputs, RA2 and RA5 digital inputs and RA3 the ADC reference input. You do not have RA3 connected. I suspect you want it set to 0x04.

Set the GIE bit after the other interrupt enable bits and as a separate instruction.

Not essential, but good practice is to check both ADIF and ADIE are enabled in the ISR, it will avoid any pending interrupt occurring until you have initialized the other registers.

Brian.
 

    thannara123

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top