cancel
Showing results for 
Search instead for 
Did you mean: 

DMA burst mode dont work correctly

eqbal
Associate II

I want to generate an arbitrary wave form on channel1 and channel2 of timer1. I use dma burst mode and other:

MCU: STM32f401CCU6

Frequency: 84 Mhz

TIM1 PSC: 84-1

TIM1 Counter Mode: Center aligned mode 1

TIM1 RCR: 1

TIM1 ARR: 1000

TIM1 frequency is 500 and the array of values is:

uint32_t levels[] = {

50, 100, 150, 100, 250, 100, 350, 100, 450, 100, 550, 100, 650, 100, 750, 100, 850, 100, 950, 100

};

the first one is CCR1 and second one is CCR2, it circular and has 10 value for each channel

I use DMA burst, Setting is:

0693W00000AP05BQAT.jpg 

and TIM1 start command is:

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);

 HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);

 HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);

 HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);

 HAL_TIM_DMABurst_MultiWriteStart(&htim1, TIM_DMABASE_PCR, TIM_DMA_UPDATE, (uint32_t*)levels, TIM_DMABURSTLENGTH_2TRANSFERS, 20);

every thing is OK, except last duty cycle, the output wave form is:

0693W00000AP05kQAD.gifit must be like this:

0693W00000AP06TQAT.gifWhat is the problem? Why the last Section is not correct?

3 REPLIES 3

Take that waveform and draw into it the "triangle" representing TIMx_CNT going down and up. Then mark, where does the repetition counter count to 0 - that's the point where te CCRx registers reload. IMO that happens when CNT=0, i.e. in the middle of the pulse. That's why you see the last longest pulse cut to half.

There's probably no simple remedy for this, the center-aligned mode is simply tricky.Maybe the simplest way is to set RCR=0 and account for the fact that update happens boh at overflow and underflow by doubling every value in the table in RAM.

JW

eqbal
Associate II

Thanks a lot

Thanks for your help