Skip to main content
sshan.2
Associate III
January 13, 2023
Question

STM32G431 Break input for PWMs

  • January 13, 2023
  • 4 replies
  • 1977 views

I am generating two PWMs with TIM1 CH1 and CH2 .I want to stop the PWMs when Break input is present. I have configured the STM32 Break input in the STM32cubeIDE and able to stop the PWMs when Break input is HIGH(3.3v).

I needed the reverse way now like when Break input is GND(0v) No PWMs .I have changed the Digital input polarity -Low and Break Polarity -Low but No luck .

Please suggest any ideas on this ??

This topic has been closed for replies.

4 replies

Javier1
Principal
January 13, 2023

Could you post some code or the CubeMX file?

Did you spotted this in the cubeMX config window already?

0693W00000Y8BjiQAF.png 

source

hit me up in https://www.linkedin.com/in/javiermuñoz/
sshan.2
sshan.2Author
Associate III
January 16, 2023

Hi Javier,

Yes I did the changes as you mentioned in the screen shot in the STMCubeIDE.below is the code

 htim1.Instance = TIM1;

 htim1.Init.Prescaler = 0;

 htim1.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED1;

 htim1.Init.Period = PERIOD;

 htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim1.Init.RepetitionCounter = 0;

 htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

 if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)

 {

  Error_Handler();

 }

 sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC2REF;

 sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;

 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

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

 {

  Error_Handler();

 }

 sBreakInputConfig.Source = TIM_BREAKINPUTSOURCE_BKIN;

 sBreakInputConfig.Enable = TIM_BREAKINPUTSOURCE_ENABLE;

 sBreakInputConfig.Polarity = TIM_BREAKINPUTSOURCE_POLARITY_LOW;

 if (HAL_TIMEx_ConfigBreakInput(&htim1, TIM_BREAKINPUT_BRK, &sBreakInputConfig) != HAL_OK)

 {

  Error_Handler();

 }

 sConfigOC.OCMode = TIM_OCMODE_PWM1;

 sConfigOC.Pulse = DUTY_CYCLE;

 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(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)

 {

  Error_Handler();

 }

 sConfigOC.Pulse = PERIOD-DUTY_CYCLE;

 sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;

 if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != 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_ENABLE;

 sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_LOW;

 sBreakDeadTimeConfig.BreakFilter = 0;

 sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT;

 sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;

 sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;

 sBreakDeadTimeConfig.Break2Filter = 0;

 sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT;

 sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;

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

 {

  Error_Handler();

 }

Javier1
Principal
January 16, 2023

could you share the cubeMX .ioc file?

hit me up in https://www.linkedin.com/in/javiermuñoz/
sshan.2
sshan.2Author
Associate III
January 16, 2023