Re: How to dynamically change duty cycle with HardwareTimer library?
Posted: Sun Mar 13, 2022 8:20 am
To my understanding (as a hobby user) :
setCaptureCompare is 0 indexed, CounterCompare Register (CCRx) is 0 indexed
setOverflow is 1 indexed, Hardware AutoReload Register (ARR) is 0 indexed.
setPrescaleFactor is 1 indexed, Prescaler register (PSC) is 0 indexed.
To set duty cycle to 100% CounterCompare Register must be greater than ARR (or same in setOveflow)
In example above, my error is only in comment, and should be:
Actaul hardware AutoReloaRegister (ARR) is 254, so 255 in CounterCompareRegister (CCR) (same as setCaptureCompare ) will be 100% duty cycle.
Again, this is just my opinion, based on information i found in source code/datasheet/internet.
Here is some links i found that helped me :
https://github.com/stm32duino/Arduino_C ... issues/897
https://github.com/stm32duino/Arduino_C ... #L852-L853
setCaptureCompare is 0 indexed, CounterCompare Register (CCRx) is 0 indexed
setOverflow is 1 indexed, Hardware AutoReload Register (ARR) is 0 indexed.
setPrescaleFactor is 1 indexed, Prescaler register (PSC) is 0 indexed.
To set duty cycle to 100% CounterCompare Register must be greater than ARR (or same in setOveflow)
In example above, my error is only in comment, and should be:
Code: Select all
PWMtimer ->setOverflow( 255 , TICK_FORMAT); // Overflow in 255 ticks (same for all 4 channels) // PWM base frequency: 72MHz/255=282.35KHz
Again, this is just my opinion, based on information i found in source code/datasheet/internet.
Here is some links i found that helped me :
https://github.com/stm32duino/Arduino_C ... issues/897
https://github.com/stm32duino/Arduino_C ... #L852-L853