16-bit timer
Procedure
To use Pulse Width Modulation mode:
1.
Load the OC2R register with the value corresponding to the period of the signal using
the formula in the opposite column.
2.
Load the OC1R register with the value corresponding to the period of the pulse if
(OLVL1 = 0 and OLVL2 = 1) using the formula in the opposite column.
3.
Select the following in the CR1 register:
–
–
4.
Select the following in the CR2 register:
–
–
–
If OLVL1 = 1 and OLVL2 = 0 the length of the positive pulse is the difference between the
OC2R and OC1R registers.
If OLVL1 = OLVL2 a continuous signal will be seen on the OCMP1 pin.
The OC
R register value required for a specific timing application can be calculated using
i
the following formula:
Where:
t
f
=
CPU
=
PRESC
If the timer clock is an external clock the formula is:
Where:
t
=
114/279
Using the OLVL1 bit, select the level to be applied to the OCMP1 pin after a
successful comparison with the OC1R register.
Using the OLVL2 bit, select the level to be applied to the OCMP1 pin after a
successful comparison with the OC2R register.
Set OC1E bit: the OCMP1 pin is then dedicated to the output compare 1 function.
Set the PWM bit.
Select the timer clock (CC[1:0]) (see
= Signal or pulse period (in seconds)
CPU clock frequency (in hertz)
Timer prescaler factor (2, 4 or 8 depending on CC[1:0] bits, see
Signal or pulse period (in seconds)
Doc ID 12468 Rev 3
Table
50).
Pulse Width Modulation cycle
When
Counter
OCMP1 = OLVL1
= OC1R
OCMP1 = OLVL2
When
Counter
Counter is reset
= OC2R
to FFFCh
ICF1 bit is set
t
f
CPU
*
OCiR Value =
PRESC
t
f
-5
OCiR =
*
EXT
ST72361xx-Auto
- 5
Table
50)
Need help?
Do you have a question about the ST72361 Auto Series and is the answer not in the manual?