• Pic® Basic

  • Crystals, PLL's & Proton

    Crystals, PLL’s and Proton

    Bad device configuration can cause problems with some Proton Commands, this seems particular prevalent when PLLs are being used. Hopefully this article will guide you in the right directing to avoid such problems.

    In Proton some of the commands are very dependent on the oscillator frequency, Rsin, Rsout, DelayMs, and DelayUs are just a few of those affected. In order for the compiler to calculate the correct timings for these commands it must know at what frequency the PIC is being clocked, otherwise the timings will be either too long or too short. So how do we let the compiler know the frequency at which we are clocking the PIC?

    No PLL usage:
    Under normal circumstances (clock =< 20MHz, no PLL) you can just follow the manual and use the crystal declare to inform the compiler of the clock speed, i.e.

    Declare Xtal = 20 for a 20MHz clock or
    Declare Xtal = 12 for a 12MHz clock, and so forth.

    However, things are not as straight forward when you wish to clock your PIC at frequencies higher than 20MHz because most PIC's cannot take an input frequency greater than 20MHz directly. The solution is to use a PIC with an internal PLL (Phase Locked Loop). How you set up the PIC and inform the compiler of the clocking frequency depends on the circumstances however, they fall into three basic categories as follows...

    Using an external crystal and the PIC’s internal PLL
    For simple configurations, i.e. clocking the PIC at 64MHz using a 16MHz crystal via the PICs internal PLL we can inform the compiler of the PICs actual clocking frequency by either...


    Declaring the crystal at its true frequency in conjunction with the PLL_REQ declare, i.e.

    Device = 16LF1946
    ;--- Config Fuse Settings ----------------------------------------------------
    Config1 FOSC_HS ;HS oscillator selected
    Config2 PLLEN_ON ;PLL enabled
    ; Other fuses not shown for clarity

    Declare Xtal = 16
    Declare PLL_Req = True1


    Directly declare the crystal frequency as the PLL frequency (crystal frequency x 4) i.e.

    Device = 18F24K20
    ;--- Config Fuse Settings ----------------------------------------------------
    FOSC = HSPLL_HS ;HS oscillator selected, PLL enabled (HSPLL)
    ; Other fuses not shown for clarity

    Declare Xtal = 642 ;*** Crystal = 16MHz, PIC = 64MHz (16*4), hence Xtal = 64 ***


    The PDS manual states that the PLL_Req declare sets the PLL config fuse. It achieves this by changing the PDS default fuse setting (as specified in the PPI files) of either the OSC fuses to HSPLL or the PLL Enable fuse to ON (device dependant) however; it only has that effect if no fuse configuration data has been entered. If any fuse configuration data has been entered the PLL_Req declares only effect is to tell the compiler to base its timing calculations on a frequency four times greater than that specified in the Xtal declare.

    This works provided that the specified PLL frequency is allowed for the device you are using, see the “Crystal Frequency Declare” section of the user manual for acceptable values.