News:

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

Main Menu

Pic18F45k80

Started by Rizwan s shaikh, Apr 08, 2024, 10:19 AM

Previous topic - Next topic

Rizwan s shaikh

having problem to set INTOSC for the PIC18F45K80
16Mhz.32Mhz and 64Mhz
Please help

Stephen Moss

You are not exaclty giving people much information to go on there, help us to help you...
Is your compiler version up to date?
Have you tried a simple program to toggle an I/O pin high and low once a second, and if so is it not running at all, running too fast or too slow?

Posting your code will also have people come up with a solution as it may be a code issue or an incorrect fuse configuration issue, but without your code how could anyone determine which.
Although for 32MHz & 64MHz my guess (with no other information to go on) would be that you have not set the INTOSC frequency to 8MHz & 16MHz resepectively and enabled the PLL, 16MHz you can from the INTOSC get without using the PLL.

John Lawton

If you use the Fuse Configurator plugin you'll get something like this (actually for a PIC18F45K40):


'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

; For Device = 18F45K40:

Config_Start
  FEXTOSC = OFF              ;Oscillator not enable
  RSTOSC = HFINTOSC_64MHZ    ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:
  CLKOUTEN = OFF             ;CLKOUT function is disable
  CSWEN = ON                 ;Writing to NOSC and NDIV is allowe
  FCMEN = ON                 ;Fail-Safe Clock Monitor enable
  MCLRE = EXTMCLR            ;If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
  PWRTE = ON                 ;Power up timer enable
  LPBOREN = ON               ;ULPBOR enable
  BOREN = SBORDIS            ;Brown-out Reset enabled , SBOREN bit is ignore
  BORV = VBOR_2P45           ;Brown-out Reset Voltage (VBOR) set to 2.45
  ZCD = OFF                  ;ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCO
  PPS1WAY = OFF              ;PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence
  STVREN = ON                ;Stack full/underflow will cause Rese
  DEBUG = OFF                ;Background debugger disable
  XINST = OFF                ;Extended Instruction Set and Indexed Addressing Mode disable
  WDTCPS = WDTCPS_31         ;Divider ratio 1:65536; software control of WDTP
  WDTE = OFF                 ;WDT Disable
  WDTCWS = WDTCWS_7          ;window always open (100%); software control; keyed access not require
  WDTCCS = SC                ;Software Contro
  WRT0 = OFF                 ;Block 0 (000800-001FFFh) not write-protecte
  WRT1 = OFF                 ;Block 1 (002000-003FFFh) not write-protecte
  WRT2 = OFF                 ;Block 2 (004000-005FFFh) not write-protecte
  WRT3 = OFF                 ;Block 3 (006000-007FFFh) not write-protecte
  WRTC = OFF                 ;Configuration registers (300000-30000Bh) not write-protecte
  WRTB = OFF                 ;Boot Block (000000-0007FFh) not write-protecte
  WRTD = OFF                 ;Data EEPROM not write-protecte
  SCANE = ON                 ;Scanner module is available for use, SCANMD bit can control the modul
  LVP = ON                   ;Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignore
  CP = OFF                   ;UserNVM code protection disable
  CPD = OFF                  ;DataNVM code protection disable
  EBTR0 = OFF                ;Block 0 (000800-001FFFh) not protected from table reads executed in other block
  EBTR1 = OFF                ;Block 1 (002000-003FFFh) not protected from table reads executed in other block
  EBTR2 = OFF                ;Block 2 (004000-005FFFh) not protected from table reads executed in other block
  EBTR3 = OFF                ;Block 3 (006000-007FFFh) not protected from table reads executed in other block
  EBTRB = OFF                ;Boot Block (000000-0007FFh) not protected from table reads executed in other block
Config_End

'**** End of Fuse Configurator Settings ****


In the main code, to run at 16MHz, I used:

OSCCON1 = %01100010             'Internal oscillator @ 64MHz / 4 = 16MHz

I hope that helps a bit

John

top204

There are several combinations of config fuse settings and SFR (Special Function Register) loading that can give particular oscillator speeds, but I always prefer the software switching methods because a simple call to a particular procedure will alter the speed of the device, and the config fuse settings can stay they same. However, always make sure the Declare Xtal value matches the device's actual operating speed.

An example of a standard Positron8 BASIC code layout for a PIC18F45K80 device that can run at 16MHz or 32MHz or 64MHz using its internal oscillator is listed below. All the information required is in the device's datasheet and the available fuse settings are in a devices's compiler '.PPI' file. The program has not been tested, but the same mechanism also works with a PIC18F25K80 device, and I remember testing the fuse settings and the 64MHz operation on one of them a few years ago:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Setup a PIC18F45K80 device to operate at 16MHz or 32MHz or 64MHz using its internal oscillator and 4xPLL software enabled.
'
' Written for the Positron8 compiler by Les Johnson.
'
    Device = 18F45K80                           ' Tell the compiler what device to compile for
    Declare Xtal = 32                           ' Tell the compiler what frequency the device will be operating at (in MHz)
'
' Setup USART1
'
    Declare HSerial1_Baud = 9600
    Declare HRSOut1_Pin   = PORTC.6
    Declare HRSIn1_Pin    = PORTC.7
'
' Create any global variables and constants here
'

