Single chip digital voltmeter (ADC0809)

Publisher:JoyfulSpirit5Latest update time:2020-05-11 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Brief Introduction


    The digital voltmeter is designed using the analog-to-digital conversion chip ADC0809. The digital voltmeter designed in the example can measure the input voltage value in the range of 0 to 5V, and display the collected voltage value through a 4-digit LED digital tube. The example measures three analog values: 4.995, 2.5, and 0.005.


    ADC0809 is a conversion device that can convert the analog voltage signal we want to measure into a digital quantity so that it can be stored or displayed.


   File package: Link: https://pan.baidu.com/s/1F2E135Jw7TG3EmUVx3xKGg Extraction code: 5ttz


2. Effect

3. Project Documents


1. Keil Engineering

2. Simulation circuit diagram

4. Source Files


#include

#define uint unsigned int

#define uchar unsigned char

uchar code led[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //The digital tube displays the level code 0-9

uint volt,vtime; //voltage value measured 

uchar addr; //measurement address bit

sbit LW1=P2^3; //corresponding to the 4th digital tube

sbit LW2=P2^2; //corresponding to the third digital tube

sbit LW3=P2^1; //corresponding to the second digital tube

sbit LW4=P2^0; //corresponding to the first digital tube

sbit LW5=P1^4; //Indicates which conversion value is currently displayed

sbit CLK=P2^4; //clock signal

sbit START=P2^5; //Switch start switch

sbit EOC=P2^6; //Conversion end flag

sbit OE=P2^7; //Define each pin of ADC0809

/******************************************************************/

//Function name: delay(uint x)

//Function: Delay program to change measurement address

//Call functions:

//Input parameter: x

//Output parameters:

//Description: The delay time of the program is x times 0.5ms. The measurement address bit is changed every 5s.

/******************************************************************/

void delay(uint x)

{

uchar y,z;

for(y=x;y>0;y--)

for(z=250;z>0;z--);//This step takes about 0.5ms

vtime++;

if(vtime==1000)

{

vtime=0;

addr++;

if(addr==3) //This example has 3 measurement input values, read these 3 values ​​in turn and convert them for display

addr=0; //The above statement realizes the change of measurement address bit

}

}

/******************************************************************/

//Function name: ADC()

//Function: Digital to analog conversion program

//Call functions:

//Input parameters:

//Output parameters:

//Description: Save the converted measured value in the variable volt

/******************************************************************/

void ADC()

{

EA=1; //Open interrupt

 

//Ensure that the AD conversion state is normal?

START=0;

START=1;

 

START=0; //ad starts conversion

while(EOC==0); //Wait for the conversion to end

OE=1; //Output data flag is true

EA=0; //Disable interrupt

volt=P3; //Get the converted value and save it in volt (P3 is the converted data)

volt=volt*196; //Conversion value processing (the full scale of the example is 5V, the conversion resolution is 8 bits, the maximum value is 255, 5/255=196mV, that is, 1 represents 196mV)

OE=0; //Output conversion ends (after obtaining the conversion value)

}

/******************************************************************/

//Function name: display()

//Function: 4-digit digital tube display

//Calling function: delay(uint x)

//Input parameters:

//Output parameters:

//Description: Display the processed voltage value on the 4-digit digital tube

/******************************************************************/

void display()

{

P0=0xff; //Blank (equivalent to turning off all lights, clearing the last display effect)

LW1=0;

P0=~led[volt/10000]&0x7f; //1 volt display with decimal point

delay(2);

P0=0xff;

LW1=1;

LW2=0;

P0=~led[(volt/1000)%10]; //100 millivolt display position

delay(2);

P0=0xff;

LW2=1; 

LW3=0;

P0=~led[(volt/100)%10]; //10 millivolt display position

delay(2);

P0=0xff;

LW3=1;

LW4=0;

P0=~led[(volt/10)%10]; //1 millivolt display position

delay(2);

P0=0xff;

LW4=1;

LW5=0;

P0=~led[addr+1]; //Display voltage measurement bit

delay(2);

LW5=1; //Indicates which conversion value is currently displayed

}

/******************************************************************/

//Main program

/******************************************************************/ 

void main()

{

EA=1; //Open the general interrupt    

    TMOD=0x01; //Set the timing counting working mode

//Assign initial value to the timer

TH0=0XFF;

    TL0=0XB4;

 

ET0=1; //Open timer 0 interrupt 

TR0=1; //Start timer 0

while(1)

{

P1=addr; //Load measurement address

LW5=1;

ADC(); //Call analog-to-digital conversion program

display(); //Call the display program

}

}

/******************************************************************/

//Function name: timer() interrupt 1

//Function: Timer interrupt 0 response program

//Call functions:

//Input parameters:

//Output parameters:

//Description: Provide clock signal for ADC

/******************************************************************/

void timer() interrupt 1

{

//Reset initial value

TH0=0XFF;

    TL0=0XF0;

CLK=~CLK; //Invert to generate clock signal

}

V. Conclusion


    ADC0809 is a successive approximation A/D device with 8 analog inputs and 8-bit parallel digital outputs.


1. Main technical indicators and characteristics

    (1) Resolution: 8 bits;

    (2) Conversion time: depends on the chip clock frequency, the time required for one conversion;

    (3) Single power supply: +5V;


    (4) Analog input voltage range: single-stage 0~+5V.


2. Pin introduction

Pin function description:

IN0-IN7: Analog input channel. That is to say, it can measure and convert eight analog quantities in a time-sharing manner.

ADDA-C: Address line. That is, the different codes of these three address lines are used to select which analog quantity to measure and convert.

ALE: Address latch enable signal. When the address is written to ADDA-C at a low level, the data on ADDA-C is latched when ALE jumps to a high level.

START: Start conversion signal. When it is a rising edge, the internal register is cleared to 0. When it is a falling edge, A/D conversion starts.

D0-D7: Data output port. The converted digital data is output to S52 from here.

OE: Output enable signal, which is the output control terminal of D0-D7. When OE=0, the output terminal is in high impedance state. When OE=1, the converted data is output.

CLOCK: Clock signal. ADC0809 does not have a clock circuit inside, and a clock pulse signal must be provided externally.

EOC: Conversion end status signal. EOC=0, conversion in progress. EOC=1, conversion is complete, and the next output operation can be performed.


Vref(+), Vref(-): Reference voltage. The reference voltage is used to compare with the input analog quantity as the basis for measurement. Generally, Vref(+)=5v, Vref(-)=0V.


3. Timing diagram and working process


Timing diagram:

work process:

 ① Eight analog signals to be measured and converted can be connected to IN0-IN7 respectively. Only one signal can be connected.

 ② Connect the ADDA-ADDC terminals to the code representing the selected measurement channel. For example, 000(B) represents channel 0; 001(B) represents channel 1; 111 represents channel 7.

 ③ Set ALE from low level to high level, so as to latch the channel code sent by ADDA-ADDC, and send the analog quantity of the selected channel to the internal conversion unit after decoding.

 ④ Give START a positive pulse. When it rises, all internal registers are cleared. When it falls, A/D conversion begins; during the conversion, START remains at a low level.

 ⑤EOC is the conversion end signal. During the above A/D conversion, EOC can be continuously measured. When EOC is high, it indicates that the conversion work is completed. Otherwise, it indicates that the A/D conversion is in progress.

 ⑥When the A/D conversion is completed, set OE to 1, and the data of D0-D7 can be read. OE=0, the output of D0-D7 is in high impedance state, OE=1, and the converted data is output from D0-D7.

    Note: The conversion work of ADC0809 is completed under the condition of clock pulse, so first give it a clock signal at the CLOCK end. The instruction manual gives the pulse signal frequency that can be connected is 10KHz-1280KHz, and the typical value is 640KHz. Here we take 50KHz.

  The TEOC duration on the timing diagram is: 8 clocks from the rising edge of START plus 2 microseconds. This should be noted, because when the START pulse just ends and enters the conversion work, EOC does not immediately become a low level but enters a low level after 8 clock cycles, so it is best to delay the EOC detection after giving the START pulse.


  The conversion time of a channel is generally 64 clock cycles. For example, when the clock frequency is 640KHz, the clock cycle is 1.5625 microseconds, and the conversion time of a channel is 1.5625×64=100 microseconds. Therefore, 1000000÷100=10000 times can be converted in 1 second.


4. Calculate the initial value of the timer:


    The signal frequency is 50KHz and the crystal frequency is 12MHz.


    At a clock frequency of 12MHz, 12MHz = 12000KHz = 12000000Hz. One clock oscillation period is 1/12000000 seconds, or 1/12 microseconds. A machine cycle of a standard MCS51 series microcontroller is 12 clock oscillation periods, or 12 * (1/12) = 1 microsecond.


To output a 50KHz rectangular square wave, the period T = (1/50K)s, the width is equal to the duty cycle of 50%, and the high level time is (0.5/50K)s = 0.01 ms = 10us


However, in reality, the frequency is too fast during simulation (I don’t know if it’s because of the wrong calculation method), and the initial value is not used in programming.


6. Proteus related operations


   1. Voltage probe element (display voltage)

   2. Custom power supply voltage

-------------------------------------------------The following is a reply from brother Rainynightsunset---------------------------


After downloading the package file:

========================The following reply to Muzi Jasmine, this brother=======================


Manual reset effect (using polling to detect whether the button is pressed, because the external interrupt pin is used)

Test code and simulation files: Link: https://pan.baidu.com/s/1zC8uhzlbIFRBOkOWuWzAWQ Extraction code: wr39

[1] [2]
Keywords:MCU Reference address:Single chip digital voltmeter (ADC0809)

Previous article:51 MCU Experiment 3: LED Flowing Light
Next article:MCU matrix button

Latest Microcontroller Articles
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
    Since development under LINUX is still quite troublesome, is there a more convenient and simple development method under WINDOWS? The answer is yes. Of course, it is not a development tool like ADS, because it ...
  • Learn ARM development(15)
    When using GCC to develop ARM, you will definitely encounter compiler problems. For example, you will encounter various warnings and errors when compiling C code. For example, I encountered several warnings yesterday, so let's take a look at what these warnings are ...
  • Learn ARM development(16)
  • Learn ARM development(17)
  • Learn ARM development(18)
  • Embedded system debugging simulation tool
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号