Other Parts Discussed in Thread: CC2541, CC2538
Hello
I am currently trying to get the battery monitor working with CC2541 (sensor tag). The problem is that when POWER_SAVING is defined, the adc returns usually a static reading regardless of the VDD. However when the define is removed it works just fine. I pasted the code i used to read the values from adc below.
I have not found anything in the manuals or guides that says the ad converter cannot work if the power savings macro is used. However i presume that the problem lies with the clock management during the conversion. Any help is appreciated.
void HalMyAdcRead(void)
{
uint32 calib = *(uint8 *)0x7826<<7; // value from info page
calib <<= 1;
calib |= *(uint8 *)0x7827;
calib *= 100; //for accuracy, to be divided out later
//read adc value
ADCCON2 = 0x3F; //12 bits resolution, internal ref, channel = vdd/3
ADCCON1 = 0x73; //start conversion
while(!(ADCCON1 & 0x80)); //wait for conversion
v = ADCL; //read adc value
v |= (((uint16) ADCH) << 8);
v = 30000* v / calib; // 3 (ideal voltage) * 1000 (for accuracy) * v (adc reading) / calib
battery = (uint16) v;
}