Presetting Configuration Fuses (PIC Defines) into your Program


+ Reply to Thread
Results 1 to 40 of 83

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Help in setting internal clock on 18F1220 device

    Hello
    I am new to this forum, I am a RF Engineer trying to use a 18F1220 with its internal oscillator. So far I have been unsucessfull in doing this. When using MPLAB and a IDC2 in debugger mode the Blink program works fine. When I program the device and run it on its own power it does not work. I think I traced it to the 18f1220.inc file, CONFIG1H fuse.

    ;************************************************* ***************
    ;* 18F1220.INC *
    ;* *
    ;* By : Leonard Zerman, Jeff Schmoyer *
    ;* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
    ;* All Rights Reserved *
    ;* Date : 01/27/04 *
    ;* Version : 2.45 *
    ;* Notes : *
    ;************************************************* ***************
    NOLIST
    ifdef PM_USED
    LIST
    "Error: PM does not support this device. Use MPASM."
    NOLIST
    else
    LIST
    LIST p = 18F1220, r = dec, w = -311, f = inhx32
    INCLUDE "P18F1220.INC" ; MPASM Header
    __CONFIG _CONFIG1H, _XT_OSC_1H
    __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
    __CONFIG _CONFIG3H, _MCLRE_ON_3H
    __CONFIG _CONFIG4L, _LVP_OFF_4L
    NOLIST
    endif
    LIST
    EEPROM_START EQU 0F00000h
    BLOCK_SIZE EQU 8

    It sets the oscillator to External. I am not sure what the fuse should be set to. I also beleve the INTRC needs to be reconfigured for 8 MHz. Can anyone assist me? Thank You.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wbubel View Post
    Hello
    I am new to this forum, I am a RF Engineer trying to use a 18F1220 with its internal oscillator. So far I have been unsucessfull in doing this. When using MPLAB and a IDC2 in debugger mode the Blink program works fine. When I program the device and run it on its own power it does not work. I think I traced it to the 18f1220.inc file, CONFIG1H fuse.

    ;************************************************* ***************
    ;* 18F1220.INC *
    ;* *
    ;* By : Leonard Zerman, Jeff Schmoyer *
    ;* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
    ;* All Rights Reserved *
    ;* Date : 01/27/04 *
    ;* Version : 2.45 *
    ;* Notes : *
    ;************************************************* ***************
    NOLIST
    ifdef PM_USED
    LIST
    "Error: PM does not support this device. Use MPASM."
    NOLIST
    else
    LIST
    LIST p = 18F1220, r = dec, w = -311, f = inhx32
    INCLUDE "P18F1220.INC" ; MPASM Header
    __CONFIG _CONFIG1H, _XT_OSC_1H
    __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
    __CONFIG _CONFIG3H, _MCLRE_ON_3H
    __CONFIG _CONFIG4L, _LVP_OFF_4L
    NOLIST
    endif
    LIST
    EEPROM_START EQU 0F00000h
    BLOCK_SIZE EQU 8

    It sets the oscillator to External. I am not sure what the fuse should be set to. I also beleve the INTRC needs to be reconfigured for 8 MHz. Can anyone assist me? Thank You.
    Hello wbubel, Welcome !
    In the MPASM Suite each supported PIC has a file, named for it I. E. P18F1220.inc, in it is listed every valid config and register address. To switch to using MPASM, in MCS click view, compile and program options,click on the tab named assembler, and insert a check in the box "use MPASM", click OK and you are set. Here is what is available for config 1 . . .
    Code:
    ;Configuration Byte 1H Options
    _IESO_ON_1H       EQU  H'FF' ; Internal External Oscillator Switch Over mode enabled
    _IESO_OFF_1H      EQU  H'7F' ; Internal External Oscillator Switch Over mode disabled
    _FSCM_ON_1H       EQU  H'FF' ; Fail-Safe Clock Monitor enabled
    _FSCM_OFF_1H      EQU  H'BF' ; Fail-Safe Clock Monitor disabled
    _RC_OSC_1H        EQU  H'FF' ; External RC on OSC1, OSC2 as FOSC/4
    _RCIO_OSC_1H      EQU  H'F7' ; External RC on OSC1, OSC2 as RA6
    _LP_OSC_1H        EQU  H'F0' ; LP Oscillator
    _XT_OSC_1H        EQU  H'F1' ; XT Oscillator
    _HS_OSC_1H        EQU  H'F2' ; HS Oscillator
    _HSPLL_OSC_1H     EQU  H'F6' ; HS + PLL
    _EC_OSC_1H        EQU  H'F4' ; External Clock on OSC1, OSC2 as FOSC/4
    _ECIO_OSC_1H      EQU  H'F5' ; External Clock on OSC1, OSC2 as RA6
    _INTIO1_OSC_1H    EQU  H'F9' ; Internal RC, OSC1 as RA7, OSC2 as FOSC/4
    _INTIO2_OSC_1H    EQU  H'F8' ; Internal RC, OSC1 as RA7, OSC2 as RA6
    You can change it in the file you posted or comment them out there and just add the ones you want at the top of your code (my preferred method). Most PICs you use DEFINE OSC 8 , but I won't say all . . .
    Last edited by Archangel; - 17th July 2009 at 17:41.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    _INTIO2_OSC_1H would set it for internal osc with OSC1 & OSC2 pins free to use for I/O.

    Look in the P18F1220.INC file in your MPLAB directory for a list of config options.

    To select 8MHz internal, look in the 18F1220 data sheet in the Oscillator Configurations
    section. It shows the value to write to OSCCON to select various frequencies.

    When programming the PIC with the ICD, in inserts a debug kernel, so you may need to
    configure the ICD as the programmer before burning the PIC for stand-alone operation.

    With the ICD debug kernel programmed into the PIC it needs the PC interface to operate.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Jul 2009
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re:Help in setting internal clock on 18F1220 device

    Joe S. and Bruce
    Thanks for your valuable help. Sorry its been a while since I've been able to get back to this project. Here is the status. I have set the CONFIG1H fuse to
    _INTIO2_OSC_1H as Bruce suggested and OSCCON = %01110000.
    I set the ICD as a programmer. When I released the PIC from Reset it runs so slow I thought it was not working. Either I screwed up the OSCCON settings or there is something I am missing.


    OSCCON = %01110000 'Define the Osc to 8 MHz
    LED2 var PORTB.2 ' LED
    cntr var word
    FET var PORTA.0
    TRISA = %00000000 ' Set PORTA ports 0-4 to input, 5-7 Output
    TRISB = %00000000 ' Set PORTB to all output
    PORTB = %00000100 ' Clear PORTB
    PORTA = %00000000 ' Clear PORTA

    cntr = 0
    FET = 0

    Main:
    led2 = 1
    pause 100
    led2 = 0
    pause 100
    ' cntr = cntr + 1
    ' if (cntr <= 2) then goto main
    ' FET = 1
    goto main
    Stop

    Can anyone Help me.

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wbubel View Post
    I set the ICD as a programmer. When I released the PIC from Reset it runs so slow I thought it was not working. Either I screwed up the OSCCON settings or there is something I am missing.
    You should compile NOT using ICD COMPILE, use the one which says compile, only use ICD compile to use the ICD, recompile with the COMPILE for stand alone use. Put a
    DEFINE OSC 4
    or whatever number is right in you code near the top. The PIC is probably running using the fail safe oscillator .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    Jul 2009
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    This piece of code made it work

    DEFINE OSC 4 'Define the Osc to 8 MHz

    asm
    bsf OSCCON, SCS1 ; 1x = Internal Block
    bcf OSCCON, SCS0 ; 00 = Primary Oscillator (20Mhz?)
    bsf OSCCON, IRCF2 ; 111=8000 110=4000 101=2000
    bsf OSCCON, IRCF1 ; 100=1000 011=0500 010=0250
    bcf OSCCON, IRCF0 ; 001=0125 000=0032
    MSTABLE010 btfss OSCCON, IOFS
    bra MSTABLE010 ; wait until Oscillator is stable
    endasm

  7. #7
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Subtle differences in config

    This doesn't directly apply to your situation this time, but I did run into a sneaky change the other day that took me a while to notice..
    I was trying to change the oscillator config on a 18F1320. I had been recently using 18F1330s and just assumed they would be the same since they were so close family wise. Bad assumption. Here are the two together.
    Code:
    ;****************************************************************
    ;*  18F1330.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2006 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 06/05/06                                        *
    ;*  Version   : 2.47                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F1330, r = dec, w = -311, w = -230, f = inhx32
            INCLUDE "P18F1330.INC"  ; MPASM  Header
            __CONFIG    _CONFIG1H, _OSC_INTIO2_1H 
           ; __CONFIG    _CONFIG1H, _OSC_XT_1H
            __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
            __CONFIG    _CONFIG4L, _XINST_OFF_4L
            NOLIST
        endif
            LIST
    EEPROM_START	EQU	0F00000h
    BLOCK_SIZE	EQU	8
    
    '==============================================================================
    '==============================================================================
    
    ;****************************************************************
    ;*  18F1320.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2006 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 06/05/06                                        *
    ;*  Version   : 2.47                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F1320, r = dec, w = -311, w = -230, f = inhx32
            INCLUDE "P18F1320.INC"  ; MPASM  Header
            __CONFIG    _CONFIG1H, _INTIO2_OSC_1H    ; this for INT OSC 
        ;   __CONFIG    _CONFIG1H, _XT_OSC_1H	 ;was this for XT OSC
            __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
            __CONFIG    _CONFIG4L, _LVP_OFF_4L
            NOLIST
        endif
            LIST
    EEPROM_START	EQU	0F00000h
    BLOCK_SIZE	EQU	8
    the commented out part was my addition, but notice the different syntax for the oscillator statement.
    Just hadn't run into that before.
    Bo

  8. #8
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Can't find @MyConfig

    Hi all,

    I have tried to find where the @MyConfig references were without any success. Anyone have them bookmarked?
    I still don't have a good handle on changing these without tweaking the .inc files and I'm afraid that's going to bite me someday (even though I do leave the original lines REM'd).

    I have seen @MyConfig used, but don't know if there are any caveats.

    Thanks
    Bo

Similar Threads

  1. pic program crashing
    By comwarrior in forum General
    Replies: 5
    Last Post: - 8th July 2009, 17:33
  2. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 15:46
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  4. size of program vs mem on pic
    By PICMAN in forum General
    Replies: 1
    Last Post: - 1st March 2005, 18:23
  5. Serial communication PIC to PIC help.
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2005, 16:45

Members who have read this thread : 6

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