cancel
Showing results for 
Search instead for 
Did you mean: 

HAL Tick and PWM on TIM1

JBenn.1
Associate II

Hello,

We use the CubeIDE generator for most of the code initialization. Therefore the HAL is also inizalized.

The function HAL_Init(); is executed and TIM1 is started.

The Hal ticks work fine.

Now I want to use the Chanel 1 of Timer1 for a PWM signal on PA8. (STM32F767ZIT)

We use the following code:

void initTftBacklightDimming(void){
 
	TIM_HandleTypeDef htim1;
	htim1.Instance = TIM1;
 
	TIM_OC_InitTypeDef sConfigOC = {0};
	sConfigOC.OCMode       = TIM_OCMODE_PWM1;
	sConfigOC.Pulse        = 100;
	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();
	}
 
	GPIO_InitTypeDef GPIO_InitStruct = {0};
	if(htim->Instance==TIM1)
	{
		__HAL_RCC_GPIOA_CLK_ENABLE();
		
		/**TIM1 GPIO Configuration
		PA8     ------> TIM1_CH1
		*/
		GPIO_InitStruct.Pin = GPIO_PIN_8;
		GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
		GPIO_InitStruct.Pull = GPIO_NOPULL;
		GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
		GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
		HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
	}
  
	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
}

Unfortunately I have no signal on the PB8 pin.

Does anyone know why it is failing?

4 REPLIES 4
Imen GH
ST Employee

Hello @JBenn.1​,

You can get inspiration from the TIM example (under the folder Projects in the firmware package).

So, I recommend you to have a look to the example under STM32Cube directory:

STM32Cube\Repository\ STM32Cube_FW_F7_V1.16.0\Projects\STM32F769I_EVAL\Examples\TIM\TIM_7PWMOutput

This example runs on STM32F767xx/STM32F769xx/STM32F777xx/STM32F779xx devices.

You can compare your files with the mentioned example. 

Imen

> Now I want to use the Chanel 1 of Timer1 for a PWM signal on PB8.

There is no TIM1_CH1 on PB8.

Your code appears to set PA8.

> Unfortunately I have no signal on the PB8 pin.

If you have measured on PA8 and still no signal, maybe you haven't set TIM1_BDCR.MOE.

JW

TDK
Guru

Also possible your duty cycle is 0% or 100% and you misinterpret the DC signal for no output.

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

Thanks for the hint.

I now have a PWM signal. :grinning_face:

However, freeRTOS makes me problems, which uses the same timer as SysTick.