Topic

FAQ
Login Register
How can I read multiple AD ports simultaneously or sequentially? (8258 BLE)
Sep 16, 2022 07:26

/

A

/A


Hello~

I have a qeustion.


In the example code "telink mesh _ sdk",
In the "light.h" file within the "light8258" project,

I have verified that if "ADC_SET_CHN_ENABLE" is set to 1, the ADC value of GPIO_PB4 is programmed to be read.


But I want to read other ports besides that.


Which part should I modify to read simultaneously or sequentially?
Is it possible to read only one port at a time on the 8258?


As a simple example, if I have to read the AD values of "PB0" and "PB1", can I process them in the main loop as shown below?
I wonder if the code below is the right way.


main()
{
adc_init();
adc_base_init(GPIO_PB0);
adc_power_on_sar_adc(1);
base_PB0_Ad_val = adc_sample_and_get_result();


adc_init();
adc_base_init(GPIO_PB1);
adc_power_on_sar_adc(1);
base_PB0_Ad_val = adc_sample_and_get_result();
}


2 replies
TL_Soyo Sep 16, 2022 10:17
1
/A

Hi,

  it can read only one port at a time,


just for reference.


u8 flag =0;

adc_init();

adc_base_init(GPIO_PB1);

adc_power_on_sar_adc(1);

loop()

{

if( flag ==0)

{

base_PB1_Ad_val = adc_sample_and_get_result();

adc_power_on_sar_adc(0);//stop adc

adc_base_init(GPIO_PB0);

adc_power_on_sar_adc(1);//start adc

flag  =1;

}

else

{

base_PB0_Ad_val = adc_sample_and_get_result();

adc_power_on_sar_adc(0);//stop adc

adc_base_init(GPIO_PB1);
adc_power_on_sar_adc(1);

flag = 0

}

}


wooseok [Author] Sep 16, 2022 19:41
0
/A




thank you. soyo