18F26K22 - Unable to get 64MHz Internal clock speed


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2011
    Location
    Bangalore, India
    Posts
    33

    Default 18F26K22 - Unable to get 64MHz Internal clock speed

    One of the attractions of the PIC 18F26K22 is its ability to execute code at 64MHz with its internal clock. But I am unable to get either 32MHz or 64MHz despite enabling the PLL.

    The simple test program to blink an LED at 1Hz is shown below.

    '--------------------------------------------
    DEFINE OSC 64 'Clock Speed: 64MHz

    'Fuse setting to select the Internal Oscillator, to enable PLL and to enable Primary Clock
    ASM
    __CONFIG _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_ON_1H & _PRICLKEN_ON_1H
    ENDASM

    OSCCON = %11110010 'Internal oscillator is set to 16MHz

    OSCTUNE = %11000000 'HFINTOSC selected; PLL enabled; Factory calibrated frequency

    ADCON0.0 = 0 'Disable ADC
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0

    CM1CON0.7 = 0 'Disable comparator1
    CM2CON0.7 = 0 'Disable comparator2

    'Port direction
    TRISA = 0 'All are Outputs
    TRISB = 0 'All are Outputs
    TRISC = 0 'All are Outputs

    START:

    PortC.3 = 1 : pause 500 'Turn the LED on and wait for half a second
    PortC.3 = 0 : pause 500 'Turn the LED off and wait for half a second

    GOTO START

    END
    '--------------------------------------------

    I use PBPro 2.60C to compile and PICkit2 to program. There are no issues in compiling this code and programming a 18F26K22. But the code runs at one fourth the speed. 'Pause 500' statement produces a 2 second delay. I face the same problem if I want to run it at 32MHz (4 x 8MHz). In other words, it is as if the PLL does not get turned on. After compiling, the hex file opened in MeLabs programmer shows the status of the PLL as Enabled. If I change the first line of the code to DEFINE OSC 16, everything works fine at 16MHz; enabling or disabling the PLL in the code does not make any difference.

    I have gone through the Oscillator section of the data sheet several times and I think I am doing everything required, but the PIC refuses to run at 64MHz speed. I will highly appreciate any help/suggestions to solve the problem.

    Regards,
    Bala

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: 18F26K22 - Unable to get 64MHz Internal clock speed

    I also use PBP 2.60C on a 18F24K22 (same family of PICs). Looks like you're missing one register, try this:

    Code:
    '   PIC     18F24K22    int osc 64MHz
    
    asm
     __CONFIG    _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_ON_1H & _PRICLKEN_ON_1H & _FCMEN_ON_1H & _IESO_OFF_1H
     __CONFIG    _CONFIG2L, _PWRTEN_ON_2L & _BOREN_SBORDIS_2L & _BORV_285_2L
     __CONFIG    _CONFIG2H, _WDTEN_OFF_2H
     __CONFIG    _CONFIG3H, _CCP2MX_PORTC1_3H & _PBADEN_OFF_3H  & _HFOFST_OFF_3H & _T3CMX_PORTB5_3H & _P2BMX_PORTC0_3H & _MCLRE_EXTMCLR_3H
     __CONFIG    _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    endasm
    
    ' Define LOADER_USED to allow use of the boot loader.
    ' This will not affect normal program operation.
    
    ' Define	LOADER_USED	1
    DEFINE OSC 64
    
    ;INCLUDE "AllDigital.pbp"
    ;DEFINE SHOWDIGITAL 1
    
    OSCCON  = %01110000                 ' I didn't need to set bit 7 of OSCCON for SLEEP
    OSCCON2 = %10000100
    OSCTUNE = %11000000
    
    ADCON0 = %00000000                  ' Disable ADC
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    
    ' Your code
    
    CM1CON0.7 = 0 'Disable comparator1
    CM2CON0.7 = 0 'Disable comparator2
    
    'Port direction
    TRISA = 0 'All are Outputs
    TRISB = 0 'All are Outputs 
    TRISC = 0 'All are Outputs
    
    START:
    
    PortC.3 = 1 : pause 500 'Turn the LED on and wait for half a second
    PortC.3 = 0 : pause 500 'Turn the LED off and wait for half a second
    
    GOTO START
    
    END
    I just noticed I didn't set the MFINTOSC Frequency Stable bit in OSCCON, don't know the impact of that. I'd start by adding OSCCON2 first, I know I put that there for a reason, just can't remember - I got this code running back in January.

    Robert
    Last edited by Demon; - 16th July 2014 at 12:51. Reason: Refining

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: 18F26K22 - Unable to get 64MHz Internal clock speed

    Here is what I have used in the past:
    ' WRITTEN BY DAVID PUROLA 09/18/2012
    '
    ' WRITTEN FOR USE W/18F26K22 E/P @ 64 Mhz.
    '
    DEFINE OSC 64

    #CONFIG
    ;----- CONFIG1H Options --------------------------------------------------
    __config _CONFIG1H, _FOSC_INTIO7_1H & _PLLCFG_ON_1H & _PRICLKEN_ON_1H & _FCMEN_ON_1H & _IESO_OFF_1H
    ;----- CONFIG2L Options --------------------------------------------------
    __config _CONFIG2L, _PWRTEN_ON_2L & _BOREN_ON_2L & _BORV_190_2L
    ;----- CONFIG2H Options --------------------------------------------------
    __config _CONFIG2H, _WDTEN_OFF_2H & _WDTPS_32768_2H
    ;----- CONFIG3H Options --------------------------------------------------
    __config _CONFIG3H, _CCP2MX_PORTB3_3H & _PBADEN_OFF_3H & _HFOFST_OFF_3H & _T3CMX_PORTB5_3H & _MCLRE_EXTMCLR_3H
    ;----- CONFIG4L Options --------------------------------------------------
    __config _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    #ENDCONFIG

    OSCCON = %01111000 'ENTER SLEEP MODE ON SLEEP,16 MHZ,FODC<3:0>
    OSCTUNE = %01000000 'ENABLE PLL FOR 8 OR 16 MHZ.
    OSCCON2 = %00000000
    Dave Purola,
    N8NTA
    EN82fn

  4. #4
    Join Date
    May 2011
    Location
    Bangalore, India
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: 18F26K22 - Unable to get 64MHz Internal clock speed

    Thanks a lot, Robert. On checking your code I noticed that bits <1:0> of register OSCCON are cleared in your code whereas I had entered them as 10 to select the Internal Oscillator Block. I corrected them to 00 to select Primary Clock as determined by CONFIG1H [FOSC<3:0>]. Register OSCCON2 settings do not seem to play any role in enabling PLL.

    Now my 18F26K22 is running at 64MHz!

    Thanks to Dave Purola too. In his code again, the last two bits of OSCCON are cleared.

    My revised code is given below.

    DEFINE OSC 64 'Clock Speed: 64MHz

    asm
    __CONFIG _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_ON_1H & _PRICLKEN_ON_1H & _FCMEN_ON_1H & _IESO_OFF_1H
    __CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_OFF_2L & _BORV_285_2L
    __CONFIG _CONFIG2H, _WDTEN_NOSLP_2H & _WDTPS_512_2H
    __CONFIG _CONFIG3H, _CCP2MX_PORTC1_3H & _PBADEN_OFF_3H & _CCP3MX_PORTB5_3H & _HFOFST_OFF_3H & _T3CMX_PORTB5_3H & _P2BMX_PORTC0_3H & _MCLRE_INTMCLR_3H
    __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
    __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
    __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
    __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
    __CONFIG _CONFIG7H, _EBTRB_OFF_7H
    ENDASM

    OSCCON = %11110000 'Internal oscillator is set to 16MHz; Primary Clock is selected as system clock.
    OSCTUNE = %11000000 'HFINTOSC selected; PLL enabled; Factory calibrated frequency

    ADCON0.0 = 0 'Disable ADC
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0

    CM1CON0.7 = 0 'Disable comparator1
    CM2CON0.7 = 0 'Disable comparator2

    'Port direction
    TRISA = 0 'All are Outputs
    TRISB = 0 'All are Outputs
    TRISC = 0 'All are Outputs

    START:

    PortC.3 = 1 : pause 500
    PortC.3 = 0 : pause 500

    GOTO START

    end


    - Bala

Similar Threads

  1. Replies: 15
    Last Post: - 27th January 2012, 16:10
  2. Running led blink at 64mhz with 18f26k22.
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th April 2011, 18:58
  3. How to set the internal CPU speed?
    By Ramius in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th April 2011, 20:04
  4. external clock / internal clock
    By grounded in forum General
    Replies: 4
    Last Post: - 31st May 2008, 17:44
  5. 16F628 Internal clock
    By srob in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th February 2007, 18:46

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts