Interfaces and Connectors
EBX-11 Reference manual
49
I
NITIATING AN
A
NALOG
C
ONVERSION
The following procedure can be used to initiate an analog conversion.
1.
Write 15h to the SPICONTROL register (I/O address 1D8h) – This value configures the
SPI port to select the on-board A/D converter, 16-bit frame length, low SCLK idle state,
rising edge SCLK edge, and automatic slave select.
2.
Write 30h to the SPISTATUS register (I/O address 1D9h) – This value selects 8 MHz
SCLK speed, hardware IRQ disable, and left-shift data.
3.
Write any value to SPIDATA2 (I/O address 1DCh) – This data will be ignored by the
A/D converter.
4.
Write the analog input channel number to bits 5-3 of SPIDATA3 (1DDh) – Any write
operation to this register triggers an SPI transaction.
5.
Poll the BUSY bit until the conversion is completed.
6.
Read the conversion data from SPIDATA2 (lower 8 bits) and SPIDATA3 (upper 4 bits).
Each analog conversion returns the conversion data from the previous conversion. The first
analog conversion after power-up or reset returns the data from ADCH0. The second conversion
returns the conversion data from the channel addressed in the first conversion. Each successive
conversion returns conversion data from the previous conversion.
This means that multiple conversions on the same A/D channel return valid data after every
conversion, starting with the second conversion. However, if a different channel is selected
between analog reads, two conversions will be necessary to return valid data from the new
channel. The analog input code example on page 50 shows how to use a 32bit SPI frame for an
automatic second conversion when only one sample is desired.
A
NALOG
I
NPUT
R
ANGE
Analog inputs are in binary format, 0 to +4.095V only.
The full analog input range is divided into 4096 steps. The output code (0000h) is associated
with an analog input voltage of 0 Volts (ground). All codes are considered positive.
Sample values are shown in the following table:
Table 26: Binary Data Format
0 to +5V
Input
Voltage
Hex
Decimal
Comment
>+4.095
–
– Out of range
+4.095
0FFFh
4095 Maximum voltage
+2.047
0800h
2048 Half scale
+1.023
0400h
1024 Quarter scale
+0.001
0001h
1 1 LSB
0.000
0000h
0 Zero (ground input)
StockCheck.com