2021-05-19 11:12 PM
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:
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:
it must be like this:
What is the problem? Why the last Section is not correct?
2021-05-20 12:18 AM
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
2021-05-20 05:43 AM
Thanks a lot
2021-05-20 05:43 AM
Thanks for your help