PIC18F45K80 runs way to fast.


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2014
    Posts
    12

    Default PIC18F45K80 runs way to fast.

    Hi.

    Im using the PIC18F45K80 for the very first time and use a 64MHz external clock source.
    To test the new hardware, and to see that it's alive, I just blinks en LED.
    The example blinks the LED way to fast, I just can se a flicker, but if I increse the pause to 5000, then it blinks 36 times in one minute.
    Anyone got an idea why this happens?

    Code:
    while 1
        high portd.7
        pause 500
        low portd.7
        pause 500
    wend

    Here is my complete code:
    Code:
    ' PIC18F45K80 Configuration Bit Settings
    ' Basic source line config statements
    
    #CONFIG
        CONFIG RETEN = OFF
        CONFIG INTOSCSEL = HIGH
        CONFIG SOSCSEL = HIGH
        CONFIG XINST = OFF
        CONFIG FOSC = EC3
        CONFIG PLLCFG = OFF
        CONFIG FCMEN = OFF
        CONFIG IESO = OFF
        CONFIG PWRTEN = ON
        CONFIG BOREN = OFF
        CONFIG BORV = 3
        CONFIG BORPWR = ZPBORMV
        CONFIG WDTEN = OFF
        CONFIG WDTPS = 1048576
        CONFIG CANMX = PORTB
        CONFIG MSSPMSK = MSK7
        CONFIG MCLRE = ON
        CONFIG STVREN = OFF
        CONFIG BBSIZ = BB2K
        CONFIG CP0 = OFF
        CONFIG CP1 = OFF
        CONFIG CP2 = OFF
        CONFIG CP3 = OFF
        CONFIG CPB = OFF
        CONFIG CPD = OFF
        CONFIG WRT0 = OFF
        CONFIG WRT1 = OFF
        CONFIG WRT2 = OFF
        CONFIG WRT3 = OFF
        CONFIG WRTC = OFF
        CONFIG WRTB = OFF
        CONFIG WRTD = OFF
        CONFIG EBTR0 = OFF
        CONFIG EBTR1 = OFF
        CONFIG EBTR2 = OFF
        CONFIG EBTR3 = OFF
        CONFIG EBTRB = OFF
    #ENDCONFIG
    
    
    '************************* DEFINES ******************************
    define osc 64
    
    
    define adc_bits 12    ' Set number of bits in result
    define adc_clock 3     ' Set clock source (3=rc)
    define adc_sampleus 50    ' Set sampling time in uS
    
    
    
    
    'lcdout $FE,$80 rad 1, $FE,$C0 rad 2
    define lcd_dreg portc
    define lcd_dbit 0
    define lcd_rsreg portc
    define lcd_rsbit 4
    define lcd_ereg portc
    define lcd_ebit 5
    define lcd_bits 4
    define lcd_lines 2
    define lcd_commandus 3000
    define lcd_dataus 100
    
    
    
    '************************ REGISTERS *****************************
    ancon0 = 100000                                                  
    ancon1 = 000000                                                  
    adcon2.7 = 1                                                        
    
    
    
    
    '*********************** PORT CONFIG ****************************
    trisa = 100000                                   'porta direction 0=OUTPUT 1=INPUT
    porta = 000000                                   'porta preset
    trisb = 010111                                   'portb direction 0=OUTPUT 1=INPUT
    portb = 000000                                   'portb preset
    trisc = 000000                                   'portc direction 0=OUTPUT 1=INPUT
    portc = 000000                                   'portc preset
    trisd = 111111                                   'portd direction 0=OUTPUT 1=INPUT
    portd = 110000                                   'portd preset
    trise = 001111                                   'porte direction 0=OUTPUT 1=INPUT
    porte = 000000                                   'porte preset
    
    
    
    
    '****************************************************************
    '*******************    MAIN PROGRAM     ************************
    '****************************************************************
    while 1
        high portd.7
        pause 500
        low portd.7
        pause 500
    wend
    
    
    end

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: PIC18F45K80 runs way to fast.

    I haven't looked at your CONFIGs and I've never run a PIC with a direct clock signal but the first thing that pops is
    Code:
    define osc 64
    defines are case sensitive, osc and OSC are not the same.
    It absolutely MUST be define OSC 64.

  3. #3
    Join Date
    Dec 2014
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: PIC18F45K80 runs way to fast.

    Thank you very much, now it works.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: PIC18F45K80 runs way to fast.

    Great, and remember that it applies to the other defines you've got in there as well.

Similar Threads

  1. Replies: 15
    Last Post: - 27th January 2012, 16:10
  2. Mibam at 20mhz runs slower than at 4 mhz
    By Homerclese in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st October 2010, 18:41
  3. clock runs reverse and fast:(
    By HYETİK in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd March 2009, 11:44
  4. hardware counting while software runs
    By Archangel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd October 2006, 03:26
  5. Ds1302 Stops are runs slow
    By Kman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th June 2006, 02:10

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