Anda di halaman 1dari 4

ADC 4ch

________________
+ |
|
__|__
|
___
9 V
|
_____ battery
|
___
|
|
|
|
|
__|__
<
___
>
1 K Resistor
_
<
>
Parallel Printer Port:
|
(pin numbers shown are
| 1
for DB25 male plug)
_______|_________
|
V+
| 12
2
|
clk |----------------o D0
Inputs:
|
| 2
3
3 |
cs' |----------------o D1
A0 o----------| in0
| 13
4
4 |
din |----------------o D2
A1 o----------| in1
| 10
10
5 |
dout |----------------o Acknowledge
A2 o----------| in2
| 7
18
6 |
dgnd |----------------o Ground
A3 o----------| in3
|
|
8 |
|
|
Gnd o----------| agnd
|
__|__
|
|
___
| ADC0833CCN
|
_
| A to D Conv.
|
|
|
| vcc
vref/2 |
|_________________|
| 7
| 9
|
|
|
| +2.5 V
__|__
|
0.1 uF _____
|
Disc
|
|
Capacitor |
| +
|
____|___|
|
| / \
|
/
\
LM336Z-2.5
|
/_____\
Precision Reference IC
|
|
|
| ----------|
__|__
___
_

{-------- ADC driver ANALOG.PAS -------}


unit analog;
interface
{-------- User-modifyable constants ------}
const

nlpt = 1; {printer port number}


vref = 2.5; {reference voltage for ADC}

{-------- Read an ADC channel --------}


function analog_read (ch: integer): real;
implementation
var

in_addr, out_addr: word; {i/o addresses}

const
cs = 2; {ADC chip select line}
di = 4; {ADC data input line}
clk = 1; {ADC clock line}
dout = 64; {ADC data output line}
a: array[0..3] of byte = {Channel select word, bit #1}
(0,di,0,di);
b: array[0..3] of byte = {Channel select word, bit #2}
(0,0,di,di);
{-------- Read an ADC channel --------}
function analog_read (ch: integer): real;
var
result: byte;
i: integer;
begin
{transmit chip setup sequence as per ADC0833 data sheet}
port[out_addr]
port[out_addr]
port[out_addr]
port[out_addr]
port[out_addr]
port[out_addr]
port[out_addr]
port[out_addr]
port[out_addr]
port[out_addr]
port[out_addr]

:=
:=
:=
:=
:=
:=
:=
:=
:=
:=
:=

0;
di;
di + clk;
di;
di + clk;
di;
a[ch];
a[ch] + clk;
b[ch];
b[ch] + clk;
di;

port[out_addr]
port[out_addr]
port[out_addr]
port[out_addr]

:=
:=
:=
:=

di + clk;
di;
di + clk;
0;

{the main conversion loop}


result := 0;
for i := 1 to 8 do begin
result := result*2;
port[out_addr] := clk;
if port[in_addr] and dout <> 0 then result := result + 1;
port[out_addr] := 0;
end;
port[out_addr] := cs;
analog_read := result*vref*7.8125e-3;
end;
{-------- Initialization Section --------}
const
base: word = $40;
offs: array[1..3] of word = ($08,$0a,$0c);
dummy: real;
begin

{find out where printer port is}


out_addr := memw[base:offs[nlpt]];
in_addr := out_addr + 1;
{place ADC in idling mode}
port[out_addr] := cs;
{read ADC a few times to let it settle}
dummy := analog_read(0);
end.

{-------- End of ANALOG.PAS ---------}


{-------- Test program TEST.PAS --------}
program test;
uses

crt,
analog;

var

i: integer;

begin
while not keypressed do begin

for i := 0 to 3 do write (analog_read(i):3:3,' ');


writeln;
delay (500);
end;
end.
{-------- End of TEST.PAS --------}