Hi guys,
I am attempting to do a single ended sequence reading of the first 2 ADC channels without DMA. I have my ADCCON1 [5:4] set to 11. I have an event set to 10sec where i read the latest ADC value from the channels. I get the correct reading for the second channel but not the first channel. i keep on getting a constant value for the first channel even with changing input. Can someone help me out. below is my code.
uint8 i = 0;
uint16 Tempsensor;
uint16 sensorRH;
uint16 TrueRH;
uint16 Tempsensorsend;
uint8 Vsupply = 33;
static uint16 adc_data[3];
APCFG = 0x03; // set first four channels as analog input
/*
* ADC configuration :
* - Continous mode
* - Single-ended sequence conversion
* - Reference Voltage is the internal reference voltage
* - 12 bit resolution (512 dec rate)
*/
ADCCON2 = 0x33; // internal reference,first four channels and 12 bits(512 ENOB)
// Set [ADCCON1.STSEL] to continues conversion.
ADCCON1 = 0x73;
/* ADC conversion :
* The ADC will run in continous mode until disabled.
// Stop continuous mode.
*/
//ADCCON1 |= ADCCON1_ST;
for ( i=0; i<3; i++)
{
adc_data[i]= (int16) (ADCL);
adc_data[i] |= (int16) (ADCH << 8);
// normalize the result
if(adc_data[i] < 0) adc_data[i] = 0;
// The results are in two's complement form and the value is not converted to signed.
adc_data[i] = (adc_data[i] >> 4) & 0x0FFF;
//processing sensor data from both sensors
sensorRH = ((CONSTANT * adc_data[0])/(0.00636 * Vsupply/10)) - 23.8208 ; // commerial humidity sensor in percentage
TrueRH = (sensorRH)/(1.0546 - (0.00216 * Tempsensor));
Tempsensor = (((CONSTANT * adc_data[1]) - 500)/10); // commercial temperature sensor in degrees celcius
Tempsensorsend = Tempsensor * 100; // commercial temperature sensor in degrees celcius
}
AT_DBG("ADC_0(hum) = %d",adc_data[0]);
AT_DBG("ADC_1(temp) = %d",adc_data[1]);
AT_DBG("Tempsensor = %d", Tempsensor);
AT_DBG("sensorRH = %d", sensorRH);
AT_DBG("TrueRH = %d", TrueRH);
if (channel == 1)
{
return (Tempsensor);
}
else if (channel ==2)
{
return (sensorRH);
}
return 0;
}
if (events & ADC_READ_EVT)
{
get1_adc_value(channel);
}
Thank You.