2023-06-28 12:37 AM
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
Solved! Go to Solution.
2023-06-29 11:47 AM - edited 2023-06-29 11:54 AM
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
2023-06-29 11:47 AM - edited 2023-06-29 11:54 AM
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
2023-06-29 10:54 PM
Hi Andrei, Thanks a lot to share your approach. I will test it on my setup.