Correct 24FJ64GA002 settings for external oscillator with PLL

Started by Wimax, Apr 26, 2023, 03:21 PM

Previous topic - Next topic

Wimax

Hello Everybody !

I still have an "ancient doubt"...Positron16 manual states the following procedure for using a 24FJ64GA002 with an external 8 MHz oscillator and internal PLL (x4):

Device = 24FJ64GA002
Declare Xtal = 32
CLKDIV = 0 ' CPU peripheral clock ratio set to 1:1
OSCCON.Byte1 = %00010000 ' Enable 4 x PLL '

' Configure for external oscillator with PLL
'
Config Config1 = JTAGEN_OFF, GCP_OFF, BKBUG_OFF,_
COE_OFF, ICS_PGx1, FWDTEN_OFF, WINDIS_OFF,_
FWPSA_PR128, WDTPOST_PS256
Config Config2 = IOL1WAY_OFF, IESO_OFF, FNOSC_PRIPLL,_
FCKSM_CSECME,OSCIOFNC_OFF,POSCMOD_HS


but reading on the datasheet it appears that bits 12-14 of the OSCON register should be set to 011 = Primary Oscillator with PLL module (XTPLL, HSPLL, ECPLL) while configuration 001 = Fast RC Oscillator with Postscaler and PLL module (FRCPLL)

In other words, should the OSCCON register be set as follows ?

CLKDIV = 0 ' CPU peripheral clock ratio set to 1:1
OSCCON.Byte1 = %00110000 ' Enable 4 x PLL '

Which is the correct setting ?


trastikata

Quote from: Wimax on Apr 26, 2023, 03:21 PMWhich is the correct setting ?

Hi,

always follow the datasheets, and when in doubt (about the oscillator frequency) use a blinking LED for verification!

Wimax

Yes,  ;) I'm following the data-sheet , but if there is a typo it might be useful to fix it in future versions of the user manual.

top204

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Setup the device to operate with an external crystal and the 4xPLL enabled
'
' Written by Les Johnson for the Positron16 BASIC compiler.
'
    Device = 24FJ64GA002
    Declare Xtal = 32

'-------------------------------------------------------------------------------------------------------------
' The main program starts here
'
Main:
    Clock_Init()

'-------------------------------------------------------------------------------------------------------------
' Initialise the clock
' Input     : None
' Output    : None
' Notes     : None
'
Proc Clock_Init()
    CLKDIV = $3100
    OSCTUN = $00
    PMD1 = $00
    PMD2 = $00
    PMD3 = $00
    Write_OSCCONH($03)
    Write_OSCCONL($00)
EndProc

'-------------------------------------------------------------------------------------------------------------
' Setup a PIC24FJ64GA002 for external crystal oscillator with PLL
'
Config Config1 = WDTPOST_PS256,_        ' Watchdog Timer Postscaler is 1:256
                 FWPSA_PR128,_          ' WDT Prescaler ratio of 1:128
                 WINDIS_ON,_            ' Standard Watchdog Timer enabled,(Windowed-mode is disabled)
                 FWDTEN_OFF,_           ' Watchdog Timer is disabled
                 ICS_PGx1,_             ' Emulator EMUC1/EMUD1 pins are shared with PGC1/PGD1
                 BKBUG_OFF,_            ' Device resets into Operational mode
                 GWRP_OFF,_             ' General Code Segment Write protect disabled
                 GCP_OFF,_              ' General Code Segment Code protect disabled
                 JTAGEN_OFF             ' JTAG port is disabled

Config Config2 = POSCMOD_XT,_           ' XT Oscillator mode selected
                 I2C1SEL_PRI,_          ' Use default SCL1/SDA1 pins
                 IOL1WAY_OFF,_          ' IOLOCK can be changed
                 OSCIOFNC_OFF,_         ' OSC2/CLKO/RC15 functions as CLKO (FOSC/2)
                 FCKSM_CSDCMD,_         ' Clock switching and Fail-Safe Clock Monitor are disabled
                 FNOSC_PRIPLL,_         ' Primary Oscillator with PLL module
                 SOSCSEL_SOSC,_         ' Default Secondary Oscillator
                 WUTSEL_LEG,_           ' Legacy Wake-up Timer
                 IESO_ON                ' Two-Speed Start-up enabled

Wimax