PIC18F4620 Oscillator Config problem


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2007
    Posts
    53

    Default PIC18F4620 Oscillator Config problem

    Hi,

    I currently have a matrix keypad and lcd connected to a PIC18F4620 running a 20MHz external crystal. When a key is pressed the number of the key is displayed on the lcd and also sent out via the serial port. Everything works as it should providing I have DEFINE OSC 8. As soon as I try to set it to 20, I get jibber out of the serial port.

    I am sure I have an error in my configuation and would appreciate any help on this one.

    Andy

    Code:
    ;----- CONFIG1H Options --------------------------------------------------
    '_OSC_LP_1H           EQU  H'F0'    ; LP
    '_OSC_XT_1H           EQU  H'F1'    ; XT
    '_OSC_HS_1H           EQU  H'F2'    ; HS
    '_OSC_RC_1H           EQU  H'F3'    ; RC
    '_OSC_EC_1H           EQU  H'F4'    ; EC-OSC2 as Clock Out
    '_OSC_ECIO6_1H        EQU  H'F5'    ; EC-OSC2 as RA6
    '_OSC_HSPLL_1H        EQU  H'F6'    ; HS-PLL Enabled
    '_OSC_RCIO6_1H        EQU  H'F7'    ; RC-OSC2 as RA6
    '_OSC_INTIO67_1H      EQU  H'F8'    ; INTRC-OSC2 as RA6, OSC1 as RA7
    '_OSC_INTIO7_1H       EQU  H'F9'    ; INTRC-OSC2 as Clock Out, OSC1 as RA7
    
    '_FCMEN_OFF_1H        EQU  H'BF'    ; Disabled
    '_FCMEN_ON_1H         EQU  H'FF'    ; Enabled
    
    '_IESO_OFF_1H         EQU  H'7F'    ; Disabled
    '_IESO_ON_1H          EQU  H'FF'    ; Enabled
    
    ;----- CONFIG2L Options --------------------------------------------------
    '_PWRT_ON_2L          EQU  H'FE'    ; Enabled
    '_PWRT_OFF_2L         EQU  H'FF'    ; Disabled
    
    '_BOREN_OFF_2L        EQU  H'F9'    ; Disabled
    '_BOREN_ON_2L         EQU  H'FB'    ; SBOREN Enabled
    '_BOREN_NOSLP_2L      EQU  H'FD'    ; Enabled except SLEEP, SBOREN Disabled
    '_BOREN_SBORDIS_2L    EQU  H'FF'    ; Enabled, SBOREN Disabled
    
    '_BORV_46_2L          EQU  H'E7'    ; 4.6V
    '_BORV_43_2L          EQU  H'EF'    ; 4.3V
    '_BORV_28_2L          EQU  H'F7'    ; 2.8V
    '_BORV_21_2L          EQU  H'FF'    ; 2.1V
    
    ;----- CONFIG2H Options --------------------------------------------------
    '_WDT_OFF_2H          EQU  H'FE'    ; Disabled
    '_WDT_ON_2H           EQU  H'FF'    ; Enabled
    
    '_WDTPS_1_2H          EQU  H'E1'    ; 1:1
    '_WDTPS_2_2H          EQU  H'E3'    ; 1:2
    '_WDTPS_4_2H          EQU  H'E5'    ; 1:4
    '_WDTPS_8_2H          EQU  H'E7'    ; 1:8
    '_WDTPS_16_2H         EQU  H'E9'    ; 1:16
    '_WDTPS_32_2H         EQU  H'EB'    ; 1:32
    '_WDTPS_64_2H         EQU  H'ED'    ; 1:64
    '_WDTPS_128_2H        EQU  H'EF'    ; 1:128
    '_WDTPS_256_2H        EQU  H'F1'    ; 1:256
    '_WDTPS_512_2H        EQU  H'F3'    ; 1:512
    '_WDTPS_1024_2H       EQU  H'F5'    ; 1:1024
    '_WDTPS_2048_2H       EQU  H'F7'    ; 1:2048
    '_WDTPS_4096_2H       EQU  H'F9'    ; 1:4096
    '_WDTPS_8192_2H       EQU  H'FB'    ; 1:8192
    '_WDTPS_16384_2H      EQU  H'FD'    ; 1:16384
    '_WDTPS_32768_2H      EQU  H'FF'    ; 1:32768
    
    ;----- CONFIG3H Options --------------------------------------------------
    '_MCLRE_OFF_3H        EQU  H'7F'    ; Disabled
    '_MCLRE_ON_3H         EQU  H'FF'    ; Enabled
    
    '_LPT1OSC_OFF_3H      EQU  H'FB'    ; Disabled
    '_LPT1OSC_ON_3H       EQU  H'FF'    ; Enabled
    
    '_PBADEN_OFF_3H       EQU  H'FD'    ; Port B<4:0> digital on RESET
    '_PBADEN_ON_3H        EQU  H'FF'    ; Port B<4:0> analog on RESET
    
    '_CCP2MX_PORTBE_3H    EQU  H'FE'    ; Muxed with RB3
    '_CCP2MX_PORTC_3H     EQU  H'FF'    ; Muxed with RC1
    
    ;----- CONFIG4L Options --------------------------------------------------
    '_STVREN_OFF_4L       EQU  H'FE'    ; Disabled
    '_STVREN_ON_4L        EQU  H'FF'    ; Enabled
    
    '_LVP_OFF_4L          EQU  H'FB'    ; Disabled
    '_LVP_ON_4L           EQU  H'FF'    ; Enabled
    
    '_XINST_OFF_4L        EQU  H'BF'    ; Disabled
    '_XINST_ON_4L         EQU  H'FF'    ; Enabled
    
    '_DEBUG_ON_4L         EQU  H'7F'    ; Enabled
    '_DEBUG_OFF_4L        EQU  H'FF'    ; Disabled
    
    ;----- CONFIG5L Options --------------------------------------------------
    '_CP0_ON_5L           EQU  H'FE'    ; Enabled
    '_CP0_OFF_5L          EQU  H'FF'    ; Disabled
    
    '_CP1_ON_5L           EQU  H'FD'    ; Enabled
    '_CP1_OFF_5L          EQU  H'FF'    ; Disabled
    
    '_CP2_ON_5L           EQU  H'FB'    ; Enabled
    '_CP2_OFF_5L          EQU  H'FF'    ; Disabled
    
    '_CP3_ON_5L           EQU  H'F7'    ; Enabled
    '_CP3_OFF_5L          EQU  H'FF'    ; Disabled
    
    ;----- CONFIG5H Options --------------------------------------------------
    '_CPB_ON_5H           EQU  H'BF'    ; Enabled
    '_CPB_OFF_5H          EQU  H'FF'    ; Disabled
    
    '_CPD_ON_5H           EQU  H'7F'    ; Enabled
    '_CPD_OFF_5H          EQU  H'FF'    ; Disabled
    
    ;----- CONFIG6L Options --------------------------------------------------
    '_WRT0_ON_6L          EQU  H'FE'    ; Enabled
    '_WRT0_OFF_6L         EQU  H'FF'    ; Disabled
    
    '_WRT1_ON_6L          EQU  H'FD'    ; Enabled
    '_WRT1_OFF_6L         EQU  H'FF'    ; Disabled
    
    '_WRT2_ON_6L          EQU  H'FB'    ; Enabled
    '_WRT2_OFF_6L         EQU  H'FF'    ; Disabled
    
    '_WRT3_ON_6L          EQU  H'F7'    ; Enabled
    '_WRT3_OFF_6L         EQU  H'FF'    ; Disabled
    
    ;----- CONFIG6H Options --------------------------------------------------
    '_WRTB_ON_6H          EQU  H'BF'    ; Enabled
    '_WRTB_OFF_6H         EQU  H'FF'    ; Disabled
    
    '_WRTC_ON_6H          EQU  H'DF'    ; Enabled
    '_WRTC_OFF_6H         EQU  H'FF'    ; Disabled
    
    '_WRTD_ON_6H          EQU  H'7F'    ; Enabled
    '_WRTD_OFF_6H         EQU  H'FF'    ; Disabled
    
    ;----- CONFIG7L Options --------------------------------------------------
    '_EBTR0_ON_7L         EQU  H'FE'    ; Enabled
    '_EBTR0_OFF_7L        EQU  H'FF'    ; Disabled
    
    '_EBTR1_ON_7L         EQU  H'FD'    ; Enabled
    '_EBTR1_OFF_7L        EQU  H'FF'    ; Disabled
    
    '_EBTR2_ON_7L         EQU  H'FB'    ; Enabled
    '_EBTR2_OFF_7L        EQU  H'FF'    ; Disabled
    
    '_EBTR3_ON_7L         EQU  H'F7'    ; Enabled
    '_EBTR3_OFF_7L        EQU  H'FF'    ; Disabled
    
    ;----- CONFIG7H Options --------------------------------------------------
    '_EBTRB_ON_7H         EQU  H'BF'    ; Enabled
    '_EBTRB_OFF_7H        EQU  H'FF'    ; Disabled
    
    
    
    DEFINE OSC 8 '20
    
    '-- Defines for LCD -----------------
    ' Set LCD data port
    DEFINE  LCD_DREG     PORTD 
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE  LCD_DBIT     4
    ' Set LCD Register Select (RS) port
    DEFINE  LCD_RSREG    PORTD
    ' Set LCD Register Select (RS) bit 
    DEFINE  LCD_RSBIT    2
    ' Set LCD Enable port
    DEFINE  LCD_EREG     PORTD
    ' Set LCD Enable bit
    DEFINE  LCD_EBIT     3
    ' Set LCD bus size (4 or 8) bits
    DEFINE  LCD_BITS     4
    ' Set number of lines on LCD
    DEFINE  LCD_LINES    2
    ' Set command delay time in uS
    DEFINE LCD_COMMANDUS 1500
    ' Set data delay time in uS    
    DEFINE LCD_DATAUS     44
    '------------------------------------
    
    '-- Defines for Keypad --------------
    
    DEFINE KEYPAD_ROW        2        ' 2 ROW keypad       
    DEFINE KEYPAD_ROW_PORT   PORTB    ' ROW port = PORTB
    DEFINE KEYPAD_ROW_BIT    4        ' ROW0 = PORTB.4
    DEFINE KEYPAD_COL        6        ' 6 COL keypad
    DEFINE KEYPAD_COL_PORT   PORTC    ' COL port = PORTC
    DEFINE KEYPAD_COL_BIT    0        ' COL0 = PORTB.0
    DEFINE KEYPAD_DEBOUNCEMS 100      ' debounce delay = 100 mSec
    DEFINE KEYPAD_AUTOREPEAT 1        ' use auto-repeat feature (Yes=1, No=0)
    '------------------------------------
    
    '-- Defines for USART ---------------
    ' Set receive register for receiver enabled
    define HSER_RCSTA 90h
    ' Set transmit register for transmitter enabled
    define HSER_TXSTA 20h
    ' Set baud rate
    Define HSER_BAUD 9600
    
    
    '------------------------------------
    
    @ __config _CONFIG1H, _OSC_HS_1H 
    @ __config _CONFIG2L, _PWRT_ON_2L & _BOREN_SBORDIS_2L & _BORV_28_2L
    @ __config _CONFIG2H, _WDT_OFF_2H
    @ __config _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_ON_3H
    @ __config _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L   
    
    
    ByteA   var byte
    
        
        OSCCON.6 = 1 ' Internal Oscillator Frequency Select bits
        OSCCON.5 = 1
        OSCCON.4 = 1
        
        OSCCON.1 = 0 ' System Clock Select bits
        OSCCON.0 = 0
        
        CMCON.0 = 1    ' Turn comparators OFF
        CMCON.1 = 1
        CMCON.2 = 1
    
        ADCON0.0 = 0        ' A/D Coverter Module On bit. 1=enabled, 0=disabled  
    
        clear
        
        TRISA = 111111    ' 
        TRISB = 001111    ' 
        TRISC = 111111    '
        TRISD = 001111    '
        
        include "KeyPad.bas"
     
        pause 500 ' wait one half second for LCD to initialise
        
      
    Init:
        lcdout $FE,1,"Press any Key"
    
    Start:
        gosub KeypadScan ' is an include file
        if Key then      '
            lcdout $FE,1,"Key=",dec Key 'display value of pressed key on LCD        
            hserout ["Key= ",dec Key,13,10] 'send value out serial port 
            Key = 0
            pause 500
            goto init
        endif
        goto start

  2. #2
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4620 Oscillator Config problem

    Ok - I have removed the crystal and it still runs at 8MHz! Definitely have a configuration issue somewhere.....

    Andy

  3. #3
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default Re: PIC18F4620 Oscillator Config problem

    Ok - got it working. Disabled internal/external clock switchover and fail safe clock monitor.

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