digital ohmmeter

28
Digital Ohmmeter Table of Content Page number Abstract 3 1.0 Introduction 1.1 Program Description 4 1.2 Hardware Description 5 1.3 Block Diagram of Digital Ohmmeter 7 2.0 Algorithm 8 Flow Chart 9 3.0 Software Description 13 4.0 Project Result 16 5.0 Conclusion 19 6.0 Reference 20 7.0 Software Listing Coding for this project 21 Schematic Diagram 24 2

Upload: low-koon-yee

Post on 27-Aug-2014

175 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Digital Ohmmeter

Digital Ohmmeter

Table of Content

Page number

Abstract 3

1.0 Introduction

1.1 Program Description 4

1.2 Hardware Description 5

1.3 Block Diagram of Digital Ohmmeter 7

2.0 Algorithm 8

Flow Chart 9

3.0 Software Description 13

4.0 Project Result 16

5.0 Conclusion 19

6.0 Reference 20

7.0 Software Listing

Coding for this project 21

Schematic Diagram 24

2

Page 2: Digital Ohmmeter

Digital Ohmmeter

Abstract

A digital ohmmeter is an electrical instrument that used to measured resistance in electronics. In this mini project, the task given is to design a digital ohmmeter by using 8051 Microcontroller Board and external circuit contains chip ADC 0831 and LCD 2x16 characters. The result of resistance value is shown in LCD. Theory of voltage divider is used to determine the value of resistor measured. The range of resistor measured is set from 1k Ω to 1MΩ. Program is written using Keil uVision2 in the form of c program. After the program is compiled, the program will executed by using 8051 Microcontroller Board. Schematic diagram and flow chart of this project are included in this report.

3

Page 3: Digital Ohmmeter

Vin

Rmeasure

Vout

Rreference

Digital Ohmmeter

1.0 Introduction

1.1 Program Description In this mini project, ADC 0831 is used to convert the input voltage into 8-bit binary numbers. After getting data from ADC 0831, the 8-bit binary value is then converted into resistance value by using calculation of voltage divider theory. The resistance value is then show in LCD. The software used for this mini project is Keil uVision2 and Flash Magic. Program is written in the form of c program.

Basic Concepts and Theory of Voltage Divider (Potential Divider)In electronics, a voltage divider (also known as a potential divider) is a simple linear circuit that produces an output voltage, Vout that is a fraction of its input voltage, Vin. Voltage division refers to the partitioning of a voltage among the components of the divider.

The basic circuit for a voltage divider for resistor in series is shown below.

In this circuit the two resistor are connected in series across V in, which is the power supply voltage connected to the resistor, Rreference, where the output voltage Vout is the voltage across the resistor Rmeasure which is given by the formula. If more resistors are connected in series to the circuit, the different voltages will appear across each resistor with regards to their individual resistance providing different voltage points from a single supply.

Vout can be calculated by using voltage divider formula:

V out=V ¿×Rmeasure

Rreference+Rmeasure

From above equation, Rmeasure can also be calculated.

Rmeasure=V outR referenceV ¿−V out

4

Page 4: Digital Ohmmeter

Digital Ohmmeter

1.2 Hardware Description

2x16 Characters LCD Liquid Crystal Display (LCD) is very helpful in providing user interface as well as for debugging purpose. The most common type of LCD controller is HD44780 which provides a simple interface between the controller & an LCD.

Figure: Character LCD type HD44780 pin diagram

ADC0831The ADC0831 series are 8-bit successive approximation Analogue/Digital converters with a serial I/O and configurable input multiplexers with up to 8 channels. The data output is 8-bit binary value and is between 0 up to 255 decimal. The gaps between bits by bits are referred to Vref that determine by user.

Figure: Top view and pin connection of ADC0831

5

Pin no.

Name Description

1 VSS Power supply (GND)2 VDD Power supply (+5V)3 VEE Contrast adjust

4 RS0 = Instruction input1 = Data input

5 RW0 = write to LCD module1 = Read from LCD module

6 E Enable signal7 D1 Data bus line (LSB)8 D2 Data bus line 19 D3 Data bus line 210 D4 Data bus line 311 D5 Data bus line 412 D5 Data bus line 513 D6 Data bus line 614 D7 Data bus line (MSB)

