This section describes the steps involved in generating an analog output (performing a D/A conversion) on a selected output channel using direct programming, without the driver software.
Perform an D/A conversion according to the following steps. Each step is discussed in detail, below.
A different formula is required for bipolar and unipolar output ranges.
Note: The DAC cannot generate the actual full-scale reference voltage, which would require an output code of 4096 that is not possible with a 12-bit number. The maximum output value is 4095. Therefore, the maximum possible output voltage is 1 LSB less than the full-scale reference voltage.
Output value = (Output voltage) / (Full-scale voltage) * 4096
Example:
Desired output voltage = 2.168V, full-scale voltage = 5V, unipolar mode (0-5V)
Output code = 2.168V / 5V * 4096 = 1776
Output value = (Output voltage) / (Full-scale voltage) * 2048 + 2048
Example:
Desired output voltage = -2.168V, full-scale voltage = 5V, bipolar mode (±5V)
Output code = -2.168V / 5V * 2048 + 2048 = 1160
Use the following formulas to compute the LSB and MSB values.
LSB = (D/A Code) AND 255. Keep only the low 8 bits
MSB = int((D/A code) / 256). Strip off low 8 bits, keep 4 high bits
Example:
Output code = 1776
LSB = 1776 AND 255 = 240 (F0 Hex)
MSB = int(1776 / 256) = int(6.9375) = 6
(In other words, 1776 = 6*256 + 240)
The channel number is 0-3 and must be inserted in bits 7-6 of the D/A MSB byte, written to Base+5.
Example:
MSB = MSB + Channel * 64
To update the DAC, set DASIM bit to 0. This performs an update of the current channel and all previously latched channels, causing a simultaneous update. If no other channels were previously latched, this only updates the current channel. To latch the channel set DASIM bit to 1.
Update example:
MSB = MSB & 0xDF
Latch example:
MSB = MSB + 32
The LSB is written to Base+4 and the MSB/channel no. is written to Base+5. If you are using enhanced features be sure to enable enhanced features before writing to the registers.
DACBUSY = 1 for 10mS while the data in registers Base+4 and Base+5 are serially shifted into the D/A chip. After DACBUSY returns to 0 you can write to register Base+4 and Base+5. Registers Base+4 and Base+5 should NOT be written to while DACBUSY = 1. When updating multiple channels for simultaneous update repeat steps 1 to 6, as shown in the following example.
Example:Using the bipolar mode formula, we compute D/A code = 3V / 5V * 2048 + 2048 = 3276.8.
Round this up to 3277. (Binary value = 1100 1100 1101)
LSB = 3277 & 255 = 205 (Binary value = 1100 1101)
MSB = int(3277/256) = 12 (Binary value = 1100)
MSB = 12 + 1 * 64 = 76
To update: MSB = MSB & 0xDF
To latch: MSB = MSB + 32
outp(Base + 8, 3); //select page 3
outp(Base + 15, 0xA6); //enable enhanced features
outp(Base + 4, LSB);
outp(Base + 5, MSB);
while (inp(Base + 4) & 0x80);