This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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
  • Not sure.

    If the ADC is working for one channel but not the other then chances are that it is not the ADC setup.

    When you perform the conversion on channel 8 do you see 8 in the upper nibble of the ADC_DAT register indicating that the converter did indeed convert this channel? Are you sure you are on channel 8's input of the device and its connection is good? If the input of the ADC channel 8 is open (not connected) you should get a result around 2.5V (since the ADC charges the internal sample capacitor to half the voltage before a conversion is performed).


    Strom1 = 0x02AA = 3.333V
    Strom2 = 0x0292 = 3.216V

Reply
  • Not sure.

    If the ADC is working for one channel but not the other then chances are that it is not the ADC setup.

    When you perform the conversion on channel 8 do you see 8 in the upper nibble of the ADC_DAT register indicating that the converter did indeed convert this channel? Are you sure you are on channel 8's input of the device and its connection is good? If the input of the ADC channel 8 is open (not connected) you should get a result around 2.5V (since the ADC charges the internal sample capacitor to half the voltage before a conversion is performed).


    Strom1 = 0x02AA = 3.333V
    Strom2 = 0x0292 = 3.216V

Children
  • hello
    what do you mean about (is not the ADC setup !!!)
    yes when i debug .,i see 8 in the upper nibble or 6 .
    i have cheked the connection .its good
    the Problem is
    i change the voltage (0V.......4,5V) in P5.8 or P5.6
    und i got same Result .
    hier is what i see in debugg with voltage und without

    ADC_CON    =   0x0006
    ADC_CON1   =   0x0104
    ADC_DAT    =   0x6292
    Strom1     =   0x0292
    Strom2     =   0x0295
    Strom_Wert =   0x0292
    ADC_CIC    =   0x0080
    

    thanks for your help