Skip to main content
NSemrHomeInit
Associate III
January 20, 2021
Question

How to trigger an ADC using the PWM timer at the beginning of the period.

  • January 20, 2021
  • 1 reply
  • 674 views

Hello,

I want to trig the ADC using the PWM timer,

The ADC would be triggered in the first event of the PWM "counter start".

How to wait for the ending conversion using a while loop in the PWM isr.

Could I read the ADC without using the DMA bus?

I am using the CubMx.

Thank you in advance,

S.Tarik

This topic has been closed for replies.

1 reply

ST Technical Moderator
February 4, 2021

Hello @NSemrHomeInit​ ,

Generally with the while loop, you can do the polling technique.

Other possibility is to use the ADC EOC interrupt.

Here is one of example in the HAL within STM32CubeF4: STM32Cube_FW_F4_V1.25.2\Projects\STM324x9I_EVAL\Examples\ADC\ADC_RegularConversion_Polling

 /*##-3- Start the conversion process #######################################*/ 
 if(HAL_ADC_Start(&AdcHandle) != HAL_OK)
 {
 /* Start Conversation Error */
 Error_Handler();
 }
 
 /*##-4- Wait for the end of conversion #####################################*/ 
 /* Before starting a new conversion, you need to check the current state of 
 the peripheral; if it’s busy you need to wait for the end of current
 conversion before starting a new one.
 For simplicity reasons, this example is just waiting till the end of the 
 conversion, but application may perform other tasks while conversion 
 operation is ongoing. */
 HAL_ADC_PollForConversion(&AdcHandle, 10);
 
 /* Check if the continuous conversion of regular channel is finished */
 if((HAL_ADC_GetState(&AdcHandle) & HAL_ADC_STATE_EOC_REG) == HAL_ADC_STATE_EOC_REG)
 {
 /*##-5- Get the converted value of regular channel ######################*/
 uhADCxConvertedValue = HAL_ADC_GetValue(&AdcHandle);
 }
 
 /* Infinite loop */
 while(1)
 {
 }

I hope this helps !

Please mark my answer as best by clicking on the "Select as Best" button if it fully solved your issue. This will help other users find this solution more quickly.

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks