It is always a mystery to beginner to use ADC on CC2530/CC2541. Here, I post how to use TI Z-Stack/BLE Stack API to read ADC value on CC2530/CC2541. I hope this post can help anyone who struggles on CC2530/CC2541 ADC usage. In the followings, I show how to use P0_2 as ADC input, HAL_ADC_REF_125V as reference voltage, and HAL_ADC_RESOLUTION_10, HAL_ADC_RESOLUTION_12, HAL_ADC_RESOLUTION_14 as ADC resolution respectively.
1. Read ADC value from P0_2 using HAL_ADC_REF_125V as reference voltage and HAL_ADC_RESOLUTION_10 as ADC resolution.
uint16 adc_ain2=0;
HalAdcSetReference(HAL_ADC_REF_125V);
adc_ain2=HalAdcRead(HAL_ADC_CHN_AIN2,HAL_ADC_RESOLUTION_10);
The max measurable voltage of P0_2 is 1.15 because I am using HAL_ADC_REF_125V as reference voltage here. If the input voltage is larger than 1.15V, the ADC reading adc_ain2 will be always 511. If I connect P0_2 to 0.5V, I will have ADC reading adc_ain2=223. Then, we can convert the reading 223 to measured voltage using the following equation.
measured voltage = 1.15x223/511=0.501...
2. If I change HAL_ADC_RESOLUTION_12 (the max reading is 2047) as ADC resolution and connect P0_2 to 0.5V, I will have ADC reading adc_ain2=886. Then, we can convert the reading 889 to measured voltage using the following equation.
measured voltage = 1.15x889/2047=0.499...
3. If I change HAL_ADC_RESOLUTION_14 (the max reading is 8191) as
ADC resolution and connect P0_2 to 0.5V, I will have ADC reading
adc_ain2=3550. Then, we can convert the reading 3550 to measured voltage
using the following equation.
measured voltage = 1.15x3550/8191=0.498...
Thanks! This helped me.
ReplyDeleteThanks! This helped me.
ReplyDeleteShould this be in the main() loop inside the while or plrase suggest the exact location for the same.
ReplyDeleteThanks great share