Code:
void analogReadRes(unsigned int bits)
{
// if (bits > 16) bits = 16;
// analog_right_shift = 16 - bits;
// TODO: actually reconfigure A/D for desired resolution
/*
ADC0_CFG1 bits 3-2 set the number of bits in the ADC result.
For single ended:
00 = 8 bits
01 = 12 bits
10 = 10 bits
11 = 16 bits
*/
switch (bits) {
case 8:
ADC0_CFG1 |= 0;
break;
case 12:
ADC0_CFG1 |= 4;
break;
case 16:
ADC0_CFG1 |= 12;
break;
default:
ADC0_CFG1 |= 8;
}
}