Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC12F629 Band Gap & OSCCAL

Status
Not open for further replies.
Hey Everyone

I've used the PIC12F629 before but never really undertood the band gap bits of the config word. But I realise I don't really need to.
629 Configuration Word (from data sheet)JPEG: PIC12F629 675 Config Word1.jpg

Also, from what I understand the Band Gap, along with the OSCCAL are pre set at the factory.
After some hunting around I understand from the [URL='https://ww1.microchip.com/downloads/en/DeviceDoc/41191D.pdf']629 Programming Spec[/url] (found on the 629 page of microchip.com) that the programming device (PICkit2 in my case) should in fact save the Band Gap and the OSCCAL values, and re-write them after the program cycle is complete to ensure they remain unchanged.
The flow chart on page 13 in the spec I've linked above makes it pretty clear.

So the band gap has something to do with the Brown Out reset thresholds or whatever. cool.
Question 1: The 2 Band Gap bits are the 2 Msb's of the config word so does it not matter what you attempt to write to the config word in regards to these 2 bits? Will they be restored to what they were prior to erasing anyway? (If the programmer meets microchips programmers spec). I mean, is it possible to mess the factory set BG bits up, (other than by means of using a programmer that does not save and restore these bits during erasing/programming cycles)

And the OSCCAL is fairly self explanatory; It calibrates the int osc.
But the data sheet and the 629 programming spec I've linked above seem to refer to the OSCCAL as 2 different things.
1: The programming spec refers to is as a RETLW instruction stored in the last address of the program memory at 0x03FF where the 8 Lsb's of the 14 bit word is the factory set osc cal (which I have had a play with and read this location with the 3 629's I own), and,
2: The data sheet has an OSCCAL register located at 90h in bank 1 (where only 6 bits are implemented)
629 OSCCAL Register (from data sheet)JPEG:PIC12F629 675 OSCCAL Register1.jpg

So Question 2 is, what is the deal with OSCCAL ?
I understand what it does, but is the OSCCAL at 90h just another means of fine tuning the int osc on top of the already factory set value at 0x03FF? Or are they related?

Jake.
 

Attachments

  • PIC12F629 675 Config Word.jpg
    PIC12F629 675 Config Word.jpg
    661.4 KB · Views: 1,145
  • PIC12F629 675 OSCCAL Register.jpg
    PIC12F629 675 OSCCAL Register.jpg
    216.3 KB · Views: 1,023
If I remember this correctly... The pic12f6xx has a 4Mhz internal oscillator.. The OSCAL value is calculated and placed at location 0x3FF... If you do not need the prescision you don't need to fetch it.. However! If you need to use the baud rate generator or anything that requires the tuned oscillator setting, you need to fetch the value and place it in the OSCAL reg every time you boot... If you clear the flash, you can recalculate the value with pickit2...

I use a pic12f675 as a touch panel interface and send the resistive values via RS232.. Without the value the baud is miles out!!

I'm hoping if I'm wrong someone will assist, As this may not be the case in this thread!!
 
Thanks Ian, that makes a lot of sense.
So the value in 0x03FF won't be larger than 6 bits? So it can be written straight to OSCCAL at 90h?
Although I wonder why OSCCALs 6 bits are left justified (bits 0&1 unimplemented)
 
Many programs do a call to the last memory location as the first instruction, so if the calibration word gets erased, a return from call never happens and the program counter rolls around to location 0, which effectively is the reset location.

Then the first instruction is to call the last location....... in an infinite loop.

...so the effect of losing the calibration word is to prevent your program from running.

So either make sure that your calibration is ALWAYS valid, or as others have suggested use another PIC.

Even PIC12F683 is a huge improvement, later pics even better. No calibration needed, so no calibration word to lose, hence never an issue.
 
i am new to pic microcontroller programming. I am facing the same issue. I simulate my program in proteas. it works fine. But when i try to program it using pickit2 my band gap values changes from 1000 to 0000. Please tell me what is the easiest way to set the band gap values. thanks in advance.
 
Status
Not open for further replies.

Latest threads

Back
Top