I was playing around a while ago with resistor ladders and plunked out a spread sheet with a HEX (or R2R) type ladder and compared that to a 4 bit weighted resistor array. You probably really don’t need more accuracy, but this is a different way of looking at it. It takes fewer resistors (only 4) and can be made to arrive at more values. There are over 50 different values of voltage instead of the 16 with the standard HEX style.
Basically you have three outputs on a PIC. High, Low and Tristate. So instead of binary, you get trinary. Instead of 16, you get 81 (but a lot end up being duplicates). You put a resistor in series with the outputs and then tie all four together. Use 4 different values. Now you can go through all the combinations of pulling some high, some low and tristating others.
The spread sheet shows some output graphs. The 4 yellow resistor values can be changed and the results viewed on the right. Plunk the ones you like into the yellow column by the CALC chart to view the sine curve. There is also a curve for “perfect” and HEX. These are superimposed below the tables.
Of course you would have to change the tables in Alan’s code to match the values that you have selected, and then add a table of TRIS bits, but it seemed kind of fun to play with.
It is not too often that you come across a trinary application.