Skip to main content
slawek
Associate III
July 4, 2018
Question

2 x PWM with DMA

  • July 4, 2018
  • 1 reply
  • 1779 views
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);
    This topic has been closed for replies.

    1 reply

    slawek
    slawekAuthor
    Associate III
    January 23, 2019

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