PDA

View Full Version : 12f509 and OSCCAL



mwhatley
- 18th October 2007, 17:09
I've been searching through the various threads that address the oscillator calibration for this chip and I'm a bit confused. I've never used this chip before and I think I may have wiped out the calibration value during programming. I developed my program on a 16F684 using its internal 4 MHz osc but when I ported it over to the 509 the serial data is garbled. The scope show data at approximately the correct timing and sometimes a few correct characters make it through OK. So it seems like the timing is off just a bit.

The manual and several posts state that PBP handles the OSCCAL automatically. Does that mean that if I erase the chip prior to programming that somehow PBP puts the factory assigned value back into the OSCCAL register?

How does one go about "tweaking" the OSCCAL register?

Thanks all,
Mark

mackrackit
- 18th October 2007, 17:23
As been stated many times..The internal OSC may not be stable enough.

Getting a few correct characters would indicate this. Stick an external OSC on and see what happens.

mwhatley
- 18th October 2007, 18:06
Yes, I am aware of the importance of using a crystal. However, in this case, it is not possible. After I relealized what was probably happening I started programming the 509 without first erasing it. Those parts work fine. In fact I have used the internal oscillators in many other applications involving serial data up to 9600 baud without any problems. But that was always with parts that have a "precision 4 MHz" oscillator. Any project that would be subjected to large tempature extremes would certainly require a crystal.

So, back to my original question: How do I alter the value in the OSCCAL register?

Mark

Bruce
- 18th October 2007, 18:56
This one doesn't let you output the internal osc frequency/4 on OSC2, so you're pretty
limited on fine tuning the internal osc.

A somewhat easy way is to start off with 0 in OSCCAL, setup a simple loop sending serial
data to a PC terminal program, and slowly increment the value you're placing in OSCCAL
until you start receiving valid data on-screen.

I.E. serout OSCCAL = XX where XX is the value in OSCCAL while it's sending serial data to
the terminal window.

You'll start seeing vaild data for several different OSCCAL values. The one in the middle is
normally the one to go with since it gives a little room either way.

Jot down the middle OSCCAL value and manually load it into OSCCAL at power-up, or use
POKECODE @$3FF $xx where xx is the hex value to write back to the chip for the new osc
calibration value.

Most of the newer parts with 1% internal oscillators work pretty well, even for timing critical
serial applications, but don't get upset if it fails when the temperature shifts. That makes a
huge difference.

mackrackit
- 18th October 2007, 19:03
Bruce explains it here for the 629 http://www.picbasic.co.uk/forum/showthread.php?t=832&highlight=OSCCAL+register

I do not have the data sheet here for the 509 but it should be pretty much the same.

Slow connection while Bruce posted:)

mwhatley
- 19th October 2007, 16:11
I guess I was making it a lot harder than I thought it really was! I did not think I could write directly to the OSCCAL register. Many thanks to everyone. I will try the simple way this afternoon when I get back on that project.
73, Mark

nomad
- 20th October 2007, 01:27
After reading this and many other osccal posts, i thought i should mention an observation. as a newbie using a jdm programmer and free software off the net, i've found that several of these free software packages do NOT copy and restore the osccal! they simply erase it. as most of you pros use commercial programmers and software, you may not have noticed. the very first thing i did with my new programmer to the free 12f629 that came with it was erase it. figured it was new, nothing on it, safe move. lol yes, it erased the osccal value. when i get home next week i think i'll go through all those programs i tried and make a list of which ones erase osccal.

mackrackit
- 20th October 2007, 01:35
as most of you pros use commercial programmers and software,
Yep, that is why I recommend the PICKIT2 and MPLAB.:D
I know, $50 US is high with freight to some places in the world...
Maybe one of the moderators could put a "sticky" in the FAQ section warning about this?