cancel
Showing results for 
Search instead for 
Did you mean: 

how to config ADC conversion to be aligned with Timer comparator edges?

ausera uirwaij
Associate III

Hi, I'm doing motor drive project using F429. I want to achieve ADC triggered by PWM edges and generate interrupt to deal with ADC results, Timer 1 is counting-up mode, so How to configure related registers?

ADC triggered at one (only one at one timer period) of falling edge of T1's CC1 , CC2 and CC3, as a result, CC1 +CC2+CC3 trigger ADC in turns.

Thank you in advance.

3 REPLIES 3

I don't understand the problem description. Try to draw a timing diagram, indicating the observed behaviour and also the expected one. You may also want to read out and check/post TIM and ADC registers content.

JW

ausera uirwaij
Associate III

Hi, thanks for your kind reply.

the frequency of Timer 1 is 10khz, its CC1+CC2+CC3 comparators output complementary PWMs, CC4 is configured to be some value equal to CC1~CC3, using CC4 falling event to trigger ADC ,then read out ADC registers (or transfer DR register by DMA) and do filtering operation at the end of conversion.

*********************************************************

this is ADC interrupt handler:

*********************************************************

0693W00000FDzgsQAD.png

this ADC interrupt hits Line 750 three times during one TIMER1 period, however, I just want one hit at LINE 750 after ADC sampling which triggered by T1 CC4​ event.

this is part of my init function :

/* ADC2 init function */

void MX_ADC2_Init(void)

{

 ADC_ChannelConfTypeDef sConfig = {0};

 ADC_InjectionConfTypeDef sConfigInjected = {0};

 hadc2.Instance = ADC2;

 hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV6;

 hadc2.Init.Resolution = ADC_RESOLUTION_12B;

 hadc2.Init.ScanConvMode = DISABLE;     

 hadc2.Init.ContinuousConvMode = ENABLE;   

 hadc2.Init.DiscontinuousConvMode = DISABLE;

 hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;

 hadc2.Init.NbrOfConversion = 1;

 hadc2.Init.DMAContinuousRequests = ENABLE;

 hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;

//  hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

// hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;

 if (HAL_ADC_Init(&hadc2) != HAL_OK)

 {

  Error_Handler();

 }

 sConfig.Channel = ADC_CHANNEL_10;

 sConfig.Rank = 1;

 sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES;

 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 sConfigInjected.InjectedChannel = ADC_CHANNEL_10;

 sConfigInjected.InjectedRank = 1;

 sConfigInjected.InjectedNbrOfConversion = 1;

 sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_3CYCLES;

 sConfigInjected.AutoInjectedConv = ENABLE;

 sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;

 sConfigInjected.InjectedOffset = 0;

sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONVEDGE_FALLING;

sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T1_CC4;

 if (HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected) != HAL_OK)

 {

  Error_Handler();

 }

HAL_ADCEx_InjectedStart_IT(&hadc2); 

__HAL_ADC_DISABLE_IT(&hadc2, ADC_IT_JEOC);

HAL_ADC_Start_DMA(&hadc2,(uint32_t *)u16ADC2_Buf,ADC2_NUM_MAX);

}