V3.x Calibration Procedure

A project log for TritiLED

Multi-year always-on LED replacements for gaseous tritium light sources

Ted YapoTed Yapo 01/23/2018 at 04:270 Comments

I added some code in GitHub for calibrating the V3.x boards.  Since the inductor has a +/-30% tolerance, the brightness and runtime can vary significantly from board to board.  These differences are easily calibrated out by running a little python script I wrote that calculates a calibration table.

There are just a few steps required to calibrate a newly assembled V3.x board:

1. Run The Calibrator Image

Download the calibrator.hex image.  This image runs the LED at three different brightness levels, 16 seconds each.  When the image is running, record the currents (in uA) consumed at each brightness.  In one recent test run, I recorded the following:


These correspond to hard-coded blink frequencies of 100, 200, and 400 Hz.  Save these three current measurements in a file called currents.dat.  The C-code source for this image, calibrator.c, is in GitHub.

2. Run the Calibration Script

The python script,, reads the currents.dat file you just created, fits a line to current vs frequency, and calculates the frequencies for 1-10 year run times.  The script pops up a window with the plot shown above so you can check the calibration.  All three points should be on the line.  Once you close the plot window, the script generates a header file called modes.h:

#define N_MODES 10
struct run_time period_table[N_MODES] = {
  {1, (int)(31000./262.124721 + 0.5)},
  {2, (int)(31000./124.768381 + 0.5)},
  {3, (int)(31000./78.982934 + 0.5)},
  {4, (int)(31000./56.090211 + 0.5)},
  {5, (int)(31000./42.354577 + 0.5)},
  {6, (int)(31000./33.197487 + 0.5)},
  {7, (int)(31000./26.656709 + 0.5)},
  {8, (int)(31000./21.751126 + 0.5)},
  {9, (int)(31000./17.935672 + 0.5)},
  {10, (int)(31000./14.883309 + 0.5)},

3. Compile the Calibrated Hex File

The tritiled_v30_selectable_runtime.c code automatically includes the generated modes.h file, so you just have to recompile to create a calibrated hex file for the board.  Once you recompile, program the hex image to the board, and it's done.

If you want, you can verify the current drain for the various modes.

That's it.  It shouldn't take more than a few minutes to calibrate your board.

I originally had a script that would do this all automatically, but my PICkit3 has proven to be a little unreliable.  I often have to reset it before it will program correctly.  It could be that my particular programmer is flaky, some incompatibility with linux, or something else, but it was just too frustrating.  The new calibration process is simple, quick, and gives good results, so I'm going to leave it at that.