Skip to main content
Electronic1
Associate III
August 7, 2021
Question

STM32L475RC glitch in fixed timer PWM

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);

This topic has been closed for replies.

11 replies

Electronic1
Associate III
August 7, 2021

Hi again,

I have been following my research and I can add that during these "glitch time" there is an uncontrolled drop of some ports like gpio A 1. Although there hadn't been any microcontroller reset detected

MM..1
Super User
August 7, 2021

Dont your code use STOP mode?

Electronic1
Associate III
August 7, 2021

No, I am just using Run mode, in our application low power modes aren't required.

TDK
August 7, 2021

I would guess your chip is resetting. The spikes do not line up as they would if the timer were not being interrupted.

> Specially when there is high noise of power conversion.

What does this mean exactly?

"If you feel a post has answered your question, please click ""Accept as Solution""."
Electronic1
Associate III
August 7, 2021

I can confirm that chip is not resetting.

>Specially when there is high noise of power conversion.

This refers to electromagnetic noise produced by power converter. As the power converter produces more power the magnetic devices increase the noise they produce,

And in this situation more pulses of this PWM output are lost

TDK
August 7, 2021

Not sure. I don't see what else would interrupt the counter besides a reset. Although a reset only taking ~6us would be very quick. Maybe take a look at the power rail and ensure that is sufficiently stable.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
August 7, 2021

> I can confirm that chip is not resetting.

How?

JW

Electronic1
Associate III
August 7, 2021

A reset proces would imply a restore of the state machine, which would imply long waits and ports would follow up all the initialization process.

Electronic1
Associate III
August 7, 2021

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?

TDK
August 8, 2021

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""."