Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

Dynamically Changing the Period Value of Timers, Counters, and PWMs in PSoC® 3/4/5LP

Dynamically Changing the Period Value of Timers, Counters, and PWMs in PSoC® 3/4/5LP

VivekK_11
Employee
Employee
Welcome! First solution authored 10 replies posted

How to 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.

  •   Timer_WritePeriod(period);
  •   PWM_WritePeriod(period);
  •   Counter_WritePeriod(period);

You can also force the period value to take effect immediately by manually resetting the counter using the WriteCounter() API call given here.

  •   Timer_WriteCounter(0);
  •   PWM_WriteCounter(0);
  •   Counter_WriteCounter(0);

Note:

  1.   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.
  2.   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.
  3.   To cause the counter count for N cycles, the period variable needs to be written as N-1.
2143 Views