EE 308  Spring 1998

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 2^{N}, PCLKx = 1 for 2^{(N+1)} × (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

Duty Cycle x = \frac{PWDTYx + 1}{PWPERx + 1} × 100%

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

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