PostHeaderIcon PIC18F43K22: Duplication Is a Matching Problem, Not a Copying One

Copying is a transfer. Duplication is a correspondence, and the correspondence has four dimensions: the program, the configuration, the data array, and the physical device. A copy addresses one of them. Most duplication failures are the other three.

The 43K22, with eight kilobytes of program memory in a 40-pin package, is a good case to reason about because the array is small enough that everything else is proportionally larger.

The four dimensions

Dimension Reproduced by Fails as
Program array Programming the image Code runs but behaves differently
Configuration Writing config explicitly Wrong clock, watchdog, or boot behaviour
Data array Copying, or leaving blank deliberately Measurement offset, wrong settings
Silicon Nothing — it is a property of the part Small consistent differences

The fourth is the one that cannot be closed, and pretending otherwise wastes time. Analog trim and silicon revision belong to the die. A duplicate is therefore an approximation whose error is bounded by those two factors, and the practical question is whether the bound is acceptable for the application.

Configuration: the dimension that is usually skipped

Programmers treat configuration as a setting rather than as content, and tools reinforce this by offering it as a separate operation. A hex file exported from the array may or may not include it.

The result is a device that boots, runs the code, and differs in ways that are hard to attribute:

  • Watchdog enabled on one and not the other, which shows up as a device that resets under load.
  • Different oscillator source, which shifts every timing relationship.
  • Different brown-out threshold, which changes behaviour at low supply.
  • Different low-voltage programming setting, which changes how the device can be entered later.

Each of these is a field in the configuration word, each is comparable, and none is in the code.

Data array: decide, do not default

The small data array on this family holds whatever the application decided to keep: settings, offsets, counters, sometimes a copy of the serial number.

Three choices, and the honest one depends on purpose:

  • Copy the original’s array. The duplicate behaves like the original, including its accumulated state.
  • Leave it blank. The firmware writes defaults; whether that is correct depends on the design.
  • Write a known set. Correct when the values are documented and reproducible.

Choosing by default — that is, leaving it blank because nothing was decided — is the most common of the three and the least defensible.

What a duplicate cannot fix

Two differences survive any amount of care:

Trim. Analog blocks carry per-die trim. A duplicate that measures a small offset from the original is showing trim, not a code error. The fix is recalibration, not reprogramming.

Revision. Errata differ between revisions, and firmware written to avoid a specific erratum may behave differently on a die where the erratum does not exist — or vice versa. On a device this size the effect is usually small and occasionally decisive.

Recording the revision at duplication time is cheap and answers the question later.

Verifying a duplicate

The verification that matters compares behaviour, not files:

  1. Program the image and the configuration; write or deliberately omit the data array.
  2. Read everything back and compare against the record.
  3. Run both devices on the same inputs and compare outputs at every accessible point.
  4. Compare timing, not just values — a duplicate that produces the right answer late is not a duplicate.
  5. Run the fault cases the original was known to handle.

Step four catches configuration differences that step three misses, because a wrong oscillator often changes timing before it changes logic.

When duplication is the wrong tool

If the firmware depends on a per-die value — a unique identifier used in a key, a trim value baked into a calculation — copying produces a device that runs and computes differently. In that case the work is to understand the dependence, which is a reconstruction problem rather than a duplication one.

Deciding this before starting requires reading the program. On a device where that is impossible, the dependence can often be detected from behaviour: a duplicate that works in every mode except one is usually hitting a per-die assumption in that mode.

Related reading

FAQ

Does copying the array duplicate the device? It duplicates one of four dimensions. Configuration, data and silicon remain.

Why does a duplicate reset under load? Usually a watchdog setting that differs from the original’s.

Should the data array be copied? Only if the duplicate must reproduce the original’s accumulated state.

Can trim be transferred? It can be written, but it belongs to the die, so the result measures like the source silicon.

How is a duplicate verified? By comparing outputs and timing on identical inputs, and by exercising the fault cases.

Conclusion

Duplication on this part is a four-dimensional matching problem in which the easiest dimension is the one everyone does. Configuration, data array and silicon decide whether the second device is a duplicate or merely a device with the same program — and only behavioural verification distinguishes the two.

Comments are closed.