Timing of heartbeat LED is off


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,831

    Default Timing of heartbeat LED is off

    Migrated my test code from a 18F26K22 (max 3Kohm impedance on ADC) to a 16F1937 (max 10K).
    Datasheet: https://ww1.microchip.com/downloads/...ets/41364E.pdf
    32 MHz internal clock is on page 74

    I tried a gazillion permutations of the clock settings but I can't seem to get it to blink ON at 1 second intervals.

    Pause 15 takes about 1 second from ON to ON.

    Code:
    #CONFIG
     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF 
     __CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_LO & _LVP_OFF
    #ENDCONFIG
    DEFINE IRCF = %1110                 ' to enable 8 MHz
    DEFINE SCS = %00                    ' system clock determined by FOSC
    DEFINE OSC 32
    'DEFINE TUN = %000000
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELD = %00000000
    ANSELE = %00000000
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %00000000
    TRISD = %00000000
    TRISE = %00001000   ' E3=MCLR
    LEDblink    var     PORTB.5
        LEDblink = 0
    Mainloop:
        if ledblink = 0 then
            LEDblink = 1
        else
            LEDblink = 0
        endif            
        Pause 15
        goto mainloop
    end
    I bow in humbleness and await the appropriate mockery.
    Last edited by Demon; - 12th August 2024 at 06:14.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,451


    Did you find this post helpful? Yes | No

    Default Re: Timing of heartbeat LED is off

    DEFINE IRCF = %1110 ' to enable 8 MHz
    DEFINE SCS = %00 ' system clock determined by FOSC
    none of which are known PBP defines

    which means that the chips osc is running with POR values
    what are the POR values
    Name:  demon.jpg
Views: 57
Size:  176.8 KB

    fosc= 0.5 MHz
    Warning I'm not a teacher

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,451


    Did you find this post helpful? Yes | No

    Default Re: Timing of heartbeat LED is off

    osccon = ( IRCF << 3) | SCS

    might work
    Warning I'm not a teacher

  4. #4
    Join Date
    Aug 2011
    Posts
    431


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Timing of heartbeat LED is off

    First off, you should use CON to define a numeric constant instead of DEFINE

    Next, since the intosc defaults to 500KHz at startup, that's outside the range of the 4xPLL which is spec'd from 4MHz-8MHz.
    While it might work, I'd leave the CONFIG setting for the PLL off and enable it when you change the osc freq

    Something like this should work:
    Code:
    #CONFIG
     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF 
     __CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF
    #ENDCONFIG
    
    DEFINE OSC 32
    ' OSCCON register settings
    SPLLEN CON %1           ' PLL enable
    IRCF   CON %1110        ' to enable 8 MHz
    SCS    CON %00          ' system clock determined by FOSC
    
    OSCCON = (SPLLEN<<7) | (IRCF<<3) | SCS

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,831


    Did you find this post helpful? Yes | No

    Default Re: Timing of heartbeat LED is off

    Thanks guys. I've been away for far too long.

    Tumbleweed's code worked on the first try.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. Timing out DT's Blinking Led
    By tazntex in forum General
    Replies: 3
    Last Post: - 28th May 2010, 17:41
  2. LED Bargraph chip (guitar LED bling-age) ..do with a PIC?
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 12th July 2009, 23:15
  3. Heartbeat LED
    By ecoli-557 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th March 2009, 14:05
  4. Replies: 3
    Last Post: - 5th December 2008, 15:00
  5. LED timing
    By elen-group in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th June 2008, 10:51

Members who have read this thread : 10

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