12f629 config settings


Closed Thread
Results 1 to 7 of 7
  1. #1

    Default 12f629 config settings

    Hi All

    I am experimenting with a 12F629 and as always don't want to mess things up without knowing exactly why I need to put certain lines of code in.

    So here are my questions (however simple it may seem to some)

    1.Assuming I am using the internal oscillator and all ports as digital IO what should the settings be ?

    2.Do I have the correct statemt in OPTION_REG for weak pullups off and is anything else needed ?

    3.What exactly is the TMRO prescale = 256 ? when would it be needed ?
    (And yes have the datasheet in front of me - but obviously not sinking in !)


    4.I noticed searching through the forums regarding the 12F629 this line DEFINE OSCCAL_1K 1 appears fairly often and what's a little confusing is why it's need if at all ?

    I was reading this post which added to the confusion [HTML]http://www.picbasic.co.uk/forum/showthread.php?t=1966&highlight=12F629+settings[/HTML]
    and this one [HTML]http://www.picbasic.co.uk/forum/showthread.php?t=543[/HTML] and the datasheet.. and a qucik flip through google too !

    Here's what I have so far
    Code:
    CMCON=7                'disable analog comparator
    GPIO=$00000000     
    TRISIO=$00000000
    INTCON=0               'interrupts off
    'or INTCON.6=0 ' Disable all unmasked Interrupts and  INTCON.7=0 ' Disable 'Global Interrupts
    OPTION_REG.7= 1 'weak pull-up's disabled
    osccon=%01100000 '4MHz internal clock
    define OSC 4 '4MHz
    Any info and/or help would be appreciated


    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Here is a sample using the MCLR pin as an input to blink LEDs on the 5 remaining pins.
    Code:
     DEFINE OSC 4
       @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
        CMCON=7 :TRISIO = %001000
        CHECK: GPIO = %000000
        IF GPIO.3 = 1 THEN  
        GOSUB RUN
        ENDIF :GOTO CHECK
        RUN:
        GPIO = %000001: PAUSE 50
        GPIO = %000010: PAUSE 50
        GPIO = %000100: PAUSE 50
        GPIO = %010000: PAUSE 50
        GPIO = %100000: PAUSE 50
        RETURN
    The weak pull-ups are automatically disabled on power up. Or when a pin is made an output.

    TRMO thing is for setting the duration of the timer. How often an interrupt triggered by the timer happens.

    The OSCCAL is just for fine tuning the internal OSC, I would say you only need to worry about it if you are doing some really time critical apps. But then you would be better off using an external OSC, needing more pins now, use different PIC....

    BTW... When you do a link, do not put it in a code tag. No longer clickable
    Last edited by mackrackit; - 1st December 2009 at 10:29.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Read the manual and search the datasheet for all occurences of OSCCAL.

    From p12 of the manual:
    Some PICmicro MCUs, such as PIC12C67x, PIC12CE67x and 12F6xx, have on-chip RC oscillators. These devices contain an oscillator calibration factor in the last location of code space. The on-chip oscillator may be fine-tuned by acquiring the data from this location and moving it into the OSCCAL register. Two DEFINEs have been created to perform this task automatically each time the program starts.

    Define OSCCAL_1K 1 'Set OSCCAL for 1K device
    Define OSCCAL_2K 1 'Set OSCCAL for 2K device
    From the datasheet:
    9.2.5.1 Calibrating the Internal Oscillator
    A calibration instruction is programmed into the last location of program memory. This instruction is a RETLW XX, where the literal is the calibration value. The literal is placed in the OSCCAL register to set the calibration of the internal oscillator. Example 9-1 demonstrates how to calibrate the internal oscillator. For best operation, decouple (with capacitance) VDD and VSS as close to the device as possible.

  4. #4


    Did you find this post helpful? Yes | No

    Default an even more confused human ...

    Thanks for the info as always Dave and Dave ;-)

    This still makes no sense to me ... I have combed the forums for some exaplanation as well..What am I missing ?

    So from according to the manual and datasheet the OSCCAL value 'calibrates and fine-tunes' the built-n RC oscillator but according to what ?

    Time servers synchronize themselves with a central time server or atomic click , but how does the PIC automatically calibrate it's own clock ?
    I will be reading this up asap.

    Having said that , this of courses raises the following question

    "When do I need to use the OSCCAL setting ?

    Is it a best practice to incorporate it in every program running on chips that have it ?

    Does it consume resources or is a power-on procedure ?

    Is it only crucial for critical time-based programs or applications ?

    Was it a manufacturing afterthought ?

    Why does it need to be done ? Is it because of the doping or stepping process or just the mere nature of an RC circuit ?

    Anyways that's my confusion ....

    Off on a journey of discovery now

    Kind regards

    Dennis

    Do we just choose and OSCCAL figure randomly ?
    Define OSCCAL_1K 1 'Set OSCCAL for 1K device
    Define OSCCAL_2K 1 'Set OSCCAL for 2K device

  5. #5
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    As the PIC is being manufactured, a laser is used to trim the RC components to establish the nominal frequency of the internal oscillator. The final step is to test it and write a calibration offset value to the highest location in memory. The Define OSCCAL instruction fetches that factory calibration value and plugs it into the OSCCAL register.

    AS long as you do not erase the value, this can be done each time the chip starts up. The melLabs programmers can be set so the calibration value does not get erased. If it does get erased, you can set OSCCAL by measuring the frequency and inputting the necessary offset. To do this you need to configure for the internal oscillator with clock out.

    You should perform the calibration whenever using time critical functions like RS232.

  6. #6


    Did you find this post helpful? Yes | No

    Default Spot On!!

    Thanks again Dave that explains it perfectly :-)

    Are there fast methods to determine the oscal as well as the current fuse setting of the pic by command line or otherwise ?

    Dennis

  7. #7
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    No. The configuration word is only accessible during programming. See section 9.1 of the datasheet.

    Why would you need to see the OSCCAL value? Just make sure you have set the programmer so it does not erase the last word and use the Define to load it into the OSCCAL register. It would behoove you to actually read and digest the manual and datasheet before asking so many meaningless questions.

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. 18F4550 Bootloader enter via eeprom setting
    By bradb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd November 2008, 23:51
  3. Error 0X0000008E when connecting a 18F2550 USB HID
    By FranciscoMartin in forum USB
    Replies: 8
    Last Post: - 16th October 2008, 17:20
  4. PortE problems (PIC18F4455)
    By RubenR in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 12th July 2006, 15:26
  5. Installation sequence
    By Demon in forum General
    Replies: 23
    Last Post: - 11th July 2006, 03:56

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