Skip to main content
MChoi.5
Associate
September 12, 2018
Question

How to get the values from multi channels using one ADC block

  • September 12, 2018
  • 2 replies
  • 1132 views

Hi,

I am trying to get two voltages using two channels with one ADC block.​

My MUC is STM32F103RB. The followings are configruation of ADC and my program code.

0690X000006C0sFQAS.jpg

HAL_ADC_Start(&hadc2);

for(;;) {

ret = HAL_ADC_PollForConversion(&hadc2, 100);

if(ret == HAL_OK) {

val = HAL_ADC_GetValue(&hadc2);

}

else {

val = 0;

}

printf("#1: %ld\r\n", val1);

ret = HAL_ADC_PollForConversion(&hadc2, 100);

if(ret == HAL_OK) {

val = HAL_ADC_GetValue(&hadc2);

}

else {

val = 0;

}

printf("#2: %ld\r\n", val2);

}

Since the 3.3V line was connected to #1 and #2 was not connected, I expected the values ​​of #1 to be about 4000 and #2 to be about 2800.

However, the actual result is either the values ​​of # 1 and # 2 appear to be opposite to each other, or they represent the same value.

0690X000006C0sKQAS.jpg

I'd like to know what I should do.

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    September 12, 2018

    You should use DMA to place into an array, then use the DMA HT or TC in place of the ADC EOC

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    MChoi.5
    MChoi.5Author
    Associate
    September 12, 2018

    My program has several tasks based on FreeRTOS(9.0.0) and CMSIS(1.02). After start the ADC using HAL_ADC_Start_DMA(), other tasks are not worked. Should any other functions be used?