MAE 476/576 MECHATRONICS
LAB 2
B UILDING A D IGITAL MULTIMETER
M ARCH 20, 2003
GROUP B David Pericak 2797 2725 Jairam Ramaswamy 3067 3752 Srinivas Sundaragopal 3045 9561 Talib Bhabhrawala 2978 6208 Vamsi Krishna P 3010 3495
1
TABLE OF CONTENTS Page 1. Abstract ________________________________________2 2. Introduction _____________________________________2 3. Tasks __________________________________________3 4. Hardware used ___________________________________3 - 4 5. Circuit diagram ___________________________________5- 6 6. Procedure ________________________________________7 - 8 7. Discussion & Conclusions___________________________8 8. Software 8.1. Flowchart ____________________________________9 - 10 8.2. Source code __________________________________11 - 19
9. Contribution of each member ________________________20 10. Appendix 10.1.
References _____________________________20
2
ABSTRACT The report is about the development of a digital multimeter by incorporating various aspects like synchronous interfacing, floating point operations using integer arithmetic and of course the various issues & problems we faced. This lab also focuses on the conversion of Digital to Analog and Analog to Digital signals. These are simply necessary because the entire world around us is analog and for it to communicate with computers which are digital we require such a conversion for any sort of manipulation. Another aspect was to analyze and learn from the sets of data obtained and verify principles and utilize it for calibration. This exercise proved to be a major step guided us towards the possibility of using such techniques for more realistic and larger projects.
B ACKGROUND INFORMATION Moving from the larger picture to the issue at hand like the setup of the multimeter and to make sure it implemented what was required of it.
The following are the tasks that we set out to implement successfully a. Digital Ohmmeter − A Digital Ohmmeter was constructed by using the circuit shown in Figure 1. By pressing appropriate buttons the ohmmeter is activated and the value of the resistance is obtained in kilo ohms on the LCD. On hitting the button again the new value is displayed on a refreshed LCD. b. Digital Voltmeter − A digital voltmeter was constructed using the circuit in figure 2 and an 8 bit, serial A/D converter (ADC0831). This A/D converter is interfaced with the Basic Stamp and a voltage divider. This converts binary values from the ADC into a floating-point voltage level between 0 and 5. The binary values and the converted voltages are displayed on the LCD display. Line one of the display is the binary value and line 2 of the display is converted voltage value.
3
c. Digitally Controlled Voltage Source using an R-2R Ladder Network (R2RDAC) − The R-2R ladder network was created the ladder’s output was interfaced with an LED and the A/D converter (ADC0831). The system is set up so that when button D1 is pressed the output of the DAC increases, also when button D0 is pressed the output of the DAC decreases.
CIRCUIT DIAGRAMS V1 5V +V
C1 C R1 220 ohm
R2
V1 5V
+V
Figure2(O hmmeter Circuit) R2 10k
Figure 3(Voltmeter Circuit)
4
H ARDWARE INFORMATION The hardware that was used came from the Stamp Works kit ( Figure 1)
Figure 1 Hardware used included o
NX-1000 BASIC Stamp Experiment Board
o
BASIC Stamp 2 module (BS2-IC)
o
2 row x 16 character Hitachi-compatible parallel LCD with custom manufactured cable
o
Digital multimeter with two probes
o
Wire cutter / wire stripper / pliers
o
Various Resistors from 0.2K- 10K
o
Serial cable
o
Computer - Furnas 811
o
ADC0831 – A/D Converter
o
LM358
o
Potentiometer on the Board.
BASIC STAMP
BASIC STAMP EXPERIMENT BOARD
5
SPECIAL H ARDWARE ADC0831
The chip shown above is the ADC0831. It is an 8 bit AD converter with a serial I/O. This particular chip has one single ended and one differential analog channel, with a total of eight pins.
Specs: http://www.national.com/pf/AD/ADC0831.html
LM358
LM358
The figure shows the pin diagram of the LM358 chip. This chip is a low power dual opamp which was used for this experiment. The op-amp in this chip is called a voltage follower because the voltage that goes into the chip is the same as the voltage leaving the chip. This chip is used to separate the ladder circuit from the led and the ADC circuits.
Site http://www.national.com/pf/LM/LM358.html
6
USER M ANUAL The system, when powered up, waits for user input, displaying the following on the LCD. Choose mode
Button D0 and Button D1 are used as controls to switch modes. Button D0 is referred as D0 and Button D1 as D1 in the manual. The user can now choose to go to either of the two modes: I. Ohmmeter / Voltmeter mode [Press D0] II. Increment / Decrement R-2R Ladder mode [Press D1] I.
Assume D0 has been pressed initially and we are Ohmmeter / Voltmeter mode Ohmmeter/Voltmeter
The user can now choose to use the ohmmeter or the voltmeter function Press D0 for Voltmeter and D1 for the Ohmmeter. a. Voltmeter [Press D1] When D1 is pressed again, the user can measure the voltage. To use the voltmeter to measure, change the potentiometer VR-10k in the StampWorks Board. As the potentiometer is adjusted, the user can see the voltage measured in the display in binary and decimal form in the first and second rows of the LCD Display as shown 00000000 0.0 V
b. Ohmmeter [Press D0] On pressing D0, the user can measure the resistance. Place the resistor whose resistance is to be measured between the leads provided and the resistance is displayed as seen below
0hmmeter 20.00 kΩ
7
II.
Assume D1 has been pressed initially This sets the system into the Increment / Decrement R-2R Ladder mode
Increment
The user can now choose to increment Voltage by pressing D0 repeatedly a. Increase voltage [Press D0 repeatedly] As the voltage is increased, the LCD Display refreshes and shows the value as shown below: Increment 0.012 V
Similarly, D1 is used to continuously decrement the voltage value. b. Decrease voltage [Press D0 repeatedly] As the voltage is decreased, the LCD Display updates the voltage value:
Decrement 0.011 V
8
INTEGRATED CIRCUIT FOR ALL THREE PARTS
9
IMPLEMENTATION O F PARTS AND ANALYSIS PART A The aim of the first part of the experiment was to develop an ohmmeter to calculate any resistance introduced to it. We have setup the system such that the resistance is placed on two exposed wires. When button D0 is pressed the appropriate resistance is displayed on the LCD in kilo ohms. To measure another resistor just place it and on pressing the button again a fresh value is displayed.
PRINCIPLE O F O PERATION USING RCTIME
RCTIME can be used to measure the charge or discharge time of a resistor/capacitor circuit. This allows you to measure resistance or capacitance; use R or C sensors such as thermistors or capacitive humidity sensors or respond to user input through a potentiometer. In a broader sense, RCTIME can also serve as a fast, precise stopwatch for events of very short duration.
Using RCTIME is very straightforward if we can determine the RCTIME value for a particular resistance and capacitance. We figured it out, based on a value called the RC time constant, or tau (t) for short. Tau represents the time required for a given RC combination to charge or discharge by 63 percent of the total change in voltage that they will undergo. More importantly, the value t is used in the generalized RC timing calculation.
The general RC timing formula uses t to tell us the time required for an RC circuit to change from one voltage to another: Time = -t * (ln (Vfinal / Vinitial))
10
In this formula ln is the natural logarithm it’s a key on most scientific calculators. If we are interested in a 10 k resistor and 0.1 µF cap. Calculate t: t = (10 x 103) x (0.1 x 10-6) = 1 x 10-3
The RC time constant is 1 x 10-3 or 1 millisecond. Now calculating the time required for the RC circuit to go from 5V to 1.5V as in our case: Time = -1 x 10-3 * (ln (5.0v / 1.5v)) = 1.204 x 10-3
BS2
BS2e
BS2sx
BS2p
Units in Variable
2 µs
2 µs
0.8 µs
0.9 µs
Maximum pulse
131.07 ms
52.428 ms
58.982 ms
58.982 ms
As can be seen from above the BS2, the unit of time is 2µs. Correspondingly 1.204 x 10-3 works out to 602 units. With a 10 k resistor and 0.1 µF cap, RCTIME would return a value of approximately 600. Since Vinitial and Vfinal don’t change we can estimate RCTIME results by:
RCTIME units = 600 x R (in kohms) x C (in µF)
What we have successfully obtained above is a theoretical derivation of calculating RCTIME for a given R and C.
ACCURACY
Prior to calibration the following table indicates the error between actual and measured resistances. This is due to the error inherently associated with the circuit and its components.
11
Actual Resistance (k ohms) (DMM)
Calculated Resistance
% Error
0.6 0.83 1 2.2 3.2 5.2 6.4 7.7 8.2 10 12.5 14.59 17.6 20 22.5 44.51 50.11 55.89 60.37 65.26
0.633333333 0.833333333 1.016666667 2.416666667 3.666666667 6.016666667 7.466666667 9 9.65 11.66666667 14.7 17.18333333 20.86666667 23.75 26.68333333 52.83333333 59.5 66.38333333 71.71666667 77.5
5.263157895 0.4 1.639344262 8.965517241 12.72727273 13.5734072 14.28571429 14.44444444 15.02590674 14.28571429 14.96598639 15.09214355 15.65495208 15.78947368 15.67770144 15.75394322 15.78151261 15.80718052 15.82151987 15.79354839
Mean % Error
12.83742204
As can be seen the error associated with the system was averaging to about 12% which is very large and subsequently would give highly erroneous values.
CAUSES OF ERRORS •
The resistances are themselves not accurate and the ones that we used have an error of + 5%, hence they contribute to discrepancies themselves.
•
Simlarly the capacitance of the capacitor is error prone.
•
It is assumed that the digital transition from 0 to 1 occurs at 1.5 V but it may not be the case.
•
While calibration we assume that the multimeter is accurate which might not be the case because it has the exact same issues as any circuit.
•
Contact resistance might be one of the sources of error.
12
CALIBRATION The solution to reduce errors in the measurement is by proper calibration. The way we went about calibration is to first collect data pertaining to our circuit to estimate the performance of our set up. We calculated RCTIMEs for varying resistance from 0-65 kohms and maintaining constant capacitance at 0.1µF. The following table indicates the values obtained and also the theoretical value for the same R and C by using our equation above.
Capacitance
RCTIME (Calculated)
RCTIME (basic stamp)
Constant
0.6 0.83 1 2.2 3.2 5.2 6.4 7.7 8.2 10 12.5 14.59 17.6 20 22.5 44.51 50.11 55.89 60.37 65.26
0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
36 49.8 60 132 192 312 384 462 492 600 750 875.4 1056 1200 1350 2670.6 3006.6 3353.4 3622.2 3915.6
38 50 61 145 220 361 448 540 579 700 882 1031 1252 1425 1601 3170 3570 3983 4303 4650
4.0971 7.8225 8.78745 10.26525 7.299 8.92245 7.8816 8.643 5.90055 12.315 9.5169 9.82395 4.8834 3.64125 5.88045 7.71199 7.676825 7.139274 4.76085 4.76085
Slope Mean Constant
0.839959169 7.942722
Resistance (k ohms)
13
Calculated RCTIME Value
1200 1000 800 600 Series1 400 200 0 0
200
400
600
800
1000
1200
1400
BS2 RCTIME Value
The graph and data help us to develop an equation y = slope x + constant to relate the obtained quantity to what the actual should be. From the above data we obtain the value to the relation of Actual RCTIME (Cr) to the basic stamp RCTIME (Br) as Cr= 0.839959*Br+7.49272
Hence using this equation we can convert the obtained RCTIME in the code to the actual one. To obtain the resistance we divide the values by (600*0.1) and to obtain the value in non decimal format we multiply it by 1000. We get the equation as
Resistance = 13.999*Br+124.8 which we approximated to 14*Br+130.
Using the value obtained we extract each digit and display it on the LCD screen which can bee seen from the code.
The following table exhibits the values obtained from the setup after calibration.
14
Actual Resistance ohms) 0.6 0.83 1 2.2 3.2 5.2 6.4 7.7 8.2 10 12.5 14.59 17.6 20 22.5 44.51 50.11 55.89 60.37 65.26
(k
Measured Resistance Value
% Error
0.662 0.83 0.984 2.16 3.21 5.184 6.402 7.69 8.236 9.93 12.478 14.564 17.658 20.08 22.544 44.51 50.11 55.892 60.372 65.23
9.3655589 0 -1.626016 -1.851852 0.3115265 -0.308642 0.0312402 -0.130039 0.4371054 -0.704935 -0.17631 -0.178522 0.328463 0.3984064 0.1951739 0 0 0.0035783 0.0033128 -0.045991
As can be seen the errors have reduced dramatically and we tend towards accurate measurements of various resistances. This accuracy of course is with reference to the DMM and resistor accuracies.
The EFFECT OF TIME CONSTANT: The time constant is directly proportional to the capacitor being used. Since we are provided with only 2 capacitors (0.1, 1 mu Farads). Keeping the resistance constant if we take a higher capacitor the time constant will be large. larger time constant means more time for capacitor to charge or discharge (i.e. takes more time for transition from digital high to digital low) with the same conditions and with a small capacitor it takes less time to transit from digital high to digital low. Large time constant is sometimes not preferable since it slows down the process but the accuracy level may improve. Small time constant, it speeds up the process but chances are that its accuracy level might be affected. So an optimum value has to be chosen which 15
captures both the accuracy and speed. For this the values of resistance and capacitor needs to be adjusted accordingly. Volts Vs Time
Volts
6 4 2 0 0
100
200
300
Time
The upper curve is the one with large time constant while the lower one is the one with small time constant. What ever is discussed above is clearly captured in the graph. ( Assuming a threshold voltage of 1.5 V it is clear that that the circuit with small time constant crosses this first, also the slope of this line is large than the one with higher time constant which implies chances of inaccuracy creeping in is higher.)
16
IMPLEMENTATION OF PART B The objective of second part was to measure voltage between the ranges 0-5V. the voltage was generated by using the potentiometer provided on the Basic Stamp kit.
Principal Items used Analog to Digital Converter Chip-National Semiconductors ADC0831. Potentiometer.
Usage of Potentiometer The potentiometer was implemented in the following manner : One end is connected to 5V supply.
•
Other end is grounded.
•
Voltage is drawn between the middle point and grounded terminal.
•
The voltage is varied by tightening or loosening the potentiometer knob.
V1 5V
+V
•
R2 10k
Voltage is measured between these two terminals.
Usage of ADC0831 ADC0831 is used to convert the voltage to a synchronous serial signal that can be read by the BASIC stamp with SHIFTIN. The 8-bit result will be from 0 to 255 0 (00000000) corresponds to zero volts 255 (11111111) corresponds to 5 volt s.
17
Each unit therefore corresponds to (5-0)/(255-0) = .01960Volts=19.6milliVolts
For display purpose on LCD the result from Basic Stamp is converted in to millivolts by multiplying by 19.6.This is done by using Multiply Middle Operator (*/). This has the effect of multiplying a value by a whole number and a fraction. The whole number is the upper byte of the multiplier and the fraction is the lower byte of the multiplier.
*/ is clearer to express in hexa decimal since , since hex keeps the contents of upper and lower bytes separate.
To calculate constants for use with the */ instruction, put the whole number portion in the upper byte, then use the following formula for the value of the lower byte:
INT( fraction * 256). 19.6 can be split up in to 19 and INT(0.607*256) The upper byte would be$13 The lower byte would be INT(.607*256)=156($9C) So 19.6 for use with */ would be $139C
A2Dcs A2Dclock A2DData
18
Primary circuit diagram for Part B
P9 P10 P8
The circuit is self explanatory. The voltage to be measured from potentiometer is drawn from middle node and connected to pin 2 of ADC0831, which in turn converts this analog signal to digital form (binary format) which in turn is decoded back in to decimal format for display purpose.
Results: Voltage (Measured)
Binary A/D Value
Voltage Stamp)
(Basic
% Error
0.1
00010000
0.313
-0.0213
1.5
01001110
1.529
-1.93333333
1.99
01100111
2.019
-1.45728643
2.43
01111101
2.451
-0.86419753
2.97
10011010
3.019
-1.64983165
3.52
10110101
3.549
-0.82386364
4.07
11010010
4.117
-1.15479115
4.65
11101111
4.686
-0.77419355
4.98
11111111
5
-0.40160643
-1.00893375
19
6 Basic Stamp Voltage
5 4 3
Series1
2 1 0 0
1
2
3
4
5
6
Actual Voltage
Calibration is not necessary as we felt since our voltmeter was giving precision up to 3 digits where as the DMM was giving only up to 2 places . Also the error found is hardly 1% . if required our voltmeter can be calibrated to match the DMM in the same way as done for the ohmmeter. Comment on Precision of Voltmeter: The voltmeter constructed reads the voltages in multiples of 19.60milli Volts. The precision can be improved by using an ADC chip which is capable of manipulating a 12 bit result (in this case 0-5V will be equivalent to 4096 levels). The more the number of bits an ADC chip is able to handle the better is the precision, but such chips will be costlier so once again compromise has to be made on cost and precision
20
IMPLEMENTATION OF PART C DAC R2R ladder circuit
The project involves an 8-bit digital-to-analog converter that utilizes a resistor ladder network to divide current with equal current sources, and an operational amplifier to sum these currents (LM358) and convert them into an output voltage.
The use of R-2R ladder architecture is very useful for binary-weighted currents. However, the R-2R based converter is easy to implement and the resistance ratio is independent of the number of bits the precision of the resistor is significant. Because the resistance of the R-2R architecture must be so closely matched (as close as 0.01% for the LSB on an 8-bit DAC) and the current ratio through the switches is still large the implementation of current sources is needed. With equal current flow through all the switches the architecture will be slower but more stable.
The R2R Ladder circuit is used in here to increment and decrement the output of Digital to Analog Converter. The input is given in through the Basic stamp pins P12 through P15.Voltage output of the Ladder circuit depends on whether the particular pin/port is High (1) or Low (0) and LED is used as the load for the circuit.
(a) The first part of the circuit consists of a R2R ladder circuit which consist of six 2K ohm resistors and three 1K ohm resistors which are arranged in a parallel and series combination as shown in the figure.
Hardware used: ADC 8031
21
WORKING The circuit is driven into action by pressing the button D1, where it asks for the mode operation. Now it goes into the increment or decrement mode. Thus when D0 is pressed the increment mode is activated. The output increases each time the button is pressed. The corresponding Analog voltage and its bit pattern is displayed on the LCD. This continues till we reach a digital voltage of 16(Binary 1111).After this the display remains stable.
When the D1 button is pressed the decrement mode is activated. This causes the Voltage to decrease now till it reaches a Digital 0.
The observation here was that the analog voltage at Digital 16 which should have been 5 Volts was around 3 Volts which is mainly caused due to the branching of the current in R2R ladder circuit. The LED also begins to glow slowly as the voltage increases, being brightest at Digital 16 voltage.
(b)
The second part of the circuit required us to add a Voltage follower or an OPAMP
to the circuit in order to amplify the magnitude of the voltage. Here the same voltage which is inputted is also got at the output. In short the voltage at the output ‘follows the’ voltage at the input. This is to shunt out the LED and ADC circuits from the ladder circuit.
22
R2R Circuit without OpAmp: ADC Port 2 P15 P14 P13 P12
R2R Circuit with OpAmp: ADC Port 2
P15 P14 P13 P12
23
RESULTS With Op-Amp Voltage (Measured)
Binary A/D Value 0.2 0.41 0.62 0.82 1.03 1.24 1.45 1.63 1.84 2.04 2.25 2.46 2.66 2.87 3.098
Voltage (Basic Stamp)
00001011 00010101 00100000 00101010 00110101 00111111 01001010 01010100 01011110 01101001 01110100 01111110 10001001 10010100 10011110
% Error 0.215 0.411 0.627 0.823 1.039 1.235 1.451 1.647 1.843 2.058 2.274 2.47 2.686 2.902 3.09
-0.00075 -2.43902E-05 -0.000112903 -3.65854E-05 -8.73786E-05 4.03226E -05 -6.89655E-06 -0.000104294 -1.63043E-05 -8.82353E-05 -0.000106667 -4.06504E-05 -9.77444E-05 -0.000111498 2.58231E -05
Without Op-Amp Voltage (Measured)
Binary A/D Value 0.2 0.41 0.62 0.82 1.03 1.24 1.45 1.63 1.79 1.9 2 2.1 2.2 2.29 2.38
00001011 00010101 00100000 00101010 00110101 00111111 01001010 01010100 01011100 01100010 01100111 01101100 01110001 01110110 01111011
Voltage (Basic Stamp)
% Error 0.215 0.411 0.627 0.823 1.039 1.235 1.451 1.647 1.804 1.921 2.019 2.117 2.215 2.313 2.411
-0.00075 -2.43902E-05 -0.000112903 -3.65854E-05 -8.73786E-05 4.03226E -05 -6.89655E-06 -0.000104294 -7.82123E-05 -0.000110526 -9.5E-05 -8.09524E-05 -6.81818E-05 -0.000100437 -0.000130252
24
ISSUES AND PROBLEMS FACED
Like any exercise this one had its share pf problems and issues. The first and foremost was the lack of ports on the basic stamp. When we set out we were planning to use four buttons to implement the manipulation between three parts of the exercises. These lead us to work on expanding out puts by using 74HC595 to connect the LCD to the basic stamp and there by saving 4 basic stamp ports. After a number of tries to implement the same we were unable to do so. The implementation seems pretty straight forward; however we couldn’t narrow in on the cause of our setback. The obvious solution to this issue was to decrease the number of buttons. We were restricted the use of two buttons but aptly adapted by modifying the code and hence series of actions to perform.
The second issue we faced was pertaining to the burning of the LCD and the ADC chip. It was possibly due to incorrect circuit connections in terms of where wires were left exposed and created a short circuit as they must have come in contact. This pointed us towards a careful observation of proper circuit connections coupled with a having on hand a circuit diagram.
The coding never created any major problems and was comfortable after careful study of commands and experiments from the stamp works manual.
The other aspect was pertaining to calibration where we had to collect data to set up an accurate calibration. We took readings up to 10 Kohms of resistance and performed the calibrations but answers were not very accurate. Hence we connected resistors in series and got readings up to 65 kohms which resulted in fairly accurate results.
We were unable to figure out why the maximum voltage with Op Amp is coming out to be nearly 3.09V. We tried to verify using manual calculations but must have faltered at some point as we were getting about 3.3 Volts.
25
SOURCE CODE D ISCUSSION The progression of the setup is clearly indicate in the flow chart and is fairly explained in the source code. The important aspect of the code was that basic stamp doesn’t perform floating point operations and the results can’t be directly displayed on the LCD. The first aspect to take care of was to get the desired results in a non decimal format which we took care of in the equation which was used for calibration. Once this five digit number was obtained (for resistance) the number was parsed to remove each digit and store it in a nib of a declared variable. These nibs were individually displayed on to the LCD. Similar operations were done for displaying voltage. In case of incrementing input for the R2R ladder a variable ‘up’ was declared as OutD corresponding to the four input pins on the basic stamp. On incrementing or decrementing up the inputs were changed one bit at a time and the voltage was displaye d. FLOW CHART DEPICTING THE PROGRESSION OF THE CODE
Start
Home
Wait for Btn D0 or Btn D1keypress
Ohm/Volt
Yes
Is Btn D0 pressed?
No
Inc/Dec
Yes
Is Btn D1 pressed?
26
Ohm/Volt
Wait for Btn D0 or Btn D1keypress
Is Btn Reset pressed?
Change potentiometer position to change voltage value
Measure voltage in circuitry
Home
No
VOLTMETER Voltmeter mode
Yes
Yes
Is Btn D1pressed?
No
OHMMETER Is Btn D0 pressed?
No
Yes
Ohmmeter mode
Keep resistor between the junction points
LCD Display shows voltage in binary and decimal forms Measure resistance in circuitry
LCD Display shows resistance in decimal form in KΩ
Ohm/Volt
27
Inc/Dec
Wait for Btn D0 or Btn D1keypress
Is Btn Reset pressed?
Press D0 to keep incrementing voltage
Measure voltage in circuitry
Home
No
INCREMENT Increment mode
Yes
Yes
Is Btn D0 pressed?
No
DECREMENT Is Btn D1 pressed?
No
Yes
Decrement mode
Press D1 to keep incrementing voltage
LCD Display shows voltage in binary and decimal forms Measure voltage in circuitry
LCD Display shows voltage in binary and decimal forms
Inc/Dec
28
SOURCE CODE: '{$STAMP BS2} '**************************************************************************************** ** '* MECHATRONICS MAE576 '* OBJECTIVE : TO IMPLEMENT THE WORKING OF A BURGLAR ALARM USING BS2 '* TEAM MEMBERS : TALIB, VAMSI, DAVID, JAIRAM, SRINIVAS '* DESCRIPTION : The Code implements the wokring of a multimeter with '* functions to act as voltmeter,ohmeter. Further we have also ‘* implemented a R2R Ladder circuit and established the use of an operational ‘* amplifier '****************************************************************************************
'******************************************** 'Batch B Digital Multimeter '******************************************** '**************************************** 'Declarations for the ohmmeter '**************************************** RCPin RCTm
CON VAR
2 ' RC ohmeter circuit is on BS2 pin 9 Word 'Time for R circuit to change from -5 to 5 V
slope constant
CON CON
14 130
ohms
'calibrated 'calibrated VAR
Word 'This is the value of resistance calculated
'**************************************** 'Declarations for the voltmeter '**************************************** result voltage volts
VAR VAR VAR
Byte Word Word
'**************************************************************************************** 'LCD Variables and Constants '****************************************************************************************
E
CON 0
' LCD Enable pin (1 = enabled) FOR DIR H
RS
CON 3
' Register Select (1 = char)FOR DIR H
LCDbus
VAR OutB
' 4-BITLCD data bus (if connecting to 8-15) pins
ClrLCD
CON $01
' clear the LCD
CrsrHm
CON $02
' move cursor to home position
CrsrLf
CON $10
' move cursor left
CrsrRt
CON $14
' move cursor right
DispLf
CON $18
' shift displayed chars left
29
DispRt
CON $1C
' shift displayed chars right
DDRam
CON $80
' Display Data RAM control
MoveCrsr
CON %10000000
CGRam
CON $40
Line2
CON $C0
'Move Cursor to this position 'Custom Character RAM
'**************************************************************************** 'Pin Declartions For the ADC '***************************************************************************** ADdata
CON 9
ADclock
CON 10
ADcs
CON 8
'******************************************************************************* 'Button Control '******************************************************************************* Btn0 if using 8-15)pins Btn1 swData VAR Byte
CON 1
'Buttons connected to Pins 0, 1 ( use these two
CON 11
'******************************************************************************* 'Counters '******************************************************************************* char
VAR Byte
' character sent to LCD
index
VAR Byte
' loop counter
'This counter is used to manipulate the 4 bit value which is input to R2R Ladder up
VAR OutD
'******************************************************************************* 'Messages to Display on The LCD '*******************************************************************************
Msg
DATA "Pick a Mode
",0 'preload EEPROM with message
Msg1
DATA "Ohmeter Mode
",0
Msg2
DATA "Voltmeter Mode ",0
Msg3
DATA "R2R Increment
",0
Msg4
DATA "R2R Decrement
",0
Msg5
DATA "Up or Down
",0
Msg6
DATA "Ohms or Volts
",0
Msg7
DATA "Choose Mode
",0
CC
DATA $00,$00,$0E,$11,$11,$0A,$1B,$00 'Special Ohm Character
30
'***************************************************************************** 'Initializing the Pins '******************************************************************************
Initialize: DirL =
%11111101
DirH =
%11110111
' setup pins for LCD if using 0-7 pins
HIGH ADcs
'initialize AD chip select for voltmeter
swData=0 RCTm=0 ohms=0 up=0 LOW RCPin GOSUB LCD_Init DownLoad_Chars: char = CGRam GOSUB LCD_Command
' point to CG RAM ' prepare to write CG data
FOR index = CC TO (CC + 7) READ index,char GOSUB LCD_Write NEXT
'****************************************************************************** 'Main Program '****************************************************************************** Main: char=ClrLCD GOSUB LCD_Command index=Msg7 GOSUB ReadCharacter PAUSE 5 ' Directs the User to either the ohms or volts mode or the increment or decrement mode Waiting : BUTTON Btn0,0,255,10,swData,1,State1 BUTTON Btn1,0,255,10,swData,1,State2
31
GOTO Waiting
END
'****************************************************************************** 'Button Manipulation to initialize the setup towards a proper measurement '****************************************************************************** State1: index=Msg6 GOSUB ReadCharacter PAUSE 500 ‘******************************************************************************** ‘Subroutine for setting Ohmmeter or Voltmeter Mode ‘******************************************************************************** Substate1: BUTTON Btn0,0,255,10,swData,1,Calculate_RC BUTTON Btn1,0,255,10,swData,1,Calculate_AD GOTO Substate1
‘******************************************************************************** ‘Subroutine for setting Increment or Decrement Mode Using R2R Ladder ‘********************************************************************************
State2: index=Msg5 GOSUB ReadCharacter PAUSE 500 Substate2: BUTTON Btn0,0,255,10,swData,1,Increment BUTTON Btn1,0,255,10,swData,1,Decrement
GOTO Substate2 '****************************************************************************** ' Subroutine to calculate RC Time and obtain the calibrated Resistance Value ‘ This is called from Substate1 by pressing button D0 '******************************************************************************
Calculate_RC: index=Msg1
32
GOSUB ReadCharacter PAUSE 5 HIGH RCPin
'Discharge the capacitor
PAUSE 1 RCTIME RCPin,1,RCTm
'Get time to logic 0 and the time is stored in RCTm
debug ?RCTm ‘Split the Resistance into its constituent digits to display on the LCD ohms.Nib3= ((slope*RCTm)+constant)/10000
'ten thousand place
ohms.Nib2= ((slope*RCTm)+constant)//10000/1000 'thousands place ohms.Nib1= ((slope*RCTm)+constant)//10000//1000/100 'hundred's place ohms.Nib0= ((slope*RCTm)+constant)//10000//1000//100/10 'ten's place GOSUB DisplayResistance ' Display each digit appropriately LOW RCPin index=0 GOTO Substate1
'*********************************************************************** ' Subrotuine to calculate voltage using AD Converter ‘ This is called from Substate1 by pressing button D1 '*********************************************************************** Calculate_AD: index=Msg2 GOSUB ReadCharacter PAUSE 500 GOSUB ReadADC0831 voltage = result */ $139C ' Convering 8 Bit result into to voltage
'Split the Voltage into its constituent digits to display on the LCD volts.Nib3 = voltage/1000 volts.Nib2 = voltage/100//10 volts.Nib1 = voltage/10//10 volts.Nib0 = voltage/1//10 GOSUB DisplayVoltage ' Display each digit appropriately
GOTO Substate1
33
ReadADC0831: LOW ADcs SHIFTIN ADdata,ADclock, MSBPost,[result\9] 'ADC Returns a 8 Bit value for Voltage HIGH ADcs RETURN '****************************************************************************** ' Subrotuine to increment voltage using R2R Ladder Circuit ‘ This is called from Substate2 by pressing button D0 '****************************************************************************** Increment: up=up+1 PAUSE 500 LOW ADcs SHIFTIN ADdata,ADclock, MSBPost,[result\9] voltage = result */ $139C
HIGH ADcs volts.Nib3 = voltage/1000 volts.Nib2 = voltage/100//10 volts.Nib1 = voltage/10//10 volts.Nib0 = voltage/1//10
GOSUB DisplayVoltage GOTO Substate2 '****************************************************************************** ' Subrotuine to decrement voltage using R2R Ladder Circuit ‘ This is called from Substate2 by pressing button D1 '****************************************************************************** Decrement: up=up-1 PAUSE 500 'index=Msg4 'GOSUB ReadCharacter 'PAUSE 5 LOW ADcs SHIFTIN ADdata,ADclock, MSBPost,[result\9]
34
HIGH ADcs voltage = result */ $139C volts.Nib3 = voltage/1000 volts.Nib2 = voltage/100//10 volts.Nib1 = voltage/10//10 volts.Nib0 = voltage/1//10 GOSUB DisplayVoltage GOTO Substate2 equate1: up=0 GOTO here1
'**************************************************************************************** 'Display Digit by Digit Resistance On The LCD ‘This routine is called from Calculate_RC '**************************************************************************************** DisplayResistance: char = MoveCrsr + 64 GOSUB LCD_Command
'Move Cursor to the next Line
char = ohms.Nib3 + 48 GOSUB LCD_Write
'Displaying digit by converting into its ascii value
char = ohms.Nib2 + 48 GOSUB LCD_Write char = %0101110 GOSUB LCD_Write
'Displaying Decimal Point
char = ohms.Nib1 + 48 GOSUB LCD_Write char = ohms.Nib0 + 48 GOSUB LCD_Write char = 48 GOSUB LCD_Write char = 107 GOSUB LCD_Write READ CC,char
'Displaying the ohm symbol
GOSUB LCD_Write
RETURN
'************************************************************************************** 'Display Digit by Digit Voltage On The LCD with Binary Representation on the first line ‘and voltage on the other.
35
‘This routine is called from Calculate_AD '**************************************************************************************** DisplayVoltage: char = ClrLCD GOSUB LCD_Command GOSUB DisplayBits char = volts.Nib3 + 48 GOSUB LCD_Write char = %0101110 GOSUB LCD_Write
'Display Decimal Point
char = volts.Nib2 + 48 GOSUB LCD_Write char = volts.Nib1 + 48 GOSUB LCD_Write char = volts.Nib0 + 48 GOSUB LCD_Write char = 48 GOSUB LCD_Write char = 86 GOSUB LCD_Write
'Displaying the 'V'
RETURN '**************************************************************************************** 'Display Binary Representation of Voltage On The LCD ‘ This is part of the above routine and has been created for clarity '**************************************************************************************** DisplayBits: char = result.Bit7 + 48 GOSUB LCD_Write char = result.Bit6 + 48 GOSUB LCD_Write char = result.Bit5 + 48 GOSUB LCD_Write char = result.Bit4 + 48 GOSUB LCD_Write char = result.Bit3 + 48 GOSUB LCD_Write char = result.Bit2 + 48 GOSUB LCD_Write char = result.Bit1 + 48 GOSUB LCD_Write char = result.Bit0 + 48 GOSUB LCD_Write
36
char = MoveCrsr GOSUB LCD_Command
+ 64
RETURN
'**************************************************************************************** 'LCD Read The character from Messages and Sets the cursor in the LCD '**************************************************************************************** ReadCharacter: char=CrsrHm GOSUB LCD_Command Read_Char: READ index, char ' get character from EEPROM IF (char = 0) THEN Msg_Done ' if 0, message is complete GOSUB LCD_Write ' write the character index = index + 1 ' point to next character GOTO Read_Char ' go get it Msg_Done: ' the message is complete index=0 RETURN ' do it all over
'**************************************************************************************** 'Initialize The LCD '****************************************************************************************
LCD_Init: PAUSE 500
' let the LCD settle
LCDbus = %0011
' 8-bit mode
PULSOUT E, 1 PAUSE 5 PULSOUT E, 1 PULSOUT E, 1 LCDbus = %0010
' 4-bit mode
PULSOUT E, 1 char = %00001100 ' disp on, crsr off, blink off GOSUB LCD_Command char = %00000110 ' inc crsr, no disp shift GOSUB LCD_Command RETURN
37
'*********************************************************** 'Low the RS to Write to The LCD '***********************************************************
LCD_Command: LOW RS ' enter command mode '************************************************************ 'Write to the LCD '************************************************************
LCD_Write: LCDbus = char.HighNib ' output high nibble PULSOUT E, 1 ' strobe the Enable line LCDbus = char.LowNib ' output low nibble PULSOUT E, 1 HIGH RS ' return to character mode RETURN
'****************************************************************
38
CONTRIBUTION
Vamsi Krishna.P – Performed integration of hardware for the set up and primary role in documentation and calibration.
Talib.S.Bhabhrawala – Performed integration of the code for the setup and primary role in documentation and calibration.
Srinivas.Sundaragopal – Studied and setup Part A of the lab and assisted in documentation for the same.
David Perikak- Studied and setup Part B and assisted in documentation of the same.
Jairam.Ramnaswamy – Studied and setup Part C and assisted in the documentation of the same.
INFERENCE AND CONCLUSION The accuracy we obtained for various measurements was appreciable and definitely served the tasks that were set down.
39
Further the purpose of learning analog to digital conversion and asses its probable uses for future purposes was thoroughly served. We definitely extended our knowledge of basic stamp and new aspects of programming especially floating point manipulation and interfacing concepts.
References: www.parallax.com www.eng.buffalo.edu/Courses/mae576 www.maelabs.ucsd.edu/mae_ds/stamp/how/programing/basics.html Stamp Works Manual. http://www.national.com/pf/LM/LM358.html http://www.national.com/pf/AD/ADC0831.html
40