Skip to main content
Davorin
Associate III
June 25, 2020
Question

TIM1 Chan1 PWM, no output, GPIO works fine

  • June 25, 2020
  • 3 replies
  • 1390 views

Good afternoon

Configured TIM1 of a F070CBT6 to drive 3 PWM channels on PA8/PA) and PA10....

PA9 and PA10 work fine..only for channel 1 I don't see any output..furthermore it seems to be floating as when touching with a finger the attached 7406 driver turns the LED on...

OTOH when using PA8 as a general GPIO output, it works just fine to turn LED on/off...

Timer1 channel 1 output broken?

static void MX_TIM1_Init(void)
{
 
 /* USER CODE BEGIN TIM1_Init 0 */
 
 /* USER CODE END TIM1_Init 0 */
 
 TIM_ClockConfigTypeDef sClockSourceConfig = {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 = 48000-1;
 htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
 htim1.Init.Period = 1000-1;
 htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 htim1.Init.RepetitionCounter = 0;
 htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
 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();
 }
 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
 if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
 {
 Error_Handler();
 }
 sConfigOC.OCMode = TIM_OCMODE_PWM1;
 sConfigOC.Pulse = 0;
 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();
 }
 if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
 {
 Error_Handler();
 }
 if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != 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 */
 
 /* USER CODE END TIM1_Init 2 */
 HAL_TIM_MspPostInit(&htim1);
 
}

This topic has been closed for replies.

3 replies

TDK
June 25, 2020

Check HAL_TIM_MspPostInit() to ensure pins are initialized as AF correctly.

Failing that, look at GPIO registers to see how PA8 is configured.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Davorin
DavorinAuthor
Associate III
June 25, 2020

Hmm..okay....

Just discovered that TIM1 channel 2 and channel 3 also behave differently when freshly programmed via J-Link or after a power-up...

After programming it seems that the counter value set is inverted...(short dark LED phase) where as after reset I see short LED on pulses as it should be...

Didn't had this on the Nucleo-F070 board...

waclawek.jan
Super User
June 25, 2020

Set PA8 as GPIO Out and wiggle - works? (aiming at bad solder joint).

Read our and check/post the relevant GPIO and TIM registers content.

JW

Davorin
DavorinAuthor
Associate III
June 25, 2020

Yes...pin toggling works as mentioned before...

Also in pwm mode when I set a pull-down...the output isn't floating anymore...so LED doesn't light up when touching the PA8 pin...

Gotta check tomorrow more..already late here in \.ch (o;

TDK
June 25, 2020

> Also in pwm mode when I set a pull-down...the output isn't floating anymore

In PWM output mode, the pin is either set to low or high. A pulldown shouldn't be affecting it.

Edit: unless maybe it's floating during the break dead time? Not sure, but I doubt it.

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