I am attemting to measure voltage of the battery with channel 2. (The GND_ON bit is set to zero).
The problem is I always read zeros.
All other channels (including channel 1, when GND_ON is set to 1) work perfectly. So I guess my configuration and usage of the register is ok.
The voltage is much less than VDD_ANA.
Any ideas ?
Thanks.
My code is :
// Set SAR clock dividor. Clock must be maximum 2 Mhz CSL_SAR_REGS->SARCLKCTRL = (DSP_SYSTEM_CLOCK_MHZ / 2) + 20; // Set GPAIN 2 and 3 to GP output CSL_SAR_REGS->SARGPOCTRL = 0xC0;
if (chanNo == 1)
{ CSL_SAR_REGS->SARPINCTRL = /*0x3600;*/0x3602; } else if (chanNo == 2) { CSL_SAR_REGS->SARPINCTRL = 0x3600; } else { CSL_SAR_REGS->SARPINCTRL = 0x3600; } for(i=0;i<100;i++); Uint16 x = 30; while (x > 0) { // Start Single Conversion CSL_SAR_REGS->SARCTRL = 0x8000 | (chanNo << 12) | 0x400 ;//| 0x800; for(i=0;i<1000;i++); readBuffer = *sarDataRegister; /* Read the ADC data continously 40 times */ while((readBuffer & 0x8000) == 0x1000) { readBuffer = *sarDataRegister; } // Extract the converted data (clear other flags). readBuffer = readBuffer & 0x3FF; x--; } CSL_SAR_REGS->SARPINCTRL = 0;