cancel
Showing results for 
Search instead for 
Did you mean: 

800KHz Frequency generation using STM32G070RBT6

Preetpal
Visitor

I am trying to get 800KHz frequency with Timer 3 and timer clock is 64MHz and i am using below setting to initalize the timer, but its frequency is 666.66KHz. Pls provide a solution of this problem ASAP......

 

static void MX_TIM3_Init(void)

{



/* USER CODE BEGIN TIM3_Init 0 */



/* USER CODE END TIM3_Init 0 */



TIM_ClockConfigTypeDef sClockSourceConfig = {0};

TIM_MasterConfigTypeDef sMasterConfig = {0};

TIM_OC_InitTypeDef sConfigOC = {0};



/* USER CODE BEGIN TIM3_Init 1 */



/* USER CODE END TIM3_Init 1 */

htim3.Instance = TIM3;

htim3.Init.Prescaler = 0;

htim3.Init.CounterMode = TIM_COUNTERMODE_UP;

htim3.Init.Period = 79;

htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

if (HAL_TIM_Base_Init(&htim3) != HAL_OK)

{

Error_Handler();

}

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

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

{

Error_Handler();

}

if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)

{

Error_Handler();

}

sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

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

{

Error_Handler();

}

sConfigOC.OCMode = TIM_OCMODE_PWM1;

sConfigOC.Pulse = 0;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;

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

{

Error_Handler();

}

/* USER CODE BEGIN TIM3_Init 2 */



/* USER CODE END TIM3_Init 2 */

HAL_TIM_MspPostInit(&htim3);



}
2 REPLIES 2
TDK
Guru

This is quantization error in your logic analyzer. Increase your sampling rate to max or take the average of many different periods.

The timer settings and the output frequency are correct--look at the long term trend.

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

Hello,

there should be set sConfigOC.Pulse value to non zero value to generate PWM on output pin. Try to set

sConfigOC.Pulse = 39;

 (50 % duty cycle).

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.