cancel
Showing results for 
Search instead for 
Did you mean: 

Harmonics are present on Idle State TIM1 Channel 1 One pulse Mode How to remove them ?

DPatr.2
Associate III

Using STM32F429ZIT6 - Nucleo

Here's what I observe on PE9. Counter Mode is upcounting, PWM Mode 2

0693W00000KbJYuQAN.jpg0693W00000KbJYVQA3.jpg0693W00000KbJXrQAN.jpg0693W00000KbJXNQA3.jpg 

At first, I thought there had conflicts in the parameters (OCMode, OCPolarity and OCIdleState) of MX_TIM1_Init() function

static void MX_TIM1_Init(void)
{
 
  /* USER CODE BEGIN TIM1_Init 0 */
 
  /* USER CODE END TIM1_Init 0 */
 
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_SlaveConfigTypeDef sSlaveConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};
  TIM_OC_InitTypeDef sConfigOC = {0};
  TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
 
  /* USER CODE BEGIN TIM1_Init 1 */
 
  /* USER CODE END TIM1_Init 1 */
  htim1.Instance = TIM1;
  htim1.Init.Prescaler = 0;
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim1.Init.Period = 451;
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim1.Init.RepetitionCounter = 0;
  htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_TIM_OnePulse_Init(&htim1, TIM_OPMODE_SINGLE) != HAL_OK)
  {
    Error_Handler();
  }
  sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
  sSlaveConfig.InputTrigger = TIM_TS_ITR1;
  if (HAL_TIM_SlaveConfigSynchro(&htim1, &sSlaveConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sConfigOC.OCMode = TIM_OCMODE_PWM2;
  sConfigOC.Pulse = 1;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
  sConfigOC.OCNPolarity = TIM_OCNPOLARITY_LOW;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  sConfigOC.OCIdleState = TIM_OCIDLESTATE_SET;	
  sConfigOC.OCNIdleState = TIM_OCIDLESTATE_SET;	
  if (HAL_TIM_PWM_ConfigChannel(&htim1, &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.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
  if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM1_Init 2 */
  //	sConfigOC.OCMode = TIM_OCMODE_PWM1;	//Actice High trigger pulse
  //	sConfigOC.OCMode = TIM_OCMODE_PWM2;	//Actice Low trigger pulse
  //TIM1 Clock input is 180 MHz, period = 5.555 ns
  //TIM1_CCR1 = 1 	(sConfigOC.Pulse = 1;)
  //TIM1_ARR = 451	(htim1.Init.Period = 451;)
  //Delay to generate pulse = 1 * 5.555 ns = 5.555ns
  //Pulse width = (451-1)*5.555ns = 2.5 us
  /* USER CODE END TIM1_Init 2 */
  HAL_TIM_MspPostInit(&htim1);
 
}

But after checking documentation, I think thoses are fine!?

0693W00000KbJalQAF.png 

Not sure what is causing the issue, any Ideas ?

If you need whole main.c, don't hesitate to ask.

4 REPLIES 4
KnarfB
Principal III

Digital signals have (theoretically) infinite steep edges, so harmonics are always present. That's something analog, not digital. If you care about RF emission, you may select the pin speed (driver strength) according to the frequencies you're expecting.

hth

KnarfB

Which STM32? What hardware?

This looks more like interference/improper ground etc.

Set the pin as Output in GPIO_MODER and try different OSPEEDR settings.

Also try on a "known good" board such as Nucleo or Disco (after having disconnected all potential on-board circuitry connected to given pin).

JW

This was observed on STM32F429ZIT6 - Nucleo board which should be a "known good" board.

My oscilloscope has sampling probe on a wire going in D6 (PE9) and reference probe on GND Pin 5 of CN10. I dont think its improper ground.

0693W00000KbKNsQAN.png 

Do you mean electromagnetic interference ? I dont see any source around me that could generate this frequency.

I poked 3V3 line on CN8 Pin 7 and 5V line CN8 Pin 9 and here's what I observed ;

3V3 CN8 Pin 7

0693W00000KbKUyQAN.jpg 

5V CN8 Pin 9 0693W00000KbKVIQA3.jpg 

Maybe I damaged the on board regulator or filtering capacitor on power lines with an ESD ?

DPatr.2
Associate III

I poked U5V on R12 that is the 5V source coming from my USB port

0693W00000KbKrOQAV.png 

and I observed the same ripples. It looks like that is root cause and the solution would be to have a cleaner (less ripples) power source.