cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with polling ADC scan mode

David Martins
Senior
Posted on August 10, 2016 at 17:26

Hello.

I have some troubles with ADC scan mode... For example:

while (1)
{
uint32_t adc;
HAL_StatusTypeDef err;
HAL_ADC_Start(&hadc1);
for (int i = 0; i < 9; i++)
{
err = HAL_ADC_PollForConversion(&hadc1, 1000);
if (err != HAL_OK)
HAL_Delay(50);
adc = (uint16_t) HAL_ADC_GetValue(&hadc1);
#if (TEST_PRINTS_ADC == 1)
memset(TEST_PRINT, 0, TEST_LENGHT);
sprintf(TEST_PRINT, ''ADC CH%d - %5lu\r\n'', i, adc);
HAL_UART_Transmit(&huart3, (uint8_t*)TEST_PRINT, strlen(TEST_PRINT), 1000);
#endif
}
HAL_ADC_Stop(&hadc1);
}

All pins are configured and ordered in scan rank. In result I have 2 good convertions and the following gives timeout error. Does anyone have any clue what might be happening? https://postimg.org/image/v2rv4661n/ Thank you. #adc #single-scan #!stm32
6 REPLIES 6
Posted on August 10, 2016 at 17:45

Most STM32 parts expect the use of DMA when scanning ADC channels.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
David Martins
Senior
Posted on August 10, 2016 at 17:58

So... I can not use the scan mode with polling?

David Martins
Senior
Posted on August 10, 2016 at 18:22

It is strange to me can not do the scan with polling....

1.2 Multichannel (scan), single conversion mode

http://www.st.com/content/ccc/resource/technical/document/application_note/c4/63/a9/f4/ae/f2/48/5d/CD00258017.pdf/files/CD00258017.pdf/jcr:content/translations/en.CD00258017.pdf

David Martins
Senior
Posted on August 10, 2016 at 18:40

I dont understand...

This should work.

Why do I get timeout errors?

Posted on August 10, 2016 at 19:14

So... I can not use the scan mode with polling?

 

 

You can try, I'm trying to save you wasting your time.

It is strange to me can not do the scan with polling....

Seems strange to me that people burn 100's of cycles spinning in do-nothing loops too, but to each their own.

Why do I get timeout errors?

You spend 1000's of cycles outputting to a USART for conversions that take a dozen or so cycles a piece. I think the ADC has out run you.

The scan method is designed around having DMA fill an array with a complete set of conversions and giving you a TC signal in place of a dozen EOCs

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
David Martins
Senior
Posted on August 10, 2016 at 19:33

OK.

I get it ... I was thinking about the scan mode differently.

I will try to use DMA ...