PDA

View Full Version : 12f629 config settings



Dennis
- 30th November 2009, 22:44
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
http://www.picbasic.co.uk/forum/showthread.php?t=1966&highlight=12F629+settings
and this one
http://www.picbasic.co.uk/forum/showthread.php?t=543 and the datasheet.. and a qucik flip through google too !

Here's what I have so far


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

mackrackit
- 1st December 2009, 10:26
Here is a sample using the MCLR pin as an input to blink LEDs on the 5 remaining pins.


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 :)

dhouston
- 1st December 2009, 12:54
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.

Dennis
- 1st December 2009, 20:14
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

dhouston
- 1st December 2009, 21:13
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.

Dennis
- 1st December 2009, 21:30
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

dhouston
- 1st December 2009, 22:39
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.