Generating an Analog Output
There are three steps involved in performing a D/A conversion, or generating an analog output. Each step is
described in more detail, below. The descriptions use direct programming instead of driver software.
1. Compute the D/A code for the desired output voltage.
2. Write the value to the selected output channel.
3. Wait for the D/A to update.
Compute the D/A Code for the Desired Output Voltage
Use the formulas in the preceding section to compute the D/A code required to generate the desired voltage.
Note: The DAC cannot generate the actual full-scale reference voltage; to do so would require an
output code of 4096, which is not possible with a 12-bit number. The maximum output value is 4095.
Therefore, the maximum possible output voltage is always 1 LSB less than the full-scale reference
voltage.
Write the Value to the Selected Output Channel Registers
Use the following formulas to compute the LSB and MSB values.
LSB = D/A Code & 255 ;keep only the low 8 bits
MSB = int(D/A code / 256) ;strip off low 8 bits, keep 4 high bits
Example:
For,
Output code = 1776
Compute,
LSB = 1776 & 255 = 240 (0xF0)
and
MSB = int(1776 / 256) = int(6.9375) = 6
The LSB is an 8-bit number in the range 0-255. The MSB is a 4-bit number in the range 0-15.
The MSB is always rounded
down
. The truncated portion is accounted for by the LSB.
Write these values to the selected channel. The LSB is written to Base+6. The MSB and channel number are
written to Base+7 (MSB = bits 0-3, channel number,0-3 = bits 6-7).
outp(Base+6, LSB);
outp(Base+7, MSB + channel << 6);
Diamond Systems Corporation
Athena II User Manual
Page 80