cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446RE - 10KHz -PWM- TIM1 -STM32cubeide

Murali3252
Associate

I Have coded my STM32F446RE for 10KHz PWM using TIM1 In STM32cubeide.

 

i am getting pulse but the pk-pk voltage is not 3.3v it is around 150mv.

need help.

 

Code :

 

 

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_DMA_Init();

MX_TIM1_Init();

/* USER CODE BEGIN 2 */

 

TIM1->CCR1 = 50;

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);

 

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

 

/**

* @brief System Clock Configuration

* @retval None

*/

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 

/** Configure the main internal regulator output voltage

*/

__HAL_RCC_PWR_CLK_ENABLE();

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

 

/** Initializes the RCC Oscillators according to the specified parameters

* in the RCC_OscInitTypeDef structure.

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLM = 15;

RCC_OscInitStruct.PLL.PLLN = 60;

RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

RCC_OscInitStruct.PLL.PLLQ = 2;

RCC_OscInitStruct.PLL.PLLR = 2;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

 

attached scope pic:

IMG20240413224003.jpg

1 REPLY 1
nouirakh
ST Employee

Hello @Murali3252 

By testing a few examples for the STM32F446RE, I have tried to reproduce the issue.
For example TIM_PWMInput, It uses the TIM to measure the frequency and duty cycle of an external signal. As in your code 10KHz PWM using TIM1, I have modified the code to suit the configurations, and I am getting a pk-pk voltage of around 6 volts, Ampl around 3.3 volts.
You can generate an example for the TIM using CubeMX or check the STM32F4 firmware package to verify your code. It may also be a wires problem. 

Attached pic for oscilloscope visualisation:

oscilloscope visualisation.jpg