Table: Character LCD pins with 1 controller

Page 5: Digital Ohmmeter

Digital Ohmmeter

8051 Microcontroller BoardA microcontroller is a single chip microprocessor system which contains a processor core, data and program memory, serial and parallel I/O, timers, external and internal interrupt handling mechanism.

Figure: Block Diagram of a microcontroller

Figure: Pin connection of 8051 Microcontroller Board.

Other equipment that needed in this project:1. Wires2. Different values of resistors between 100Ω to 1MΩ3. Power supply4. RS232 connector5. Breadboard

6

Page 6: Digital Ohmmeter

Circuit to measure resistance

P2.0...P2.7

Microcontroller8051

LCD DISPLAY161

...

.

.

.

Power supply

Digital Ohmmeter

1.3 Block Diagram of Digital Ohmmeter

7

Page 7: Digital Ohmmeter

Vin = 5V

Rmeasure

Vout

Rreference = 33k Ω

Digital Ohmmeter

2.0 Algorithm

The calculation involved in this program is mainly use voltage divider theorem.

In this project, Vin is set to 5V and Rreference is set to 33kΩ. Rreference is determined by setting the range of measure the resistance. Range to measure the resistance is set between 1kΩ to 1MΩ.

Rreference=√Rmin× Rmax

¿√1k×1M

¿31.6kΩ

By using the above formula, Rreference is equal to 31.6kΩ by using range 1kΩ to 1MΩ. Rreference is set to 33kΩ because this value is near to 31.6kΩ.

Rmeasure can be calculated by using formula below:

Rmeasure=V outR referenceV ¿−V out

The value of Vo in voltage divider circuit is converted to binary value by using ADC0831. The 8051 microcontroller is getting binary value from ADC0831 when the program is running. To convert binary value to Vo, formula below is used.

V ou t=5.0255

×x x = binary value from ADC0831

For example, if the value of x is 128, Rmeasure is equal to 33.27kΩ. Steps to getting Rmeasuse are shown below:

V out=5.0255

×128=2.51V

Rmeasure=2.51×33 k5−2.51

=33.27 kΩ

8

Page 8: Digital Ohmmeter

False

B

While (1)

Start

f = 0

CS = 0CLK = 0CLK = 1

x = 0

True

k = 0

k < 8

False

CLK = 1CLK = 0

x = (x<<1)|D0k++

A

Display “Digital Ohmmeter”“1k <<-->> 1M ohm”

Display“ ”“ ”

Delay 1 second

Delay 1 second f++

Truef < 3

Digital Ohmmeter

Where Vin=5V & Rreference=33kΩ

Flow Chart

Flow chart for main program:

9

Page 9: Digital Ohmmeter

Delay 1 second

a = (float x)V = (5.0/255.0)*a

b = V*33000.0/(5.0-V)

Display the value of resistance to LCD

A

CS = 1

B

Digital Ohmmeter

Flow Chart for Display the value of resistance to LCD:

10

Page 10: Digital Ohmmeter

Display the value of resistance to LCD

Continue

break

Display “resistor < 1k”“out of range”

b ≥ 0.0 &&

b < 1000.0 True

False

Display “resistance”“r = %.2fk ohm”R = b/1000.0

b ≥ 1000.0&&

b < 100 000.0 True

False

Display “resistance”“r = %.1fk ohm”R = b/1000.0

b ≥ 100 000.0 &&

b < 1 000 000.0 True

False

Display “resistor > 1M”“out of range”

b ≥ 1 000 000.0 True

False

Digital Ohmmeter

Flow Chart for Delay 1 seconds

11

Page 11: Digital Ohmmeter

Continue

i = 0

Truei < 20

False

TMOD = 0X11

Delay 1 second

TH0 = 0x4BTL0 = 0xFE

TR0 = 1

While (TF0==0)

False

True

TR0 = 0TF0 = 0

i++

Digital Ohmmeter

3.0 Software Description

In this project, each port that used is declared. For ADC0831, cs is set to Port 1.0, clock (CLK) is set to Port 1.1 and D0 is set to Port 1.2. For LCD, data transfer (D0-

12

Page 12: Digital Ohmmeter

Digital Ohmmeter

D7) is set to Port 2. RS (Register Select) is set to port 3.5; RW (Read/Write Select) is set to Port 3.6 and E (Chip Enable Signal) in set to Port 3.7. The declaration of ports is shown below.

