Ternary logic
Binary gives you 2^n states, ternary 3^n. This makes a real difference very quickly as 3 binary bits (2^3) is only 8 states, whist 3 ternary bits (3^3) gets you 27 ! To get a 64 state DAC we need 6 binary bits, whilst 4 ternary 'tets' gives us 81, and 5 ternary gives 243 v's 8 binary bits for 255.
With most PIC projects, i/o pins are in sort supply - so if we could build a 'ternary DAC' we would only need 5 i/o pins to get almost as many states (243) as a full byte using 8 i/o pins (256) !
Building a ternary DAC
Ternary logic needs 3 'states' = and PIC i/o pins have 3 distinct states !!
These are:-
Output Lo (typ 0.6v)
Output Hi (typ 4.3v) and
Output 'nothing' (high impedance, or 'tri-state') when the pin is set to input mode
To convert the 'nothing' into a 'half'** level voltage, a pair of 'low value' resistors (low value compared to the DAC 'chain' resistors) are used as a 'voltage divider' between +5v and Gnd. This holds the pin half way between '1' and '0' when it's switched to 'input' mode.
If Pin Lo is 0.6 and Hi is 4.3v, then Vhalf = (0.6+4.3/)/2 = 2.45v (to within 2%), however that's not quite the end of the story, since at high current (20mA) loads the pin output voltage may not reach 4.3v (nor go as low as 0.6v) and (as usual) actual device operation is likely to differ from the data sheet (which shows only the min Hi and max Lo).
Typical circuit
Unfortunately there seems to be no data on 'real world' PIC pin o/p voltages V's current, so I started with 'data sheet' values (using LTspice) and then measured actual performance with a 'breadboard' of the design
When the PIC pin is used as an output, the divider resistors will dominate the current draw. If we want to keep within 20mA**, Rdivider = 5/.02 = 250 ohms, or nearest E24 (5%) = 270 ohms (although we are using 5% resistors that's the 'absolute value' accuracy - in any 'random' batch you should be able to find 2 resistors making a 'matched pair' (i.e. correct ratio) to within the accuracy of your multimeter (typ 4 digits i.e. .1%) and that's all we need).
**The PIC has both a single pin current limit (20 or 25mA) and a 'total PORT' limit (typically 100mA). So you can build a 5 pin DAC at 20mA per pin on one PORT, but a 6 pin DAC (using 6 pins on the same PORT) means reducing the current demand on each to 100/6 = 16mA ..
Next consider the R-nR 'ladder'. For ternary 'chain' the ratios need to be 3R/4R (rather than R/2R). Since the 'chain' resistors must be high enough to avoid impacting the 'divider' resistor effect, the 'obvious' choice is 75k and 100k
Sensing the 'chain' voltage
The high values of the chain resistors means little current is available to 'sense' the voltage. The obvious approach is to use a high-input impedance Op-Amp in 'voltage follower' mode as a buffer.
Using a 100k per step (i.e per pin) 'chain', a 4 pin ternary DAC means a 400k 'chain'. A typical Op-Amp (LM741) has a typical input resistance of 2M Ohm, which is not insignificant compared to 400k
Reducing the 'chain' resistor values to (7k5 and) 10k gives us a 40k chain and means Op Amp input resistance can be ignored, however this means the effect of the voltage divider resistors (at 25mA these can't be less than about 133R each) becomes significant (i.e. will impact the accuracy of the result).
Again, the only way to design 'for real' is the simulate the circuit (eg using LTspice) and then breadboard it.
When the PIC pin is used as an output, the divider resistors will dominate the current draw. If we want to keep within 20mA, Rdivider = 5/.02 = 250 ohms, or nearest E24 (5%) = 270 ohms (although we are using 5% resistors that's the 'absolute value' accuracy - in any 'random' batch you should be able to find 2 resistors making a 'matched pair' (i.e. correct ratio) to within the accuracy of your multimeter (typ 4 digits i.e. .1%) and that's all we need).
Next we consider the resistor 'ladder'. For ternary, the ladder ratios need to be 3R/4R (rather than R/2R). Since the 'chain' resistors must be as high as possible (to avoid the 'divider' resistors effecting the voltage on the chain) but not so high that it's impossible to 'sense' the chain result (so needs to be lower than Op-Amp input resistance). One choice is 75k and 100k.
Final notes
The PIC pin output current limits places a limit on the 'divider' resistors (ideally, we would like these to be '1 ohm'). The higher the divider values, the higher the adverse effect on step accuracy. In practice this limits the ternary DAC to 3 or 4 bits.
For higher accuracy, we have to turn to a Hybrid design (ternary + binary). See my other Note.