cancel
Showing results for 
Search instead for 
Did you mean: 

2 x PWM with DMA

slawek
Associate III
Posted on July 04, 2018 at 22:56

I am doing now small project with STM32F0. I would like to generate two PWM signals simultaneously using DMA. Everything is working fine if I am starting one of two PWM Generators. When I start two works only first one. Is there a way to make this PWM generation simultaneous on two channels?

Code simply looks like this:

    HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_1, buf1, 6);

    HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_4, buf2, 6);
1 REPLY 1
slawek
Associate III

It is possible, but to start another PWM need a lot of time to wait after first PWM is started, so you need to wait even hundreds of ms, so you need to check the PWM state, e.g.

         while( HAL_TIM_STATE_READY != HAL_TIM_PWM_GetState( &htim3))

         {

            HAL_Delay(100);

         }

         HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_1, _u16PWMTabServo[0], SERVO_POSITIONS);

         while( HAL_TIM_STATE_READY != HAL_TIM_PWM_GetState( &htim3))

         {

            HAL_Delay(100);

         }

         HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_4, _u16PWMTabServo[1], SERVO_POSITIONS);