PWM + DMA + 100% PWM duty bug, duplicated cycle
MCU: STM32F411CEU6.
IDE: STM32CUBE IDE 1.5.1
Timer1 config:
PWM generation mode, CH1+CH2
No prescaler, Period=549, Repetition counter = 8
DMA: Circular mode, memory->periph, halfword, mem increase CH1+CH2
PWM start code:
// Ensure 32-bit alignment just in case DMA doesn't like it.
// This Works
__attribute__((aligned(4))) volatile uint16_t PWM_CH1_Data[2] = { 0, 547 };
__attribute__((aligned(4))) volatile uint16_t PWM_CH2_Data[4] = { 0, 100, 200, 547 };
// PWM Duty Higher than (PWM period - 2 ) causes the bug.
// __attribute__((aligned(4))) volatile uint16_t PWM_CH1_Data[2] = { 0, 548 };
void main(void){
// ... HAL initialization, etc
// ...
// Start PWM CH1
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t*)&PWM_CH1_Data[0], 2);
// PWM seems to stay busy until the next DMA transfer happens (or repetition counter resets).
while (HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_2, (uint32_t*)&PWM_CH2_Data[0], 4) == HAL_BUSY){
asm("nop");
}
// Both PWM channels running
while(1);The PWM works nicely unless the PWM duty is set higher than 547.
Setting it to 548 duplicates the cycle. In this case, the whole repetition counter cycle (9 PWM cycles).
Being the Period 549, I don't understand the problem.
If I'm correct, the repetition counter gets the clock from the timer over/underflow?
So the output compare signal doesn't matter. The PWM should be able to reach 100%.
Check picture:
