Learn MoreFAQsTutorials

6 posts / 0 new
Last post
Jasu
Offline
Last seen:1 year 10 months ago
加入:2019-01-23 10:26
ADC

I want to read an analog value using gpio pin?how to read this analog value using adc?do you have any example code for adc reading?

Device:
PM_Dialog
Offline
Last seen:5 hours 7 min ago
工作人员
加入:2018-02-08 11:03
嗨Jasu,

嗨Jasu,

Please check the ADC example which is located under projects\target_apps\peripheral_examples\adc\batt_lvl SDK path and you will find all the appropriate steps for the usage of the ADC.

Thanks, PM_Dialog

Jasu
Offline
Last seen:1 year 10 months ago
加入:2019-01-23 10:26
YES I LOOKED AT THAT EXAMPLE

YES I LOOKED AT THAT EXAMPLE BUT THAT DOESN'T READ ANY VALUE FROM GPIO

PM_Dialog
Offline
Last seen:5 hours 7 min ago
工作人员
加入:2018-02-08 11:03
嗨Jasu,

嗨Jasu,

In order to read an ADC value for a GPIO, you should reserve and configure the GPIO as PID_ADC. For example:

  • In GPIO_reservation(): RESERVE_GPIO( ADC, ADC_PORT, ADC_PIN, PID_ADC);
  • In set_pad_function(): GPIO_ConfigurePin( ADC_PORT, ADC_PIN, INPUT, PID_ADC, false);

Be aware that you could use specific GPIO as an ADC. Please check Table 1: Pin Description of the DA14585 datasheet and search the “Analog Interface” section. After that, you should use the appropriate APIs from the ADC library, but we don’t have any available example on this.

Thanks, PM_Dialog

Jasu
Offline
Last seen:1 year 10 months ago
加入:2019-01-23 10:26
i reserved and configure the

i reserved and configure the GPIO .but i cannot understand how to read adc value from gpio(adc) pin!!

PM_Dialog
Offline
Last seen:5 hours 7 min ago
工作人员
加入:2018-02-08 11:03
嗨Jasu,

嗨Jasu,

The ADC example of the SDK gets sample from VBAT1V or VBAT3V power supplies using the 20 usec delay. Please check the adc_get_vbat_sample() :

  • 如果sample_vbat1v= TRUE, then the adc_enable_channel(ADC_CHANNEL_VBAT1V)
  • 如果sample_vbat1v= FALSE, then the adc_enable_channel(ADC_CHANNEL_VBAT3V)

This means that according the sample_vbat1v, the ADC is configured to gets samples either from VBAT1V or VBAT3V. Both ADC_CHANNEL_VBAT1V and ADC_CHANNEL_VBAT3V are defined into adc.h header file. Suppose that you would like to get samples from Pin_00, so you have to enable it first. A sample code for that is the following:

adc_calibrate();

adc_init(GP_ADC_SE,GP_ADC_SIGN,0);

adc_usDelay(20);

adc_enable_channel(ADC_CHANNEL_P00);

adc_value = adc_get_sample();

Thanks, PM_Dialog