cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L475RC glitch in fixed timer PWM

Electronic1
Associate II

Hello,

I have a power converter device controlled by a STM32L475RC. One part of the control requires a constant PWM of 70kHz of 300ns (Ton).

Although this pwm is never modified,and doesn't use interrupts or DMA modules, periodically it produces a glitch in its output (like in attached image). Specially when there is high noise of power conversion.

I suppose that another peripheral is producing this error, but I can't figure out which one. (Another timer?, a I2C by DMA communication?,...)

Any one has ever seen some similar, and know which is the cause?

Thanks in advance

/* TIM8 init function */

void MX_TIM8_Init(void)

{

 /* USER CODE BEGIN TIM8_Init 0 */

 /* USER CODE END TIM8_Init 0 */

 TIM_MasterConfigTypeDef sMasterConfig = {0};

 TIM_OC_InitTypeDef sConfigOC = {0};

 TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};

 /* USER CODE BEGIN TIM8_Init 1 */

 /* USER CODE END TIM8_Init 1 */

 htim8.Instance = TIM8;

 htim8.Init.Prescaler = 0;

 htim8.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim8.Init.Period = 1143;

 htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim8.Init.RepetitionCounter = 0;

 htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

 if (HAL_TIM_PWM_Init(&htim8) != HAL_OK)

 {

   Error_Handler();

 }

 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

 sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;

 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

 if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)

 {

   Error_Handler();

 }

 sConfigOC.OCMode = TIM_OCMODE_PWM1;

 sConfigOC.Pulse = 24;

 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

 sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;

 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

 sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;

 sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;

 if (HAL_TIM_PWM_ConfigChannel(&htim8, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)

 {

   Error_Handler();

 }

 sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;

 sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;

 sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;

 sBreakDeadTimeConfig.DeadTime = 0;

 sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;

 sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;

 sBreakDeadTimeConfig.BreakFilter = 0;

 sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;

 sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;

 sBreakDeadTimeConfig.Break2Filter = 0;

 sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;

 if (HAL_TIMEx_ConfigBreakDeadTime(&htim8, &sBreakDeadTimeConfig) != HAL_OK)

 {

   Error_Handler();

 }

 /* USER CODE BEGIN TIM8_Init 2 */

 /* USER CODE END TIM8_Init 2 */

 HAL_TIM_MspPostInit(&htim8);

}

// 70KHz (Ton 300ns)

HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_1);

11 REPLIES 11
Electronic1
Associate II

After more proves I have discovered that disconnecting the JTAG improves the stability of PWM outputs. Probably because my Jtag wasn't isolated

But I still lose some pulses.

Maybe I should improve the immunity for this microcontroller, anyone could recommend me how to improve it? Or where I could found information related?

For reducing the effect of a high frequency converter commuting near the microcontroller?

It makes sense that long wires would act as an antenna and exacerbate the issue.

Are you using HSE as a clock source? Does it happen with HSI as a clock source as well? Any chance you could share the layout?

> Maybe I should improve the immunity for this microcontroller, anyone could recommend me how to improve it? 

It very much depends on the source of the noise. It may be more effective to shield the source than to shield the STM32. There are some general tips here:

https://www.st.com/resource/en/application_note/cd00004479-emc-design-guide-for-stm8-stm32-and-legacy-mcus-stmicroelectronics.pdf

If you feel a post has answered your question, please click "Accept as Solution".