
Hercules III User Manual Rev A.2
www.diamondsystems.com
Page
67
14. PERFORMING AN A/D CONVERSION
14.1
Introduction
This chapter describes the steps involved in performing an A/D conversion on a selected input channel using
direct programming (without the driver software). Perform an A/D conversion according to the following steps,
each step is discussed in detail below.
5.
Select the input channel.
6.
Select the input range.
7.
Wait for analog input circuit to settle.
8.
Initiate an A/D conversion.
9.
Wait for the conversion to finish.
10.
Read the data from the board.
11.
Convert the numerical data to a meaningful value.
14.2
Select the Input Channel
To select the input channel to read, write a low-channel/high-channel pair to the channel register at Base+2. The
low four bits select the low channel, and the high four bits select the high channel. When you write any value to
this register, the current A/D channel is set to the low channel.
For example, to set the board to channel 4 only, write 0x44 to Base+2). To set the board to read channels 0
through 15, write 0xF0 to Base+2.
When you perform an A/D conversion, the current channel automatically increments to the next channel in the
selected range. Therefore, to perform A/D conversions on a group of consecutively-numbered channels, you do
not need to write the input channel prior to each conversion. For example, to read from channels 0 - 2, write 0x20
to base+2. The first conversion is on channel 0, the second will be on channel 1 and the third will be on channel
2. The channel counter wraps around to the beginning so the fourth conversion will be on channel 0, again.
If you are sampling the same channel repeatedly, set both high and low to the same value as in the first example,
above. On subsequent conversions, you do not need to set the channel again.
14.3
Select the Input Range
Select the input range from among the available ranges. If the range is the same as for the previous A/D
conversion it does not need to be set again. Write this value to the input range register at Base+3.
For example, for ±5V range (gain of 2), write 0x01 to Base+3.
14.4
Wait for Analog Input Circuit to Settle
After writing to either the channel register, Base+2, or the input range register, Base+3, allow time for the analog
input circuit to settle before starting an A/D conversion. The board has a built-in 10µS timer to assist with the wait
period. Monitor the WAIT bit at Base+3, bit 5. When the bit value is 1, the circuit is actively settling on the input
signal. When the value is 0, the board is ready to perform A/D conversions.
14.5
Perform an A/D Conversion on the Current Channel
After the above steps are completed, start the A/D conversion by writing to Base+0. This write operation only
triggers the A/D if AINTE = 0 (interrupts are disabled). When AINTE = 1, the A/D can only be triggered by the on-
board counter/timer or an external signal. This protects against accidental triggering by software during a long-
running interrupt-based acquisition process.
outp(base,0x80);