How to Reset Osccal Value


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2008
    Location
    British Columbia, Canada
    Posts
    20

    Default How to Reset Osccal Value

    I've done a fairly thorough search in the forum already on osccal. Because of this i now know how to read the value from my chip and to write it on the bottom using liquid paper before I erase anything (thanks!).

    My problem is that while my programmer PICPgm usually leaves osccal alone when programming this last write it has has changed the value on me and I cannot figure out how to get it back.
    The value i originally read from my 12f675 was "0x3430" (now shows 0x34FF) and from what I have read in the forums the last two digits "30" is the osccal value.

    From reading the PBP Manual I see that to restore a value one uses something like:

    DEFINE OSCCAL = $a0 '(though I replaced a0 with my value of 30)

    However when I try to compile this I get a syntax error.
    I'm sure this is something simple and it would be nice to have the correct method documented here for newbies such as myself.

    Thanks
    -Justin

  2. #2
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Post

    Your syntax is wrong. Type the following in the code:

    OSCCAL = $30

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink Reset, Restore, or Modify ???

    Hi,

    First ... restoring ( when genuine value is lost) an Osccal value is not so simple.
    The simplest way is to use the Pickit2 ( from µChip ) that has this feature already automated ( see the price, and talk after ... LoL )


    Now Reset ... I suppose it is to write the genuine value to its location ...

    0x3430 means RETLW 30 ( value is $30 )

    DEFINE OSCCAL is just to tell the Pic to read the Osccal value ( does not write anything )

    so, you could use

    ************************************************** ***************************
    END
    '************************************************* ****************************

    @ ORG 3FFh
    @ RETLW 30h

    at the end of your program.

    Note the two last lines must be placed AFTER the END !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Aug 2008
    Location
    British Columbia, Canada
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Thank you Acetronics.

    I added
    @ ORG 3FFh
    @ RETLW 30h
    to the end of my program it compiled and increased the program length from 102 words to 1024 words I assume this is due to the fact that the osccal value is at the end of the chip memory.

    However when I tried to burn the HEX file I get errors. Which leads me to conclude I must have fried part of the chip at some point (like when I plugged it into the breadboard wrong and it got hot and almost burnt my fingers).

    I'll think I'll have to junk this chip but it is extremely helpful to know how to make changes like this, thanks again.


    Also thanks to Pic2008 for pointing out my syntax error.
    -Justin

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Pic2008 View Post
    Your syntax is wrong. Type the following in the code:

    OSCCAL = $30

    Hi,

    You sure ???


    From a µChip Datasheet ...

    2.2.2.7 OSCCAL Register
    The Oscillator Calibration register (OSCCAL) is used to
    calibrate the internal 4 MHz oscillator. It contains 6 bits
    to adjust the frequency up or down to achieve 4 MHz.
    The OSCCAL register bits are shown in Register 2-7.
    REGISTER 2-7: OSCCAL — OSCILLATOR CALIBRATION REGISTER (ADDRESS: 90h)

    Legend:
    R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
    - n = Value at POR ’1’ = Bit is set ’0’ = Bit is cleared x = Bit is unknown
    R/W-1 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0
    CAL5 CAL4 CAL3 CAL2 CAL1 CAL0 — —
    bit 7 bit 0
    bit 7-2 CAL5:CAL0: 6-bit Signed Oscillator Calibration bits
    111111 = Maximum frequency
    100000 = Center frequency
    000000 = Minimum frequency
    bit 1-0 Unimplemented: Read as '0'
    Legend:
    R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
    - n = Value at POR ’1’ = Bit is set ’0’ = Bit is cleared x = Bit is unknown
    Alain
    Last edited by Acetronics2; - 31st August 2008 at 14:57.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi,

    You sure ???



    Alain
    Yes, I'm sure. greensasquatch pointed that the original value from the chip is 30H.

    greensasquatch, without writing @ ORG 3FFh and @ RETLW 30h, have you tried the method I have written here?

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Not so sure ...

    as you write the cal value in a "non protected" memory location and not at the end of the program memory ...

    you'll lose the cal value if you use the '675 for another program.

    so it's much better to write it at the end of the program memory, as programmers will read it ( and preserve it ) if you do not remember what you had done ... some weeks later.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Here is a copy / paste from one of my programs 12F675:
    Code:
    POKECODE @$3FF, $50  ' reintroduces osscal correction data
                             ' $3FF tells it where to code, $50 is the
                             ' Cal value unique to each individual chip.
    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.

  9. #9
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Thumbs up

    Quote Originally Posted by Acetronics View Post
    Hi,

    Not so sure ...

    as you write the cal value in a "non protected" memory location and not at the end of the program memory ...

    you'll lose the cal value if you use the '675 for another program.

    so it's much better to write it at the end of the program memory, as programmers will read it ( and preserve it ) if you do not remember what you had done ... some weeks later.

    Alain
    There are two ways of doing it, either write to the OSCCAL directly or like you said, write at the end of program memory at 0x3FF.

    Good point.

Similar Threads

  1. IC12F508 with Internal Oscillator and Software Reset
    By karan123 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd October 2009, 16:13
  2. pic reset sometimes
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 23rd January 2008, 17:27
  3. Software Driven Reset Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th April 2005, 00:53
  4. reset and interrupt vectors
    By dtoohey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th February 2005, 22:02
  5. Replies: 5
    Last Post: - 1st December 2004, 12:49

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