I'm having an issue with using the ADC in the CC2540. I'm trying to read values from an external sensor using a modified version of the simple profile. The sensor outputs a voltage in the range of 0v to 2.5v. However I'm finding that I get no reading from the ADC until the output of the sensor passes ~950mV. I'm assuming that the value should actually be a proportion of the voltage between 0v and AVDD (as configured in my code) but this doesn't seem to be happening. Could anyone suggest why this is the case?
My code is given below. The actual device I'm working on is the the BLE112 breakout board and the sensor has three wires - VSS (connected to pin 3), Sense (connected to pin 26) and GND (connected to pin 30) (http://goo.gl/YaQRq)
static void performPeriodicTask( void ) { uint16 adc; uint8 valueArray[2]; HalAdcSetReference( HAL_ADC_REF_AVDD ); //HalAdcSetReference( HAL_ADC_REF_125V ); adc = HalAdcRead( HAL_ADC_CHN_AIN2, HAL_ADC_RESOLUTION_12 ); valueArray[0] = HI_UINT16(adc); valueArray[1] = LO_UINT16(adc); /* * Call to set that value of the load characteristic in the profile. Note * that if notifications of the load characteristic have been enabled by * a GATT client device, then a notification will be sent every time this * function is called. */ Loadcell_SetParameter( LOADCELL_LOAD, LOADCELL_LOAD_LEN, &valueArray); }
EDIT: Upon further investigation it turns out that this voltage is recognised by the ADC upon exceeding 1.2V or so.
Input Volts ADC Value 1.158V 00:0A. 1.337V 02:B5 (increase of 683 decimal) 1.519V 03:32 (increase of 125 decimal)
All other increases after this are approx ~120. Hence from the looks of things the ADC isn't updating correctly until a certain voltage is present (rather than just not seeing this voltage)