In void main(void) function, “Digital Ohmmeter” and “1k <<-->> 1M ohm” is set and shown in LCD address 80 and C0. After that, it will blink 3 times and each time will delay 1 second. Coding of this section is shown below.

After the display character of “Digital Ohmmeter”, the value of output of ADC0831 is declared as variable x. To get output data from ADC0831, chip select (cs) is set to zero. Clock pulse is then set to 1 and 0. It is used to get negative trigger clock pulse and then to get the value of D0. After that, the first value of D0 which is MSB of 8-bit output is shift to left by bit and then set in or condition in bit with D0. As the value of D0 is out with bit by bit, the step above is using 8 times. It is because the output of ADC0831 is in series mode. After the steps is finish, cs is set to zero. While(1) is used continue the loop the program. Coding of this section is shown in figure below.

13

Page 13: Digital Ohmmeter

Digital Ohmmeter

After the value of x is finish get from ADC0831, calculation is used to get the V out

of the input of ADC0831. Value of Vout is used to calculate the Rmeasure by using voltage divider method. The coding to calculate Rmeasure is shown in below.

The value of Rmeasure is shown in LCD by using various statements. It is used to display the value of Rmeasure in different mode. If the value of Rmeasure is less than 1kΩ, the LCD will display “out of range” because the range of this digital ohmmeter is between 1kΩ to 1MΩ. If Rmeasure is between 1kΩ to 100kΩ, the output shown in LCD is in 2 decimal points. If Rmeasure is between 100kΩ to 1MΩ, the output shown in LCD is in 1 decimal point. . If the value of Rmeasure is more than 1MΩ, the LCD will display “out of range”.

After the value of Rmeasure is achieved in previous condition, the output is shown in LCD. The output of display is refreshed every 1 second.

The function of delay1s() is used to delay the output every 1 second. Mode of timer T0 and T1 is first set to mode 1. For loop is set to 20 times because the internal timer used is 1.085 s, and the maximum timer that can be used inμ internal timer is 50ms. TH0 and TL0 is set to 4BH and FEH because the counter for looping in 50ms is 19454 times. After minus with 65536 which is FFFF in hexadecimal, the value of 46082 which is 4BFE in hexadecimal is used to start the timer counter. After the counter is count to FFFFH, TF0 will count to 1 and

14

Page 14: Digital Ohmmeter

Digital Ohmmeter

TH0 and TL0 is reset to 0. The process is continuing for 20 times so that 1 second of time is count.

4.0 Project Result

The results that get from this project are shown below:

15

Page 15: Digital Ohmmeter

Digital Ohmmeter

When 220Ω of resistor is measured, the result shown is out or range.

16

The title of “Digital Ohmmeter” and accepted range to measure resistor is shown.

Page 16: Digital Ohmmeter

Digital Ohmmeter

When 3.3kΩ is inserted in the circuit, the result shown in LCD is 3.27kΩ.

When 47kΩ is inserted in the circuit, the result shown in LCD is 47.14kΩ.

17

Page 17: Digital Ohmmeter

Digital Ohmmeter

When 470kΩ is inserted in the circuit, the result shown in LCD is 528.0kΩ.

The result of this project is mainly successfully showing the value of resistor measured. For this project, it is hard to detect whether the measured resistor in circuit or not because when the resistor measured is not inserted in circuit, the output of Vout is exceed 5.0V. The ADC0831 is then converting value to 255 in binary value and the value of 255 is exceeding the range of measured resistor. The output of display in LCD will show “out of range” because the value of resistor measured is exceed 1MΩ after the calculation of theory of voltage divider.

5.0 Conclusion

18

Page 18: Digital Ohmmeter

Digital Ohmmeter

As conclusion, I learned that how to set up a digital ohmmeter by using voltage divider method to calculate the resistance measured. I also learned how to interfacing LCD to 8051 microcontroller. The function of ADC0831 is learned from this project. The results that get from this project are mainly satisfied and achieved the goal that I had set.

The further investigation that can be done in this project is by using indicator to control the chip select of ADC0831. In order to solve the inserting resistor measured problem, an external hardware that is indicator is used to control the chip select when a measured resistor is inserted into circuit.

