EE 308  Spring 1999

HC12 - Two Choices of Clock for PWM

1. PCLKx = 0:

• Clk_{x} = 0.125μs × 2^{N}

• Per_{x} = 0.125μs × 2^{N} × (PWPERx + 1)

2. PCLKx = 1:

• Clk_{x} = 0.125μs × 2^{(N+1)} × (M + 1)

• Per_{x} = 0.125μs × 2^{(N+1)} × (M + 1) × (PWPERx + 1)

N = PCKA 2:0 for PWM 1 and 0, N = 0, 1, ⋯, 7 N = PCKB 2:0 for PWM 3 and 2. M = PWSCAL0 7:0 for PWM 1 and 0, M = 0, 1, ⋯, 255 M = PWSCAL1 7:0 for PWM 3 and 2. Normally want PWPERx = 200 − > 255. Example: Want 5 kHz PWM – Per_{x} = 200 μs.

 1. Try PCLKx = 0 and PWPERx = 255

200μs = 0.125μs × 2^{N} × (PWPERx + 1)

2^{N} = \frac{200μs}{0.125μs × 256} = 6.25

Not possible Try PWPERx = 199

2^{N} = \frac{200μs}{0.125μs × 200} = 8

N = 3

Exactly 5 kHz, get 1 part in 200 accuracy

EE 308  Spring 1999

2. Try PCLKx = 1 and PWPERx = 255

200μs = 0.125μs × 2^{(N+1)} × (M + 1) × (PWPERx + 1)

2^{(N+1)} × (M + 1) = \frac{200μs}{0.125μs × 256} = 6.25

Not possible. Use a slightly different frequency – let 2^{(N+1)} × (M + 1) = 6

N = 0 and M = 2

This gives

Per_{x} = 0.125μs × 2^{(0+1)} × (2 + 1) × (255 + 1) = 192μs for a 5.2 kHz frequency