News:

;) This forum is the property of Proton software developers

Main Menu

Code for basic running on Intosc 18f25k80

Started by TimB, Jan 10, 2022, 07:11 PM

Previous topic - Next topic

TimB

Hi All

Bang head on table

Trying to get a new board to come to life. It's a Pic18f25k80 on intosc. Ideally at 64mhz

Does anyone have any code to get me going?

Cheers

Tim

top204

#1
Try this Tim:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Setup a PIC18F25K80 device to operate at 64MHz using its internal oscillator
' Written for the Positron8 compiler by Les Johnson
'
    Device = 18F25K80
    Declare Xtal = 64
 
'----------------------------------------------------------------------
' The main program starts here
'
Main:
    Int_Osc64()             ' Setup the internal oscillator to operate at 64MHz
   
   
'----------------------------------------------------------------------
' Set the internal oscillator to operate at 64MHz
' Input     : None
' Output    : None
' Notes     : None
'
Proc Int_Osc64()
    OSCCON  = %01110000
    OSCCON2 = %00000000
    OSCTUNE = %01000000
    REFOCON = %00000000
    DelayMs 100
EndProc

'----------------------------------------------------------------------
' Setup the config fuses for internal oscillator on a PIC18F25K80
'
Config_Start
    FOSC = INTIO2           ' Oscillator is Internal RC
    PLLCFG = Off            ' PLLx4 Disabled
    IESO = Off              ' Internal External Oscillator Switch Over Mode disabled
    INTOSCSEL = High        ' LF-INTOSC in high-power mode during sleep
    RETEN = Off             ' Ultra low-power regulator is disabled 
    SOSCSEL = Dig           ' Digital (SCLKI) mode
    XINST = Off             ' Extended Instruction Set disabled   
    FCMEN = Off             ' Fail-Safe Clock Monitor 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        ' Use ZPBORMV instead of BORMV
    WDTEN = Off             ' WDT disabled in hardware
    WDTPS = 1048576         ' Watchdog Postscaler is 1:1048576
    CANMX = PORTB           ' ECAN TX and RX pins are located on RB2 and RB3
    MSSPMSK = MSK7          ' 7-Bit address masking mode
    MCLRE = On              ' MCLR enabled. RE3 disabled
    STVREN = On             ' Stack Overflow Reset enabled
    BBSIZ = BB2K            ' Boot Block size is 2K words
    Cp0 = Off               ' Code Protect 0x00800-0x01FFF disabled
    CP1 = Off               ' Code Protect 0x02000-0x03FFF disabled
    CP2 = Off               ' Code Protect 0x04000-0x05FFF disabled
    CP3 = Off               ' Code Protect 0x06000-0x07FFF disabled
    CPB = Off               ' Code Protect Boot disabled
    CPD = Off               ' EEPROM Read Protect disabled
    WRT0 = Off              ' Table Write Protect 0x00800-0x01FFF disabled
    WRT1 = Off              ' Table Write Protect 0x02000-0x03FFF disabled
    WRT2 = Off              ' Table Write Protect 0x04000-0x05FFF disabled
    WRT3 = Off              ' Table Write Protect 0x06000-0x07FFF 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 0x00800-0x01FFF disabled
    EBTR1 = Off             ' Table Read Protect 0x02000-0x03FFF disabled
    EBTR2 = Off             ' Table Read Protect 0x04000-0x05FFF disabled
    EBTR3 = Off             ' Table Read Protect 0x06000-0x07FFF disabled
    EBTRB = Off             ' Table Read Protect Boot disabled
Config_End

TimB

#2

Yay  ;D working

Thanks Les!!!

Something up with the board, stopped again...

top204

#3
Sounds obvious, but make sure your MCLR pin has a pull-up, and a 100nF capacitor to Gnd, so the device sees a reset when first powered up.

When changing oscillator configs, the device usually needs a power-down/power-up sequence to make the change happen, and a reset does not always work. I also forgot to add a small delay of about 100ms at the end of the Int_Osc64() procedure, which gives it a bit of time for the oscillator to become stable before exiting (now added to the code listing above).

TimB

OK found the issue

Dodgy MCLR diode soldering

Working now