
Hercules-EBX CPU User Manual V1.02
Page 81
12.2.4 PERFORM AN A/D CONVERSION ON THE CURRENT CHANNEL
After the above steps are completed, start the A/D conversion by writing to Base + 15, bit 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 +15,0x01);
12.2.5 WAIT FOR THE CONVERSION TO FINISH
The A/D converter chip takes up to either 4 or 9 microseconds to complete one A/D conversion,
depending on the scan interval setting (Base + 12 : bit 3). Most processors and software can
operate fast enough so that if you try to read the A/D converter immediately after starting the
conversion, 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 “A/D Range/Status Readback Register“ at Page 0 : Base+4. When the A/D
converter is busy (performing an A/D conversion), this bit is 1 and the program must wait. When
the A/D converter is idle (conversion is done and data is available), this bit is 0 and the program
may read the data. Here are examples:
while (inp(base+4) & 0x80);
// Wait for conversion to finish before proceeding
This method could hang your program if there is a hardware fault and the bit is stuck at 1. Better
is to use a loop with a timeout:
int checkstatus()
// returns 0 if ok, -1 if error
int
i;
for (i = 0; i < 10000; i++)
{
if !(inp(base+4) & 0x80) then return(0);
// conversion completed
}
return(-1);
// conversion didn’t complete
12.2.6 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 can be read back as either two 8-bit bytes or one 16-bit word. For 8-bit
accesses, 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, since each time a byte is read from the FIFO, the FIFO’s internal pointer
advances, and that byte is no longer available. Note that reading data from an empty FIFO
returns unpredictable results.
The following pseudo-code illustrates how to read and construct the 16-bit A/D value with 8-bit
accesses:
LSB = inp(base);
MSB = inp(base+1);
Data = MSB * 256 + LSB;
// combine the 2 bytes into a 16-bit value
Alternatively, the value can be read as one 16-bit value (which is preferred – this would increase
the overall system bandwidth while reading data from the FIFO):
Data = inpw(base);
// Where the MSB and LSB are all read in one access
Содержание HERCULES-EBX HRC400-5A128
Страница 9: ...Hercules EBX CPU User Manual V1 02 Page 9 3 HERCULES BOARD DRAWING...
Страница 118: ...Hercules EBX CPU User Manual V1 02 Page 118 Figure 14 Hercules EBX Cable Kit...
Страница 121: ...Hercules EBX CPU User Manual V1 02 Page 121...
Страница 123: ...Hercules EBX CPU User Manual V1 02 Page 123...