Test For Presence of Internal Oscillator Calibration Word for PIC12F629

Description

The PIC 12F629 and 12F675 devices have an internal 4Mhz oscillator that enables the devices to be used without an external crystal or RC network. This frees up one or two pins for I/O use and allows the device to be built into minimum component count designs. Additionally, the devices undergo an Internal Oscillator Calibration Test to ensure accurate timing and reliable performance.

Problems arise if by accident or otherwise, the factory programmed oscillator calibration word, located at program memory address 0x3FF is erased or over written.  If application code tries to read the calibration word and it has been erased, the code will normally crash.

It turns out that erased calibration words on the 12F629/675 PIC are the cause of almost all queries relating to code on my website that uses a 12F629/675.  People using JDM type programmers and associated software seem to have this problem more than most.  This is, in part I suspect, due to the free software / cheap hardware used by the JDM programmer that attracts inexperienced users.

Internal Oscillator

My advise to people with problems is to put the PIC into their programmer hardware and read out the program memory to see if the calibration word is present.  However, experience again shows that many users just become even more confused so I’ve written this application to give a quick Good/Bad test of the calibration word.  There’s also an optional bit of hardware that will display the value of the calibration word if it’s present.


How it works

If the calibration word has been erased, when the application code tries to read it, instead of returning with the calibration value, it wraps back round to the start of program memory as if it had been reset.  When the PIC starts after a Power-on-reset (POR)  certain internal registers are initialised to known values.  If the code wraps back round to the reset vecotr because of a missing calibration word, unlike the Power-on-reset, these registers are not initialised.

The application use the fact that this wrap-around doesn’t affect the internal registers so if we alter the value in a specific register after a power-on-reset we can tell if it has had a Power-on-reset or the code has wrapped back round due to a missing calibration value.

The code indicates the result of the test as Good/Bad by blinking an LED; green LED meaning the calibration word is present, and red LED if it has been erased.

With some extra hardware around a 74HC595 it can also display the value of the calibration word, if present, as a binary number using eight LEDs.  This is optional and the good/bad test works without it being present.

For the basic calibration good / bad test, you only need to build the circuit on the left of the dotted line in the schematic. I deliberately kept it simple so you can quickly and easily build the test circuit.

The circuit around 74HC595 is only used to display the binary value of the calibration word. I added it for a bit of fun, you don’t need it if you just want to test for the presence of the calibration word.

Software

Download HEX code  (for use with either 12F629 or 12F675)

Source code ASM (if you want to see how it works)

For more detail: Test For Presence of Internal Oscillator Calibration Word for PIC12F629

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter