Diamond Power Products MM-48-AT User Manual

Page 29

Advertising
background image

Diamond-MM-48-AT User Manual V1.01

Page 29

8.3 Trigger an A/D conversion on the current channel

After the above steps are completed, start the A/D conversion by writing a 1 to the ADSTART
bit in Base + 8. This write operation only triggers the A/D if the CLKEN bit is 0 to disable
hardware triggering and enable software triggering. Otherwise the A/D will only trigger when
the selected clock or trigger signal occurs. CLKEN should always be 0 when controlling A/D
conversions in software.

8.4 Wait for the conversion to finish

The A/D converter takes up to 5 microseconds to complete a conversion. Most processors
and software can operate fast enough so that if you try to read the A/D converter immediately
after writing to base + 0, you will beat the A/D converter and get invalid data. Therefore the
A/D converter provides a status signal ADBUSY to indicate whether it is busy or idle. This bit
can be read back as bit 7 in the status register at Base + 9. When the A/D converter is busy
(performing an A/D conversion), this bit is 1, and when the A/D converter is idle (conversion
is done and data is available), this bit is 0. Here is a pseudocode explanation:

Status = read(base+9) AND 128 // or Status = read(base+9) AND 80 Hex

If Status = 0 then conversion is complete, else A/D converter is busy

Keep repeating this procedure until Status = 0.

8.5 Read the data from the board

Once the conversion is complete, you can read the data back from the A/D converter. The
data is 16 bits wide and is read back in two 8-bit bytes. The following pseudocode illustrates
how to construct the 16-bit A/D value from these two bytes:

LSB = read(base)

MSB = read(base+1)

Data = MSB * 256 + LSB // combine the 2 bytes into a 16-bit value

The final data is interpreted as a signed value ranging from –32768 to +32767.

Note: The data range always includes both positive and negative values, even if the board
is set to a unipolar input range. The data must now be converted to volts or other engineering
units by using a conversion formula as shown on the next page.

Advertising