 | Discussion Forum |  |
|
|
ADC of Xc167Next Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author A S Posted 21-Nov-2008 11:19 GMT Toolset C166 |  ADC of Xc167 A S 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 ;
}
| | Read-Only Author Chris Wunderlich Posted 21-Nov-2008 15:13 GMT Toolset C166 |  RE: ADC of Xc167 Chris Wunderlich 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
| | Read-Only Author A S Posted 21-Nov-2008 15:44 GMT Toolset C166 |  RE: ADC of Xc167 A S Thank you for your quick response I've changed my code and I have P5.6 to a voltage applied 3v and P5.8 nothing I still get: Strom1 = 0x02AA Strom2 = 0x0292 this is not correct what could be the reason !!!!!
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
| | Read-Only Author Chris Wunderlich Posted 21-Nov-2008 19:04 GMT Toolset C166 |  RE: ADC of Xc167 Chris Wunderlich 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
| | Read-Only Author A S Posted 21-Nov-2008 19:56 GMT Toolset C166 |  RE: ADC of Xc167 A S 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 | |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|