next up previous
Next: About this document ...

HC12 - Two Choices of Clock for PWM

  1. PCLKx = 0 (Clock A or B):
  2. PCLKx = 1 (Clock S0 or S1):

$N$ = PCKA 2:0 for PWM 1 and 0, $N = 0, 1, \cdots, 7$
$N$ = PCKB 2:0 for PWM 3 and 2.

$M$ = PWSCAL0 7:0 for PWM 1 and 0, $M = 0, 1, \cdots, 255$
$M$ = PWSCAL1 7:0 for PWM 3 and 2.

Normally want PWPERx = 200 $->$ 255.

Example: Want 5 kHz PWM - Per$_{\rm {x}}$ = 200 $\mu$s = 1,600 P clock cycles..

  1. Try PCLKx = 0 and PWPERx = 255

    \begin{displaymath}1600 = 2^N \times ({\tt {PWPERx+1}})\end{displaymath}


    \begin{displaymath}2^N = \frac{1600}{256} = 6.25\end{displaymath}

    Not possible. Try $2^N = 8$, $N = 3$

    \begin{displaymath}1600 = 2^N \times ({\tt {PWPERx+1}}) = 2^3 \times ({\tt {PWPERx+1}})\end{displaymath}


    \begin{displaymath}{\tt {PWPERx+1}} = \frac{1600}{2^3} = 200\end{displaymath}


    \begin{displaymath}{\tt {PWPERx}} = 199\end{displaymath}

    Exactly 5 kHz, get 1 part in 200 accuracy

  2. Try PCLKx = 1 and PWPERx = 255

    \begin{displaymath}1600 = 2^{(N+1)} \times (M+1) \times ({\tt {PWPERx+1}})\end{displaymath}


    \begin{displaymath}2^{(N+1)} \times (M+1) = \frac{1600}{256} = 6.25\end{displaymath}

    Not possible. Use a slightly different frequency - let

    \begin{displaymath}2^{(N+1)} \times (M+1) = 6\end{displaymath}


    \begin{displaymath}N = 0 {\rm\ and \ } M = 2\end{displaymath}

    This gives

    \begin{displaymath}{\rm Per}_{\rm {x}} = 2^{(0+1)} \times (2+1) \times (255+1) = 1536 {\rm ~P~clocks} = 192 \mu{\rm {s}}\end{displaymath}

    for a 5.2 kHz frequency




next up previous
Next: About this document ...
Bill Rison
2001-03-05