16.8 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 a 16-bit value and is read back in two 8-bit bytes. The LSB must be read from the board before the MSB because the data is inserted into the board’s FIFO in that order. Unlike other registers on the board, the A/D data may only be read one time, because each time an A/D sample is read from the FIFO, the internal FIFO pointer advances and that sample is no longer available. Reading data from an empty FIFO returns unpredictable results.

The following code illustrates how to read and construct the 16-bit A/D value.

LSB = inp(base);

MSB = inp(base+1);

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

The final value is interpreted as a 16-bit signed integer in the range -32768 to +32767. This numerical value is then converted to a voltage depending on the selected input range as explained below.

In scan mode, the behavior is the same except when the program initiates a conversion, all channels in the programmed channel range will be sampled once and the data will be stored in the FIFO. The FIFO depth register increments by the scan size. When STS goes low, the program should read out the data for all channels

Last updated