Skip to main content
Rob1
Associate II
June 27, 2018
Question

STM32F051 adc interrupt problem. Multiple channels.

  • June 27, 2018
  • 1 reply
  • 728 views
Posted on June 27, 2018 at 09:27

STM32F051 ADC sample 5 channels with interrupt.

I'm trying to sample 5 channels using an interrupt. (I'll get to DMA later:0))

If I set the sample time to ('ADC_SAMPLETIME_41CYCLES_5') or longer then the code works as expected.

Every interrupt I check the ('ADC_FLAG_EOC') flag , if set ,  store the adc result in an array and increment the array index. After 5 conversions the ('ADC_FLAG_EOS') flag is also set. Then reset the array index and process the data in the array.

If I set the sample time to less than the above , the ('ADC_FLAG_EOS') flag is set after only 3 conversions!!

If I set the sample time to ('ADC_SAMPLETIME_7CYCLES_5') , the ADC interrupt never fires.

What could be going on here. I understand that having a small sample time could affect the accuracy of the result , but why is it changing the behavior of the system?

I can post the code if required , but maybe someone has a quick answer

:)

Cheers

Rob

    This topic has been closed for replies.

    1 reply

    Rob1
    Rob1Author
    Associate II
    June 27, 2018
    Posted on June 27, 2018 at 12:38

    Some info to add to the question.

    If I make the ADC clock ('ADC_CLOCK_SYNC_PCLK_DIV4') , then I can set the sample time to a minimum of 

    ('ADC_SAMPLETIME_41CYCLES_5').

    If the ADC clock is set to 

     ('

    ADC_CLOCK_SYNC_PCLK_DIV2')

      , then the minimum sample time is ('ADC_SAMPLETIME_239CYCLES_5').

    If ADC clock is set to 14Mhz RC ('ADC_CLOCK_ASYNC_DIV1') , then the minimum sample time is 

    ('

    ADC_SAMPLETIME_239CYCLES_5').

    Any sample time shorter than these values and the ADC stops working correctly or at all.

    It looks like some sort of timing issue , but I can't figure out what it could be. ADC is only triggered (by software)

    every 10mS.