cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_ADC_ConvCpltCallback to FreeRtos

Mat1
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

2 REPLIES 2

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

Mat1
Associate III

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