12f509 and OSCCAL


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2005
    Posts
    16

    Default 12f509 and OSCCAL

    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

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2005
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Bruce explains it here for the 629 http://www.picbasic.co.uk/forum/show...SCCAL+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
    Last edited by mackrackit; - 18th October 2007 at 19:05. Reason: Slow connection while Bruce posted:)
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2005
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7


    Did you find this post helpful? Yes | No

    Exclamation programmer erasing osccal

    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.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    as most of you pros use commercial programmers and software,
    Yep, that is why I recommend the PICKIT2 and MPLAB.
    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?
    Dave
    Always wear safety glasses while programming.

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