Using the HC12 PWM

1.
Choose 8-bit mode (PWCLK 7:6 = 00)
2.
Choose left-aligned (PWCTL 3 = 0)
3.
Choose polarity = 1 (PPOL 3:0 = 1111)
4.
Select clock mode in PWPOL: PCLKx = 0 for 2N,
PCLKx = 1 for $2^{(N+1)} \times (M+1)$,

5.
Select N in PWCLK register: PCKA 2:0 for channels 1, 0; PCKB 2:0 for channels 3, 2.

6.
If PCLKx = 1, select M: PWSCAL0 7:0 = M for channels 1, 0; PWSCAL1 7:0 = M for channels 3, 2.

7.
Select PWPERx, normally between 200 and 255.

8.
Enable desired PWM channels: PWEN 3:0.

9.
Select PWDTYx, normally between 0 and PWPERx. Then

\begin{displaymath}{\rm Duty\ Cycle\ x} = \frac{{\tt PWDTYx}+1}{{\tt PWPERx}+1} \times 100 \%\end{displaymath}

Change duty cycle to control speed of motor or intensity of light, etc.

10.
For 0% duty cycle, choose PWDTYx = 0xFF.




1999-03-09