ADC of Xc167

Hello

Port 5 is not responding.
I have set the compatibility mode for regiseter.
at P5.6 and P5.8 is a voltage of 2.5 V created
I read from P5.6 and P5.8 a voltage.
The function does not work as I expect.
I expect to P5.6 ADC_DAT = 0x63FF read at 5V
or ADC_DAT = 0x6000 at 0V
But, I get at 5V or 0V the same result ADC_DAT = 0x6202
And I dont know how I read the voltage from the P5.6 or P5.8
I must set other register when I chose compatibilty mode ??

Thanks for Your Help



#include <xc167.h>
#include <intrins.h>
#include <XC16X.h>


void init ();
int AD_Strom_messung (int kanal);

unsigned int Strom_Wert,Strom1,Strom2;
int kanal;
.
.
.

void main (){      {
init ();
.
.
.
while(1)
 {
Strom2 = AD_Strom_messung (6); // read P5.6 ====> 15F
Strom1 = AD_Strom_messung (8); // read der P5.5 ====> 15E

}//end of while
}//end of main
.
.
int AD_Strom_messung (int kanal){

 ADC_CON = kanal + 0x0080 ;      // Select Channel und start Conversion


 do {

 }while (ADC_CON & 0x0100);// wait of end Conversion
Strom_Wert = ADC_DAT & 1023 ;//read ADRES of ADC_DAT
return Strom_Wert;
 }


void init ()
   {
ADC_CON1 = 0x0104 ;
P5DIDIS  = 0xFFFF ;
   }

Parents
  • Perhaps you are running into this issue that is described as a hint in the errata sheet.

    ADC_X.H1 Polling of Bit ADBSY
    After an A/D conversion is started (standard conversion by setting bit ADST = 1, injected conversion by setting ADCRQ = 1), flag ADBSY is set 5 clock cycles later. When polling for the end of a conversion, it is therefore recommended to check e.g. the interrupt request flags ADC_CIC_IR (for standard conversions) or ADC_EIC_IR (for injected conversions) instead of ADBSY.

    Perhaps you could change your code to something like this and see if you have the same result?

    #include <xc167.h>
    
    unsigned int Strom_Wert;
    unsigned int Strom1;
    unsigned int Strom2;
    
    void init () {
      ADC_CON1 = 0x0104 ;
      P5DIDIS  = 0xFFFF ;
    }
    
    int AD_Strom_messung (int kanal){
      ADC_CIC_IR = 0;
      ADC_CON = kanal + 0x0080 ;    // Select Channel und start Conversion
    
      do {
      }while (ADC_CIC_IR == 0);     // wait of end Conversion
      Strom_Wert = ADC_DAT & 1023;  // read ADRES of ADC_DAT
      return Strom_Wert;
     }
    
    void main(void) {
      init();
    
      while(1)
      {
        Strom2 = AD_Strom_messung (6); // read P5.6 ====> 15F
        Strom1 = AD_Strom_messung (8); // read der P5.5 ====> 15E
      }//end of while
    }//end of main
    

Reply
  • Perhaps you are running into this issue that is described as a hint in the errata sheet.

    ADC_X.H1 Polling of Bit ADBSY
    After an A/D conversion is started (standard conversion by setting bit ADST = 1, injected conversion by setting ADCRQ = 1), flag ADBSY is set 5 clock cycles later. When polling for the end of a conversion, it is therefore recommended to check e.g. the interrupt request flags ADC_CIC_IR (for standard conversions) or ADC_EIC_IR (for injected conversions) instead of ADBSY.

    Perhaps you could change your code to something like this and see if you have the same result?

    #include <xc167.h>
    
    unsigned int Strom_Wert;
    unsigned int Strom1;
    unsigned int Strom2;
    
    void init () {
      ADC_CON1 = 0x0104 ;
      P5DIDIS  = 0xFFFF ;
    }
    
    int AD_Strom_messung (int kanal){
      ADC_CIC_IR = 0;
      ADC_CON = kanal + 0x0080 ;    // Select Channel und start Conversion
    
      do {
      }while (ADC_CIC_IR == 0);     // wait of end Conversion
      Strom_Wert = ADC_DAT & 1023;  // read ADRES of ADC_DAT
      return Strom_Wert;
     }
    
    void main(void) {
      init();
    
      while(1)
      {
        Strom2 = AD_Strom_messung (6); // read P5.6 ====> 15F
        Strom1 = AD_Strom_messung (8); // read der P5.5 ====> 15E
      }//end of while
    }//end of main
    

Children
More questions in this forum