Skip to main content
thannara123
Associate III
November 2, 2023
Question

Trying to make a PWM (2 channel + 2 Channel Complimentory) by using DMA

  • November 2, 2023
  • 1 reply
  • 1151 views

I am trying to make a pwm signal ,with Lookup table for duty cyle .

Here using TIM1 of stm32nucleoF070.

I am here using DMA ,reffered a lot of from google and just worte as follows 

 

No variying singal is getting 

SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_DMA_Init();
 MX_TIM1_Init();
 /* USER CODE BEGIN 2 */

 HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)sin_table, 32);
 HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_2, (uint32_t *)sin_table, 32);
 HAL_TIM_Base_Start_IT(&htim1);
 HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1);
 HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_1);
 HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_2);
 HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_2);


 /* USER CODE END 2 */

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */

	 HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
			 	 	 	 HAL_Delay(80);
//

 }

is it correct way , 

any help is appriciated 

 

This topic has been closed for replies.

1 reply

Pierre_Paris
ST Employee
November 13, 2023

Hello @thannara123,

Thank you for your question !

Here are some remark:

  • Why are you casting "sin_table" ? My advise is to declare this array as an uint32_t and to delete the cast.
  • When you call the HAL_TIM_PWM_Start_DMA(), you start the PWM signal generation in DMA mode. Also, it's better to call it that way :

 

 if (HAL_TIM_PWM_Start_DMA(&TimHandle, TIM_CHANNEL_3, aCCValue_Buffer, 3) != HAL_OK)
 {
 /* Starting Error */
 Error_Handler();
 }​

 

  • You cannot call line 15-19 and start in interrupt mode, you started in DMA mode just before...
  • Have you consider the CubeFW example on TIM under the root "STM32Cube_FW_F0_V1.11.0\Projects\STM32F070RB-Nucleo\Examples\TIM" ? You can download the zip here.

Best Regards,

Pierre

 

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.