cancel
Showing results for 
Search instead for 
Did you mean: 

PWM signal generation with DMA through two channle there is not getting same pahse square wave

thannara123
Senior

Hello  ,  am using stm32f411 nucleo board.

 

uint32_t sin_table[2] = {

150, 250, 100}

HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)sin_table, 3)

HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_2, (uint32_t *)sin_table, 3);

I am giving this value to the ccr register

In PA8 and PA9 pin getting these PWM signal for the channel 1 and channel 2 corresspondily 

but the square wave is not exact phase some phase shift why so ?

Screenshot 2024-07-22 at 10.13.44 PM.png

please help me ?

2 REPLIES 2
Bob S
Principal

Probably because of the time it takes the HAL_TIM_PWM_Start_DMA() call to actually start the timer.  If you want both timers to start at exactly the same time you need to configure them to start from a common trigger source.  If you just need them "closer" but not exact, write your own "start" code that writes the final "enable" bit to the two times on two adjacent lines of code.

The result is bizarre in that the first channel runs to some form of effective disable (setting CCRx above ARR) before the second is started, and vice versa. Maybe consequence of declaring sin_table to have 2 elements and then use 3 for the DMA (i.e. it uses something "random" beyond the table).

I don't recommend trying to salvage the above code. To change both channels simultaneously by DMA, you should use the DMAR/DCR mechanism. It may be clickable in CubeMX, but I don't use Cube.

JW