Test For Presence of Internal Oscillator Calibration Word for PIC12F629
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.
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.
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.
Download HEX code (for use with either 12F629 or 12F675)
Source code ASM (if you want to see how it works)
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
JLCPCB Prototype: Only $2 for 10pcs 10×10cm, 24 hours Quick Turn, DHL Delivery in 3 days