Traditional Culture Encyclopedia - Traditional festivals - What are the common methods of controlling ADC by single chip microcomputer?

What are the common methods of controlling ADC by single chip microcomputer?

1, ADC principle

ADC converter consists of prefilter, modulator, digital filter and comb filter, 22? The structure of ADC is shown in figure 1. It passes the input signal through 22? The modulator is quantized into a high-speed data stream of 1bit, and the final result is obtained after digital filtering and sampling. D conversion, its principle and structure are quite different, the following is the first-order 22? Modulator as an example to illustrate 22? ADC principle.

Figure 1 2-? Structure of ADC

2. Common methods

ADC0809 is a CMOS device with 8-bit analog-to-digital converter, 8-way multiplexer and microprocessor-compatible control logic. It is a successive approximation A/D converter, which can directly interface with single chip microcomputer. ?

Internal logic structure of (1)ADC0809

As can be seen from the figure below, ADC0809 consists of an 8-channel analog switch, a data latch and decoder, an analog-to-digital converter and a three-state output latch. Multiplex switch can pass through 8 analog channels, allowing 8 analog time-sharing inputs, and * * * is converted by A/D converter. The tri-state output latch is used to latch the digital quantity after A/D conversion, and the converted data can only be taken out from the tri-state output latch when the OE terminal is at high level.

(2).ADC 0809 pin structure

The functions of each pin of ADC0809 are as follows:

? D7-D0: 8-bit digital output pin.

? In0-in7: 8-bit analog input pin.

? Vcc:+5v working voltage.

? GND: ground.

? REF(+): positive terminal of reference voltage.

? REF(-): the negative terminal of the reference voltage.

? Start: a/d conversion start signal input terminal.

? ALE: data latch enable signal input terminal.

? The above two signals are used to start the A/D conversion.

? EOC: the output pin of the conversion end signal, which is low at the beginning of conversion and high at the end of conversion.

? OE: The output enable control terminal is used to open the tri-state data output latch.

? CLK: clock signal input (generally 500KHz).

? A, b and c: address input lines.

ADC0809 requires input analog: the signal is unipolar and the voltage range is 0-5V. If the signal is too small, it must be amplified; In the process of conversion, the input analog quantity should remain unchanged. If the analog quantity changes too fast, a sample-and-hold circuit should be added before input. ?

? Address input and control line: 4.

ALE is a data latch enable input line, which is active when it is high. When the ALE line is high, the data latch and decoder latch the address signals of the three address lines A, B and C, and the analog signals of the selected channel are converted into converters after decoding. A, B and C are address input lines for gating all analog inputs on IN0-IN7. The channel selection table is shown in the following table.

Digital output and control line: 1 1.

ST is the conversion start signal. When ST jumps at the edge, all internal registers are cleared; When the edge jumps, start A/D conversion; ST should be kept low during the conversion. EOC is the end of the conversion signal. When EOC is high, it means the conversion is over; Otherwise, it means that A/D conversion is in progress. OE is an output enable signal, which is used to control three output latches to output the converted data to the single chip microcomputer. OE = 1, and output the converted data; OE = 0, and the output data line is in high impedance state. D7-D0 are digital output lines. ?

CLK is the clock input signal line. Because there is no clock circuit in ADC0809, the required clock signal must be provided by the outside world, usually with a frequency of 500KHZ.

Vref (+) and Vref (-) are reference voltage inputs.

2.ADC 0809 application instructions?

(1).ADC 0809 has an output latch, which can be directly connected with AT89S5 1 single chip microcomputer.

(2) When initializing, make both ST and OE signals low.

(3) Send the address of the channel to be converted to ports A, B and C ...

(4) Give a positive pulse signal with a width of at least 100ns at the st terminal.

(5) Judging whether the conversion is completed according to the EOC signal. ?

(6). When EOC becomes high level, OE is high level at this time, and the converted data is output to the single chip microcomputer.

3. Experimental tasks

As shown in the figure below, the analog quantity between 0 and 0-5v is input from channel IN3 of ADC0809, which is converted into digital quantity by ADC0809 and displayed on the digital tube in decimal form. VREF of ADC0809 is connected to +5v. ?

4. Program design content

(1). In the process of A/D conversion, check whether A/D conversion is completed by querying the flag signal of EOC. If it is finished, read the data through P0 port, and display it on the digital tube after data processing.

(2) Before A/D conversion, how to start the conversion?

ABC = 1 10 Select the third channel.

ST = 0, ST = 1, ST = 0 generates a positive pulse signal to start the conversion.

C language source program

? # Including

? Unsigned character code dispbitcode[]={0xfe, 0xfd, 0xfb, 0xf7,

? 0xef,0xdf,0xbf,0x7f };

? Unsigned character code dispcode[]={0x3f, 0x06, 0x5b, 0x4f, 0x66,

? 0x6d、0x7d、0x07、0x7f、0x6f、0x 00 };

? Unsigned char dispbuf[8]={ 10, 10, 10, 10, 10, 0};

? Unsigned character display count;

sbit st="p3"^0;

? sbit oe="p3"^ 1;

? sbit eoc="p3"^2;

? unsigned char channel = " 0xbc//IN3

? Unsigned character getdata

Invalid master (invalid)

? {

? TMOD = 0x 0 1;

? TH0 =(65536-4000)/256;

? TL0 =(65536-4000)% 256;

? TR0 = 1;

? ET0 = 1;

? EA = 1;

P3 = channel;

while( 1)

? {

? ST = 0;

? ST = 1;

? ST = 0;

? while(EOC = = 0);

? OE = 1;

? getdata = P0

? OE = 0;

? disp buf[2]= get data/ 100;

? get data = get data % 10;

? disp buf[ 1]= get data/ 10;

? disp buf[0]= get data % 10;

? }

? }

Void t0(void) uses 0 interrupt 1

? {

? TH0 =(65536-4000)/256;

? TL0 =(65536-4000)% 256;

? p 1 = disp code[disp buf[disp count]];

? P2 = dispbitcode[disp count];

? disp count++;

? if(dispcount==8)

? {

? dispcount = 0;

? }

?