Skip to main content
Explorer II
June 28, 2023
Solved

HAL_ADC_ConvCpltCallback to FreeRtos

  • June 28, 2023
  • 2 replies
  • 2014 views

Hi,

I use the ADC with DMA. The adc conversion is triggered with 20kHz.

I would like to transfer my 4 adc values from interrupt HAL_ADC_ConvCpltCallback to a FreeRtos task.

What is the best way to transfer adc values from HAL_ADC_ConvCpltCallback to FreeRtos task?

Are there examples which I should check?

I read about binary semaphores, queues.

Thanks

    This topic has been closed for replies.
    Best answer by Andrei Chichak

    What I do is use the circular buffer mode on the ADC DMA, and use the HAL_ADC_ConvHalfCpltCallback as well as the HAL_ADC_ConvCpltCallback. In each of these callbacks I use xTaskNotifyFromISR to send a message back to my ADC task, either HALF_DONE or ALL_DONE.

    The ADC task waits on a xTaskNotifyWait, and depending on which message it gets, processes one half of the DMA block or the other.

    In my case I have a timer triggering conversions at 200Hz., so I have 5ms to process the ADC conversions before the next tranche becomes available. In your case you will have 50us to process 4 values. If you swamp the system with interrupts, you might want to have the DMA fire after, say, 100 sets of 4 values (if you're averaging to reduce ADC noise), thereby giving yourself 5ms to process 400 values.

    A

    2 replies

    Graduate II
    June 29, 2023

    What I do is use the circular buffer mode on the ADC DMA, and use the HAL_ADC_ConvHalfCpltCallback as well as the HAL_ADC_ConvCpltCallback. In each of these callbacks I use xTaskNotifyFromISR to send a message back to my ADC task, either HALF_DONE or ALL_DONE.

    The ADC task waits on a xTaskNotifyWait, and depending on which message it gets, processes one half of the DMA block or the other.

    In my case I have a timer triggering conversions at 200Hz., so I have 5ms to process the ADC conversions before the next tranche becomes available. In your case you will have 50us to process 4 values. If you swamp the system with interrupts, you might want to have the DMA fire after, say, 100 sets of 4 values (if you're averaging to reduce ADC noise), thereby giving yourself 5ms to process 400 values.

    A

    Mat1Author
    Explorer II
    June 30, 2023

    Hi Andrei, Thanks a lot to share your approach. I will test it on my setup.