News:

Let's find out together what makes a PIC Tick!

Main Menu

Internal osc with xtal fitted

Started by RGV250, Dec 22, 2024, 07:10 PM

Previous topic - Next topic

RGV250

Hi,
I have an Amicus18 board where the external xtal is soldered in place. I would like to try a program that uses the internal osc, if I set FOSC = INTIO67  will the external xtal affect anything or will it just be ignored. I do not need to use the pins.

Regards,
Bob

John Lawton

Those port lines will act as I/O so there is some extra capacitive load on those lines but you can ignore that if not using them.

Interestingly I have used the same config setting but have not managed to get the PLL working so I'm stuck at 16MHz max internal osc speed.

John

RGV250

Hi John,
In my example it is only running at 8mhz, have you set CONFIG1H bit 4 (PLLCFG)?

Bob

Stephen Moss

Quote from: John Lawton on Dec 22, 2024, 08:27 PMInterestingly I have used the same config setting but have not managed to get the PLL working so I'm stuck at 16MHz max internal osc speed.

John
I don't know what device you are using but some have a software (not Config Fuse) PLL enable bit in a register (OSCTUNE?) somewhere that you may need to set if you have not already done so.

John Lawton

My device is the original Amicus 18 fitment, 18F25K20 and it doesn't seem to have a PLLCFG bit. Yes I have set the appropriate bit in OSCTUNE without success.

It isn't mission critical, just curious really. The PLL does work using the xtal oscillator but I wanted to use it with the internal osc.

John

RGV250

Hi John,
Try setting the FOSC = HSPLL instead of INTIO67

Bob

John Lawton

Doesn't that just switch to the Xtal oscillator?

John

CPR

If this PIC is similar to the 18F25K22 you could try setting OSCTUNE.6 = 1 in order to get PLL working.

John Lawton

Yep, I think OSCTUNE is set correctly.

I've been able to run a 18F25K22 at 48MHz using the internal osc, just not the 18F25K20.

As I said it is just a curiousity.

John

RGV250

#9
Hi John,
You might be right, I was looking at the comment in fuse configurator where it does not mention the external osc for those?
From the datasheet.
Quote2.6 PLL Frequency Multiplier
A Phase-Locked Loop (PLL) circuit is provided as an
option for users who wish to use a lower frequency
oscillator circuit or to clock the device up to its highest
rated frequency from the crystal oscillator. This may be
useful for customers who are concerned with EMI due
to high-frequency crystals or users who require higher
clock speeds from an internal oscillator. There are
three conditions when the PLL can be used:
• When the primary clock is HSPLL
• When the primary clock is HFINTOSC and the
selected frequency is 16 MHz
• When the primary clock is HFINTOSC and the
selected frequency is 8 MHz
You could also try HFINTOSC.

Bob

top204

Below is a code listing template for a PIC18F25K20 device operating at 64MHz with its internal oscillator.

The program has been tested on my original Amicus18 board, with its 16MHz crystal in-place:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Internal Oscillator operating at 64MHz template for a PIC18F25K20 device.
' Written by Les Johnson for the Positron8 BASIC Compiler.
'
    Device = 18F25K20                                               ' Tell the compiler what device to compile for
    Declare Xtal = 64                                               ' Tell the compiler what frequency the device is operating at (in MHz)   
    Declare Float_Display_Type = Fast                               ' Use the compiler's faster floating point display routine
    Declare Auto_Heap_Arrays = On                                   ' Make all arrays "Heap" types, so they always get placed after standard variables
    Declare Auto_Heap_Strings = On                                  ' Make all Strings "Heap" types, so they always get placed after standard variables
    Declare Auto_Variable_Bank_Cross = On                           ' Make sure all multi-byte variables remain within a single RAM bank
'
' Setup USART1
'
    Declare Hserial1_Baud = 9600                                    ' Set USART1 Baud rate to 9600
    Declare HRSOut1_Pin   = PORTC.6                                 ' Set the TX pin for USART1
    Declare HRSIn1_Pin    = PORTC.7                                 ' Set the RX pin for USART1
   
'------------------------------------------------------------------------------------------------
' The main program starts here
' Transmit text from USART1 to check the device's oscillator is operating at the correct speed
'
Main:
    Setup()                                                         ' Setup the program and any peripherals

    Do                                                              ' Create a loop
        HRSOutLn "Hello World"
        DelayMS 500
    Loop                                                            ' Loop forever

