19.4 Write the Value to the Selected Output Channel Registers

Use the following formulas to compute the LSB and MSB values from the D/A code. The calculation is the same for both 12-bit and 16-bit DAC.

LSB = D/A Code & 255 (keep only the low 8 bits)

MSB = int(D/A code / 256) (strip off low 8 bits, keep remaining bits)

The LSB is an 8-bit number in the range 0-255. For a 12-bit DAC, the MSB is a 4-bit number in the range 0-15, while for a 16-bit DAC the MSB is an 8-bit number in the range 0-255. The MSB is always rounded down. The truncated portion is accounted for by the LSB.

Example:

Output code = 1776 LSB = 1776 & 255 = 240 (0xF0)

MSB = int(1776 / 256) = int(6.9375) = 6 (always round down!)

The LSB is written to Base+6. For the 12-bit DAC, the MSB and channel number are written to base+7 (MSB = bits 0-3, channel number 0-3 = bits 6-7). For the 16-bit DAC, the MSB is written to page 2 base+14, and the channel is written separately to base+7. Accessing page 2 requires setting the page register in base+1. In addition, for a 16-bit DAC, the DAMODE bit must be set to configure the circuit for 16-bit data values.

Example for 12-bit DAC:

outp(base+6, LSB); outp(base+7, MSB + (channel << 6));

Example for 16-bit DAC:

outp(base+6, LSB);

outp(base+1, 2); // select page 2

outp(base+15, MSB); // write MSB to the MSB register in page 2

outp(base+7, channel << 6); // channel no. still goes in base+7 bits 7-6

Last updated