PostHeaderIcon Copy Chip PIC16F87 Code: One Die, Two Ordering Codes

Semiconductor lines are built to sell several products from one design. A die is designed with a full complement of blocks, and the ordering codes select which blocks are tested, which are bonded to pins, and which are simply not there as far as the register map is concerned. The result is a set of parts that are nearly identical and not interchangeable.

This device is the trimmed variant of a pair. Its sibling carries an analogue-to-digital converter; this one does not. Everything else — the core, the array sizes, the serial port, the timers, the internal oscillator — is the same silicon. That makes a copy between the two almost free and occasionally catastrophic, and knowing which case you are in is a matter of reading a handful of instructions.

What differs and what does not

Element This device Sibling with converter
core and instruction set identical identical
program array size identical identical
data array size identical identical
analogue converter absent, registers unimplemented present, multi-channel
pin functions a subset a superset
configuration word layout identical identical

The important row is the fourth. An unimplemented register on this generation does not raise a fault and does not read as an error. It reads as zero, or as an undefined value, and the code that uses it continues executing with that value as though nothing were wrong.

The failure mode that makes this subtle

Suppose a product is written for the sibling, reads an analogue channel, compares the result against a threshold and takes a branch. Program that code into this device and the read returns zero every time. The comparison against the threshold now always takes the same branch, so the product behaves as though the measured quantity were permanently at one extreme.

Nothing crashes. Nothing resets. The device runs, its outputs are stable, and they are wrong in a way that looks like a sensor fault rather than a firmware mismatch.

That is the characteristic signature, and it is worth recognising because the same pattern appears whenever code crosses between variants: a peripheral that exists on one part and not the other produces a constant rather than an error, and the constant propagates silently.

Detecting the dependency before copying

Three checks decide whether an image can move to the trimmed variant, and they can all be done from the listing.

  1. Search for accesses to the converter’s control and result registers. Any read of a result register is a hard dependency.
  2. Search for configuration writes that enable the converter. Enabling a block that does not exist is harmless, but it usually sits next to a read, so it is a good marker.
  3. Search for pin assignments that differ between the variants. A pin that is analogue on the sibling and digital-only here changes the meaning of a port direction write.

Where all three come back clean, the image moves without modification. Where any of them is present, the image needs work, and the work is not a recompile — it is a substitution of the missing measurement with something the trimmed part can provide, or a decision that the trimmed part is the wrong choice.

What the configuration word does and does not decide

An assumption worth correcting: the configuration word does not tell the silicon which peripherals it has. Peripheral presence is a property of the die and its test, not of a configuration bit. The configuration word controls the oscillator, the watchdog, the brown-out threshold, the protection bits and the programming pin’s function.

That means the configuration word transfers unchanged between the two variants, which is convenient and slightly misleading. It transfers, and it says nothing about whether the code will work.

Where the variant difference matters to configuration is in pin function: on a part with fewer analogue inputs, some pins that the sibling treats as analogue are ordinary digital I/O, so a configuration that made sense on the sibling may leave a pin in a state the trimmed part handles differently.

Reading the array and identifying the variant

The identifier word distinguishes the two parts, and reading it is the first step of any copy that crosses variants. It is also the step people skip, because the packages look the same and the label is small.

On a device whose label is unreadable — which happens more often than one would expect on older stock — the identifier is the only reliable way to know which variant is in hand. Reading it before writing anything prevents the most expensive error in this class of work, which is programming a full-featured image into a trimmed part and spending a week diagnosing the resulting behaviour.

Copying in the other direction

Moving code from the trimmed variant to the full one is safe and is the common direction in practice. A product designed for this device runs unchanged on the sibling, because the sibling implements everything this one does and more.

Two caveats apply. The extra peripheral blocks are powered up in their reset state, which on some designs draws more current than the product’s supply budget allows until they are explicitly disabled. And the extra pins, where the packages differ, may be driven by the application in ways that conflict with the analogue function they now serve.

Neither is a reason not to do it, and both are reasons to state the direction of the copy in the delivery.

The delivery

  • the program image and the data image, with the variant identified
  • the configuration word decoded
  • an explicit statement of which variant was used as the source and which is the intended target
  • a list of any instructions that touch a peripheral absent on the target, by address
  • the identifier words from both devices, where both were available

The fourth item is the one that prevents the silent-constant failure. It converts a guess into a list.

For the same pair seen from the data side, where the byte-writable array and its access discipline are the subject, PIC16F88 data recovery covers the store. On the mid-range part where the analogue block is always present and the variant question does not arise, PIC16F627A binary copying covers the calibration byte instead. And for a family where the variants differ in array size rather than peripherals, changing the analysis entirely, PIC16F873A code recovery is the comparison.

The general lesson

Ordering codes within a family are not versions of one product. They are selections from a menu, and the menu changes what is present rather than what is enabled. Any copy that crosses a code boundary should begin with the identifier read and end with a list of peripherals the source used and the target lacks. Everything between those two steps is ordinary work; those two steps are what make the work correct.

Comments are closed.