'----------------------------------------------------------------------
' The main program starts here
' Transmit the text "Hello World" at 9600 Baud to make sure the device is running at the speed required by the Xtal declare.
' If the text is not seen on the serial terminal, then the device is not operating at the correct speed for the Xtal Declare.
'
Main:
    Setup()                                     ' Setup the program and any peripherals

    Do                                          ' Create a loop
        HRsout1Ln "Hello World"                 ' Transmit text to a serial terminal
        DelayMs 500                             ' Delay between transmissions
    Loop                                        ' Do it forever

'----------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    'Int_Osc16MHz()                              ' Use to set the internal oscillator to operate at 16MHz on a PIC18F45K80 device
    Int_Osc32MHz()                              ' Use to set the internal oscillator to operate at 32MHz on a PIC18F45K80 device
    'Int_Osc64MHz()                              ' Use to set the internal oscillator to operate at 64MHz on a PIC18F45K80 device

EndProc

'----------------------------------------------------------------------
' Set the internal oscillator to operate at 16MHz on a PIC18F45K80 device
' Input     : None
' Output    : None
' Notes     : None
'
Proc Int_Osc16MHz()
    OSCCON  = %01010000                         ' 4MHz
    OSCCON2 = $00
    OSCTUNE = %10000000                         ' Use INTRC with 4xPLL enabled
    REFOCON = $00
    DelayMS 50                                  ' Wait for stability
EndProc

'----------------------------------------------------------------------
' Set the internal oscillator to operate at 32MHz on a PIC18F45K80 device
' Input     : None
' Output    : None
' Notes     : None
'
Proc Int_Osc32MHz()
    OSCCON  = %01100000                         ' 8MHz
    OSCCON2 = $00
    OSCTUNE = %10000000                         ' Use INTRC with 4xPLL enabled
    REFOCON = $00
    DelayMS 50                                  ' Wait for stability
EndProc

'----------------------------------------------------------------------
' Set the internal oscillator to operate at 64MHz on a PIC18F45K80 device
' Input     : None
' Output    : None
' Notes     : None
'
Proc Int_Osc64MHz()
    OSCCON  = %01110000                         ' 16MHz
    OSCCON2 = $00
    OSCTUNE = %10000000                         ' Use INTRC with 4xPLL enabled
    REFOCON = $00
    DelayMS 50                                  ' Wait for stability
EndProc

'----------------------------------------------------------------------
' Setup the fuses for internal oscillator on a PIC18F45K80
' The OSC pins are set as genral purpose I/O pins
'
Config_Start
    FOSC = INTIO2                   ' Internal RC oscillator
    PLLCFG = Off                    ' 4xPLL disabled
    RETEN = Off                     ' Ultra low-power regulator is disabled (Controlled by REGSLP bit)
    INTOSCSEL = HIGH                ' LF-INTOSC in High power mode during Sleep
    SOSCSEL = DIG                   ' SOSC Power Selection and mode is digital (SCLKI)
    FCMEN = Off                     ' Fail-Safe Clock Monitor disabled
    IESO = Off                      ' Internal External Oscillator Switch Over Mode disabled
    PWRTEN = Off                    ' Power Up Timer disabled
    BOREN = SBORDIS                 ' Brown Out Detect Enabled in hardware. SBOREN disabled
    BORV = 3                        ' Brown-out Reset Voltage is 1.8V
    BORPWR = ZPBORMV                ' ZPBORMV instead of BORMV is selected
    WDTEN = Off                     ' WDT disabled in hardware. SWDTEN bit disabled
    WDTPS = 128                     ' Watchdog Postscaler is 1:128
    CANMX = PORTB                   ' ECAN TX and RX pins are located on RB2 and RB3
    MSSPMSK = MSK7                  ' MSSP uses a 7 Bit address masking
    MCLRE = On                      ' MCLR Enabled. RE3 disabled
    STVREN = Off                    ' Stack Overflow Reset disabled
    XINST = Off                     ' Extended Instruction Set disabled
    BBSIZ = BB1K                    ' 1K word Boot Block size
    CP0 = Off                       ' Code Protect 00800-01FFF disabled
    CP1 = Off                       ' Code Protect 02000-03FFF disabled
    CP2 = Off                       ' Code Protect 04000-05FFF disabled
    CP3 = Off                       ' Code Protect 06000-07FFF disabled
    CPB = Off                       ' Code Protect Boot disabled
    CPD = Off                       ' EEPROM Read Protect disabled
    WRT0 = Off                      ' Table Write Protect 00800-01FFF disabled
    WRT1 = Off                      ' Table Write Protect 02000-03FFF disabled
    WRT2 = Off                      ' Table Write Protect 04000-05FFF disabled
    WRT3 = Off                      ' Table Write Protect 06000-07FFF disabled
    WRTC = Off                      ' Config Write Protect disabled
    WRTB = Off                      ' Table Write Protect Boot disabled
    WRTD = Off                      ' EEPROM Write Protect disabled
    EBTR0 = Off                     ' Table Read Protect 00800-01FFF disabled
    EBTR1 = Off                     ' Table Read Protect 02000-03FFF disabled
    EBTR2 = Off                     ' Table Read Protect 04000-05FFF disabled
    EBTR3 = Off                     ' Table Read Protect 06000-07FFF disabled
    EBTRB = Off                     ' Table Read Protect Boot disabled
Config_End

Rizwan s shaikh

Thanks Les sar
16 and 32MHz wark properly
64MHz wark but baud 9600 notwark
Baud 19200 wark
Edit
PLLCFG = ON
OSCTUNE.6 = 1

Thanks again