PDA

View Full Version : How to Reset Osccal Value



greensasquatch
- 31st August 2008, 13:08
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

Pic2008
- 31st August 2008, 13:51
Your syntax is wrong. Type the following in the code:

OSCCAL = $30

Acetronics2
- 31st August 2008, 14:05
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

greensasquatch
- 31st August 2008, 14:48
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.

Acetronics2
- 31st August 2008, 14:55
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

Pic2008
- 31st August 2008, 16:21
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?

Acetronics2
- 31st August 2008, 19:04
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

Archangel
- 31st August 2008, 22:29
Here is a copy / paste from one of my programs 12F675:


POKECODE @$3FF, $50 ' reintroduces osscal correction data
' $3FF tells it where to code, $50 is the
' Cal value unique to each individual chip.

Pic2008
- 1st September 2008, 03:11
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.