Question:
How to program period and width register of TIMER in continuous PWM mode?
Answer:
Timer runs on serial clock SCLK0 frequency.Here the generation of PWM signal having different duty cycles in TMR pin is done by programming period and width registers of Timer.
Below examples will help us to understand how to program timer period.
We are generating SCLK0 frequency as 1MHz using CGU registers with the below settings
DF-0 (25MHZ)
MSEL-4 (now 100MHZ)
SYSSEL-25 (now 4MHZ)
SCLK0-4 (now SCLK0 runs at 1 MHZ).
Hence Period of SCLK0 is 1μs.
This CGU setting is common for Example 1 and 2.
Generally period of the waveform = (period value need to be given in Period register / SCLK0 in MHZ)
Period will be in μs.
Example 1: 50% duty cycle:
Timer period value 500
Period =(500/1) μs=500μs.
Timer width value 250
Width =(250/1) μs=250μs.
So generated PWM signal is having width of 250μs.
Example 2: Generate PWM signal having period of 10 seconds:
#define MHZTOHZ (1000000u) /* Conversion purpose */
Timer period value (10*MHZTOHZ)
Period = ( (10*MHZTOHZ) / 1)μs = 10S.
Timer width value (5*MHZTOHZ)
Width = ( ( 5*MHZTOHZ) / 1)μs = 5s.
Example 3:Having 125MHZ of SCLK0,generate PWM having period of 6 seconds:
#define MHZTOHZ (1000000u) /* Conversion purpose */
Timer period value (750*MHZTOHZ)
Period =( (750*MHZTOHZ) / 125)μs = 6S.
Timer width value (375*MHZTOHZ)
Width =( (375*MHZTOHZ) / 125)μs = 3s.
Note: The maximum period value is ((2^32)-1).