6.0 References

Microcontroller

19

Page 19: Digital Ohmmeter

Digital Ohmmeter

http://www.engineersgarage.com/microcontroller

Theory of voltage dividerhttp://www.kpsec.freeuk.com/vdivider.htmhttp://www.electronics-tutorials.ws/resistor/res_3.htmlhttp://www.smartcontroller.com.au/publications/voltagedivider.htm

Interfacing LCD to 8051http://www.dnatechindia.com/index.php/Tutorials/8051-Tutorial/Interfacing-LCD.htmlhttp://www.8051projects.net/lcd-interfacing/introduction.php

ADC 0831http://www.national.com/mpf/DC/ADC0831.html#Overviewhttp://www.national.com/ds/DC/ADC0831.pdf

Circuit for measure resistor in real world

7.0 Software Listing

Coding for Digital Ohmmeter program:

20

GND

Vcc

Rreference

Rmeasure

cs Vin(+)

Vin(-)

GND

Vcc CLK D0

Vref

Page 20: Digital Ohmmeter

Digital Ohmmeter

#include<reg51.h>#include<stdio.h>#include<string.h>

sbit CS = P1^0;sbit CLK = P1^1;sbit D0 = P1^2;sbit RS = P3^5;sbit RW = P3^6;sbit E = P3^7;sfr dat = 0xA0;

unsigned int x,i;

void delay(void);void LCD_cmd(unsigned char x);void LCD_wr(unsigned char x);void initLCD(void);void delay1s(void);

void main(void)

unsigned char y[16];unsigned char z[16];unsigned int j,k,f;float V,a,R,b;

for(f=0;f<3;f++)

sprintf(y,"Digital Ohmmeter");sprintf(z,"1k <<-->> 1M ohm");initLCD();LCD_cmd(0x80);for(i=0;i<16;i++)

LCD_wr(y[i]);LCD_cmd(0xc0);for(j=0;j<16;j++)

LCD_wr(z[j]);

delay1s();

sprintf(y," ");initLCD();LCD_cmd(0x80);for(i=0;i<16;i++)

LCD_wr(y[i]);LCD_cmd(0xc0);for(j=0;j<16;j++)

LCD_wr(y[j]);delay1s();

while(1)

CS=0;CLK=1;CLK=0;x=0;

21

Page 21: Digital Ohmmeter

Digital Ohmmeter

for(k=0;k<8;k++)

CLK=1;CLK=0;x=(x<<1)|D0;

CS=1;

a=(float) x;V=(5.0/255.0)*a;b=V*33000.0/(5.0-V);

if(b>=0.0 && b<1000.0)

sprintf(y," resistor < 1k ");sprintf(z," out of range ");

else if(b>=1000.0 && b<100000.0)

R=b/1000.0;sprintf(y," resistance ");sprintf(z," R = %.2fk ohm ",R);

else if(b>=100000.0 && b<1000000.0)

R=b/1000.0;sprintf(y," resistance ");sprintf(z," R = %.1fk ohm ",R);

else if(b>=1000000.0)

printf(y," resistor > 1M ");sprintf(z," out of range ");

initLCD();LCD_cmd(0x80);for(i=0;i<16;i++)

LCD_wr(y[i]);LCD_cmd(0xc0);for(j=0;j<16;j++)

LCD_wr(z[j]);delay1s();

void delay(void)

unsigned int i;for(i=0;i<200;i++);

void LCD_cmd(unsigned char x)

22

Page 22: Digital Ohmmeter

Digital Ohmmeter

dat=x;RS=0;RW=0;E=1;E=0;delay();

void LCD_wr(unsigned char x)

dat=x;RS=1;RW=0;E=1;E=0;delay();

void initLCD(void)

LCD_cmd(0x38);LCD_cmd(0x38);LCD_cmd(0x38);LCD_cmd(0x06);LCD_cmd(0x0c);LCD_cmd(0x01);

void delay1s(void)

unsigned int i;

TMOD=0x11;for(i=0;i<20;i++)

TH0=0x4B;TL0=0xFE;TR0=1;while(TF0==0);TR0=0;TF0=0;

23

Page 23: Digital Ohmmeter

Digital Ohmmeter

24