Anobium - 1 day ago

☕ Back at it with more PIC microcontroller madness! If you've been tweaking PICKitPlus INIs or ranting about oscillator calibration, buckle up – this post is a treasure trove (and a cautionary tale) straight from the debug trenches. I just dropped this gem: a quick analysis of programming pitfalls for the PIC12F683 that could save your next flash session.

Watch the intriguing video breakdown: Programming PIC12F683 – Hidden Dangers?.

It dives into the nitty-gritty of flashing your PIC12F683, but the real hook? This chilling note:

"Be very careful. Very. There is a good reason why this is all hidden. Take a note of your existing oscillator calibration value. Remember this is the factory value to support the internal oscillator."

Yikes – that's the kind of whisper that echoes in 3 AM debug sessions. The "hidden" bit? It's the Calibration Word at 0x2008, tucked away in config memory where casual programmers fear to tread. Mess with it, and your HFINTOSC goes from ±1% hero to timing villain. Factory settings are sacred... but not with this hack!

HEX Analysis: Decoding 0x2008

Diving into an Intel HEX export from PICKitPlus, the value at address 0x2008 clocks in at 0x20F8.
Pro tip: In HEX files, config words map to byte addresses – so low byte 0xF8 at 0x4010 + high byte 0x20 at 0x4011 = (0x20 << 8) | 0xF8 = 0x20F8.

This 14-bit word is your golden ticket (or ticking time bomb) for oscillator stability. Pulled straight from the PIC12F6XX Programming Spec (DS41204), here's the bit-by-bit autopsy:

Bit Value Field Description
13 0 Unimplemented (reads as 0)
12 0 FCAL6 Internal Oscillator Calibration bit 6
11 1 FCAL5 Internal Oscillator Calibration bit 5
10 0 FCAL4 Internal Oscillator Calibration bit 4
9 0 FCAL3 Internal Oscillator Calibration bit 3
8 0 FCAL2 Internal Oscillator Calibration bit 2
7 1 FCAL1 Internal Oscillator Calibration bit 1
6 1 FCAL0 Internal Oscillator Calibration bit 0
5 1 Unimplemented (reads as 0; here set to 1, possibly user-modified)
4 1 POR1 POR Calibration bit 1 (11 = highest POR voltage)
3 1 POR0 POR Calibration bit 0
2 0 BOD2 BOD Calibration bit 2 (000 = reserved; here 000)
1 0 BOD1 BOD Calibration bit 1
0 0 BOD0 BOD Calibration bit 0

Notes on the Register Value

  • FCAL<6:0> = 0b0100011 (0x23): This nudges your 8 MHz HFINTOSC slightly higher than the factory center trim. Factory spec? ±1% accuracy at 8 MHz (3.0–5.5V, 25°C), but it can drift to ±5% over full temp/voltage swings.
  • Reset Behavior: At power-on or reset, hardware slurps those FCAL bits straight into the osc circuitry – no code, no fuss. (No OSCCAL SFR here, folks – PIC12F683 keeps it hardware-only.)

The Catch

This register survives bulk erases and is Program/Verify mode only. Tweak it wrong? Scope your CLKOUT on GP4 and test. Always note your original before experimenting!

Runtime Tweaks: Don't Fear OSCTUNE

For in-code fine-tuning without risking the factory jewel, hit the OSCTUNE SFR (0x90 in Bank 1). Bits 4:0 (TUN<4:0>) give ±6.25% adjustment in ~0.3% steps – two's complement style:
- Default: 0x00 (factory bliss).
- Max boost: 0x0F (+6.25%).
- Max cut: 0x10 (-6.25%).

The changes kick in fast (~256 µs stabilize time), perfect for UART baud tweaks. Example from the datasheet vibes: Write to OSCTUNE in your init routine, then verify with a freq counter. For precision projects, pair it with that Timer1 operations.

Warning

This dialog shown in the video is "hidden" for a reason: One bad write, and your internal OSC is toast. Always backup!

Fueling the PIC Quest

Go to https://ko-fi.com/gcstudio and donate.

 
❤️
1

Last edit: Anobium 1 day ago