# pll_mc145156

Library to manage the pll chip MC145156 from Motorola

Author | Pavel Milanes Costa (CO7WT) - pavelmc@gmail.com, copyright © 2014, all rights reserved.
Adapted-by |
Compiler | >=2.4q3

Description

    This library files implement the procedures to manage a PLL system using the
    Motorola MC145156[-1|-2] chips

    A PLL is a Phase Locked Loop, a kind of Controlled oscillator used in base/mobile/handheld
    radios before the invention of the DDS chips.

    A PLL is no more than a Voltage Controled Oscillator (VCO) that is controled by the phase
    difference of it's output compared against a reference, usualy the comparison is made
    after a programable division of the output of the VCO. In this case with a dual modulus prescaler

    I assume that you know how all this work, if not please ask to google...

    All you need is the reference frequency, by the datasheet this is calculated by the Xtal
    the division ratio configured in the pins RA0..RA2, see datasheet page 14 (look for a table)
    this will be called "PLL_R" and expressed in Khz

    Then you need to know the simple division ratio of your prescaler, mine is 64 (64/65), this is
    called "PLL_P"

    From the math from the datasheet you need to calculate the register N and A, I solved that for you

    Nt = (Desired_freq/Reference_freq); but also Nt = (N*P)+A

    So, to calculate N and A registers (pll_N and pll_A in this lib) you need to know the desired freq
    for example 145000Khz

    Nt = 145000/5 = 29000; N = Nt/P
    A = Nt - (N*P)

    Next step is to send the info via SPI to the chip. For that you need three pins
    in this case we use pll_clk, pll_dat and pll_ena aliases, and if your circuit need to send sw1 & sw2
    you must define its value at load time in normal condition and then you can vary it

Sources

    Motorola Datasheet

Notes

    * Release date: 11 Nov 2014

Dependencies

No dependency found

## Summary

### Global variables/contants

- `var dword _pll_nt = 0`
- `var byte _pll_a = 0`
- `var word _pll_n = 0`

### Procedures

- `pll_set(dword in freq)`

Private

- `_pll_rset()`
- `_calc(dword in freq)`
- `_sendbit(bit in b)`

### Functions

## API details

### Global variables/contants

- `var dword _pll_nt = 0`

      vars used internally on the lib

- `var byte _pll_a = 0`

  No documentation found

- `var word _pll_n = 0`

  No documentation found

### Procedures

- `pll_set(dword in freq)`

  No documentation found

Private

- `_pll_rset()`

  No documentation found

- `_calc(dword in freq)`

      calculating the N and A vars to send

- `_sendbit(bit in b)`

  No documentation found

### Functions

## Related samples

Here are the list of samples which use this library:

18f14k50 | 18f14k50_pll.jal