16F631 and crystal problems


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86

    Default 16F631 and crystal problems

    I have been having problems with getting a 16F631 to operate correctly. I have tried both an internal and external oscillators. Under both circumstances the code seems to run 2 times faster or more. I have a very basic blinking LED program, 2 seconds on 2 off. I'm using PBP compiler 2.60.

    Code:
    @ __config _HS_OSC & _WDT_ON & _MCLRE_OFF & _CP_OFF & _IESO_OFF
    '@ __config _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF & _IESO_OFF
    
    Clear
    define osc 10
    'define osc 8
    
    OSCCON = %01101110       'external 10 mhz
    'OSCCON = %01111111         'internal 8 mhz
    
    ANSEL = 0               'set port to digital
    OPTION_REG.7 = 0        'enable pull ups on A and B
    
    TRISA = %011000         '
    TRISB = %11001111       '
    TRISC = %11111111       '
    
    PORTA = 0
    
    Pause 500
    fake_main:
    
        PORTA.0 = 0
        pause 2000
        PORTA.0 = 1
        pause 2000
                   
    goto fake_main
    
    end
    This problem is frustrating me and is probably either very obvious or very difficult.

    Thanks for the help

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 16F631 and crystal problems

    First, it is a good idea to turn off/disable the comparators:
    from the data sheet
    8.2.1
    COMPARATOR ENABLE
    Setting the CxON bit of the CMxCON0 register enables
    the comparator for operation. Clearing the CxON bit
    disables the comparator resulting in minimum current
    consumption.
    Then, if you are using a 10MHz external, do not use the OSCCON register.
    If using the internal then set OSCCON to 01110000 for 8MHz.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Re: 16F631 and crystal problems

    Hello Luckyborg,
    The aspstrophe ' symbol works in pbp to assign text as a comment, it supposedly does not work in assembly, and should be replaced with an semicolon ;
    '@ __config _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF & _IESO_OFF
    ;@ __config _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF & _IESO_OFF
    I would think MPASM would choke, who knows.
    EDIT: also DEFINES are "supposed" to be in all UPPERCASE LETTERS
    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.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: 16F631 and crystal problems

    The aspstrophe ' symbol works in pbp to assign text as a comment, it supposedly does not work in assembly, and should be replaced with an semicolon ;
    True when it's AFTER the @ symbol or Within and ASM/ENDASM block, it doesn't apply it the current case.

    But yes, OSC reswerved word HAVE TO BE IN UPPERCASE
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default Re: 16F631 and crystal problems

    Quote Originally Posted by mister_e View Post
    True when it's AFTER the @ symbol or Within and ASM/ENDASM block, it doesn't apply it the current case.

    But yes, OSC reswerved word HAVE TO BE IN UPPERCASE
    Hi Steve,
    Ok so that's the Magic, before the @ it works, after it doesn't, got it . . . for now Getting pretty foggy behind these eyes . . .
    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
    Feb 2009
    Location
    Southern California
    Posts
    86


    Did you find this post helpful? Yes | No

    Smile Re: 16F631 and crystal problems

    Thanks everyone. The problem was osc instead of OSC. The comparators are disabled on this chip by default, at least according to my 2006 preliminary datasheet I have, though I'll download the current version just to make sure nothing has changed. Can someone explain what
    Code:
    DEFINE osc 10
    would do, or is it just ignored? I've never intentionally used a DEFINE with anything other than a reserved word. Does it behave similar to
    Code:
    osc CON 10
    Thanks again for the help. I'm very glad it was under the something obvious category.

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 16F631 and crystal problems

    Yup, they are off by default, that is why I said, "a good idea". One line of code to be sure.

    DEFINE OSC XX 'Tells PBP the speed the chip is running at so it can calculate timing functions such as PAUSE.
    Dave
    Always wear safety glasses while programming.

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