cancel
Showing results for 
Search instead for 
Did you mean: 

TIM8 STM32H745 PWM mode 1

eadboston
Associate

eadboston_0-1736199838299.png

eadboston_1-1736199886380.png

I am using the STM32H745i_DISCO board. I can't seem to get TIM8 to output on PK0. I sure the GPIO is be setup correctly, but there must be something in one of the TIM8 registers. I am attempting to use TIM8 to adjust the brightness on the LCD screen, but again can't seem make the timer output anything. I can see activity within the Timer8 upon debug. The counter register is working.

eadboston_2-1736200071656.png

static void MX_TIM8_Init(void)

{

 

/* USER CODE BEGIN TIM8_Init 0 */

 

/* USER CODE END TIM8_Init 0 */

 

TIM_ClockConfigTypeDef sClockSourceConfig = {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 = 1199;

htim8.Init.CounterMode = TIM_COUNTERMODE_UP;

htim8.Init.Period = 65535;

htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim8.Init.RepetitionCounter = 0;

htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

if (HAL_TIM_Base_Init(&htim8) != HAL_OK)

{

Error_Handler();

}

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)

{

Error_Handler();

}

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 = 0;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;

sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;

sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;

if (HAL_TIM_PWM_ConfigChannel(&htim8, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)

{

Error_Handler();

}

__HAL_TIM_DISABLE_OCxPRELOAD(&htim8, TIM_CHANNEL_3);

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

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

 

}

 

 

void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

if(htim->Instance==TIM8)

{

/* USER CODE BEGIN TIM8_MspPostInit 0 */

 

/* USER CODE END TIM8_MspPostInit 0 */

 

__HAL_RCC_GPIOK_CLK_ENABLE();

/**TIM8 GPIO Configuration

PK0 ------> TIM8_CH3

*/

GPIO_InitStruct.Pin = GPIO_PIN_0;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

GPIO_InitStruct.Alternate = GPIO_AF3_TIM8;

HAL_GPIO_Init(GPIOK, &GPIO_InitStruct);

 

/* USER CODE BEGIN TIM8_MspPostInit 1 */

 

/* USER CODE END TIM8_MspPostInit 1 */

}

 

code in main.c

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_MDMA_Init();

MX_FMC_Init();

MX_LTDC_Init();

MX_CRC_Init();

MX_DMA2D_Init();

MX_JPEG_Init();

MX_QUADSPI_Init();

MX_TIM8_Init();

MX_TouchGFX_Init();

/* Call PreOsInit function */

MX_TouchGFX_PreOSInit();

/* USER CODE BEGIN 2 */

 

 

HAL_TIM_Base_Start(&htim8);

 

 

 

 

2 REPLIES 2
TDK
Guru

> HAL_TIM_Base_Start(&htim8);

This only starts the timer, not the PWM output. Should be calling HAL_TIM_PWM_Start to start the PWM signal on a channel.

See an example here:

STM32CubeH7/Projects/NUCLEO-H743ZI/Examples/TIM/TIM_PWMOutput/Src/main.c at 95f919d70044baedcc321df07c75ae1b962ee7af · STMicroelectronics/STM32CubeH7

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

In terms of registers content, TIM8_CCER.CC3E is zero. Presumably, the function @TDK mentioned above, would set it.

Interestingly TIM8_BDTR.MOE=1. Obviously, I don't use Cube/HAL.

JW