'------------------------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    Osc_64MHz()                                                     ' Set the microcontroller for internal 64MHz operation
'
' More setup code here
'
EndProc

'------------------------------------------------------------------------------------------------
' Set the microcontroller for internal 64MHz operation
' Input     : None
' Output    : None
' Notes     : For use with a PIC18F25K20 device
'
Proc Osc_64MHz()
    OSCCON = %01110000                                              ' 16MHz HFINTOSC
    OSCTUNE = %01000000                                             ' PLLEN enabled
    DelayMS 100                                                     ' Give time for stability
EndProc

'------------------------------------------------------------------------------------------------
' Setup the fuses to use the internal oscillator on a PIC18F25K20 device. With pins RA6 and RA7 as general purpose I/O
'
Config_Start
    FOSC = INTIO67                      ' Internal oscillator block. General purpose I/O on RA6 and RA7
    FCMEN = Off                         ' Fail-Safe Clock Monitor disabled
    IESO = Off                          ' Internal/External Oscillator Switchover mode disabled
    PWRT = Off                          ' Power-up Timer disabled
    BOREN = SBORDIS                     ' Brown-out Reset enabled in hardware only (SBOREN is disabled)
    BORV = 18                           ' Brown Out Reset Voltage 1.8 V nominal
    WDTEN = Off                         ' Watchdog Timer controlled by SWDTEN bit of the WDTCON register
    WDTPS = 128                         ' Watchdog Timer Postscale Select 1:128
    CCP2MX = PORTC                      ' CCP2 input/output is multiplexed with RC1
    PBADEN = On                         ' PORTB<4:0> pins are configured as analogue input channels on Reset
    LPT1OSC = Off                       ' Timer1 configured for higher power operation
    HFOFST = On                         ' HFINTOSC starts clocking the CPU without waiting for the oscillator to stablise
    MCLRE = On                          ' MCLR pin enabled. RE3 input pin disabled
    STVREN = On                         ' Stack full/underflow will cause Reset
    LVP = Off                           ' Single-Supply ICSP disabled
    XINST = Off                         ' Extended Instruction Set disabled
    Debug = Off                         ' Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    Cp0 = Off                           ' Block 0 (000800-001FFF) not code-protected
    CP1 = Off                           ' Block 1 (002000-003FFF) not code-protected
    CP2 = Off                           ' Block 2 (004000-005FFF) not code-protected
    CP3 = Off                           ' Block 3 (006000-007FFF) not code-protected
    CPB = Off                           ' Boot block (000000-0007FF) not code-protected
    CPD = Off                           ' Data EEPROM not code-protected
    WRT0 = Off                          ' Block 0 (000800-001FFF) not write-protected
    WRT1 = Off                          ' Block 1 (002000-003FFF) not write-protected
    WRT2 = Off                          ' Block 2 (004000-005FFF) not write-protected
    WRT3 = Off                          ' Block 3 (006000-007FFF) not write-protected
    WRTC = Off                          ' Configuration registers (300000-3000FF) not write-protected
    WRTB = Off                          ' Boot Block (000000-0007FF) not write-protected
    WRTD = Off                          ' Data EEPROM not write-protected
    EBTR0 = Off                         ' Block 0 (000800-001FFF) not protected from table reads executed in other blocks
    EBTR1 = Off                         ' Block 1 (002000-003FFF) not protected from table reads executed in other blocks
    EBTR2 = Off                         ' Block 2 (004000-005FFF) not protected from table reads executed in other blocks
    EBTR3 = Off                         ' Block 3 (006000-007FFF) not protected from table reads executed in other blocks
    EBTRB = Off                         ' Boot Block (000000-0007FF) not protected from table reads executed in other blocks
Config_End

Remember, the PIC18F25K20 device will only operate at a maximum of 3.6 volts. 5 volts will harm it.

The PIC18F25K20 device was the first 8-bit PIC microcontroller to operate at 64MHz, and it has limitations compared to newer devices, but was the only device suitable for the Amicus18 board back in 2012 when I designed it. Hence the name "Amicus18". But the device is still capable of some excellent performances.