Dynamically Changing the Period Value of Timers, Counters, and PWMs in PSoC® 3/4/5LP – KBA88172 | Cypress Semiconductor
Support & Community
Dynamically Changing the Period Value of Timers, Counters, and PWMs in PSoC® 3/4/5LP – KBA88172
How do you change the period value of Timer, Counter, and PWM Components on the fly in PSoC® 3/4/5LP?
The period value of fixed-function or universal digital block (UDB)-based Timer, Counter, and PWM Components can be changed on the fly using the WritePeriod() APIs given here. The new period value will be loaded only when the counter resets to zero.
You can also force the period value to take effect immediately by manually resetting the counter using the WriteCounter() API call given here.
- The change in the period of Timer/Counter/PWM made using the WritePeriod API is valid only if they are called after the Start API. Calling the Start API resets the period to the setting made in the Component Configuration window.
- When the new period value written into the period register is lesser than the previous value, it is recommended to call the WriteCounter(0) API immediately after that.
- To cause the counter count for N cycles, the period variable needs to be written as N-1.