Skip to main content
Graduate II
March 29, 2024
Solved

ADC multichannel using Interrupt

  • March 29, 2024
  • 1 reply
  • 10132 views

I have 3 potentiometers, one on each channel of the ADC, that vary 3V. The ADC reads the values and converts to voltage.

I have not been able by reading the datasheet and looking at some examples online to figure out how to get it to work using interrupts (with DMA it works).

I attach the entire project, can you kindly check it?

 

Thanks!

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello,

    I looked at your software and indeed that's normal because you're in interrupt mode.

    In each conversion you need to read ADC_DR register which common to all channels conversion. So every interrupt will be refreshed by the conversion of the next channel that will overwrite the previous one. Your implementation doesn't seem good.

    In DMA mode, the DMA manages this automatically and it's triggered automatically by the ADC for each conversion and increments the memory (when configured by the user) to write to the correct memory location.

    So in interrupt mode you need to select to trigger the ADC interrupt at each end of conversion not all channel conversions and in the callback (HAL_ADC_ConvCpltCallback) read the  ADC_DR register for each conversion to unsure that you are reading the correct channel.

    I modified your example on which I read the 4 channels: 3 internal ADC channels and one external. I'm reading them one by one in this order:

    1. Temp sensor
    2. Vrefint
    3. VBAT
    4. CHANNEL1 (PA0)

    SofLit_1-1711816121324.png

    I used F4-Discovery board for this.

    Hope it helps.

    Please close this thread on this reply if it does answer your question.

    1 reply

    Technical Moderator
    March 29, 2024

    Hello,

    I see in your code that the ADC trigger is set to TIM1 CC1 while TIM1 is not configured at all.

    SofLit_0-1711733429539.png

    SofLit_1-1711733494107.png

    Could you please double check or at least test with "Conversion launched by Software"?

    luke514Author
    Graduate II
    March 29, 2024

    You are right. By setting "Conversion launched by Software" all 3 channels read the same thing .. so I think the problem is with the code in the main.c

    Being unfamiliar with ADC, if I use "Conversion launched by Software" what should I change in the main.c? What API should I use?

    Technical Moderator
    March 29, 2024

    what do you mean by « all 3 channels read the same thing »?