MAE576 GroupD LAB2 Report

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 53

LAB 2: MULTIMETER

Mechatronics 576
Spring 2010
March 25th 2010

“Group D”

Priyanshu Agarwal
Dipen Harishbhai Dave
Ravikiran Chollangi
Jason Lieu

Department of Mechanical and Aerospace Engineering


State University of New York at Buffalo
Buffalo, New York 14260
Abstract
The major goal of this lab assignment was to develop a digital multi-meter. The basic interfacing of
LCD module, shift register 74X165, shift register 74x595, ADC, operational amplifier, relay, MOSFET
is achieved with the BASIC Stamp II. A digital multi-meter is developed which operates in four modes
i.e. Ohmmeter, Voltmeter, Digitally Controlled Voltage Source using R-2R, Digitally Controlled
Voltage Source using PWM. All the modes also provide the feature to make multiple measurements and
retain the last two readings. In addition to this the developed multi-meter also offers a feature to check
the continuity of a circuit. Also, the system has the feature of Auto Sleep Mode which kicks in when the
system is idle for some time. The multi-meter also provides visual cues to the user for user friendliness.
Contents
Abstract 
 
Contents 
1. Introduction 
1.1 Design Objective 
1.2 Features of Digital Multi‐meter 
1.3 User Operation Instructions 

2. Hardware 
2.1 List of Components 
2.2 Microcontroller (Basic Stamp 2) Pin Assignment 
2.3 Hardware Description 
2.4 Circuit Diagrams 

3. Software 
4. Mathematical Methods 
4.1 Principle for Digital Ohmmeter 
4.2 Principle for Digital Voltmeter 
4.3 Principle for Digitally Controlled Voltage Source Using R‐2R Ladder 
4.4 Principle for Digitally Controlled Voltage Source Using PWM 

5. Implementation 
5.1 Software Algorithms 
5.1.1 Overall System Flowchart 
5.1.2 Ohmmeter Mode (D0) Flowchart 
5.1.3 Voltmeter Mode (D1) Flowchart 
5.1.4 Digitally Controller Voltage Source Mode using R‐2R (D2) Flowchart 
5.1.5 Digitally Controller Voltage Source Mode using PWM (D3) Flowchart 
5.2 Subroutines 

6. Testing & Calibration  
6.1 Ohmmeter 
6.2 Voltmeter  
6.3 Digitally Controlled Voltage Source 
 
7. Discussion 
8. Conclusion 

Bibliography 
 
Appendix 
 
A. PBASIC Code for Digital Multi‐meter 

B. Data Sheets  

B.1 ADC0831, 8‐Bit Serial I/O A/D Converter 

B.2 LM358, Low Power Dual Operational Amplifier 
 
B.3 74HC595 8‐bit serial‐in, serial or parallel‐out shift register with output 
latches 
 
 
1. Introduction
A multi-meter, also known as a volt/ohm meter or VOM, is an electronic measuring instrument that
combines several measurement functions in one unit [1]. A typical multi-meter may include features
such as the ability to measure voltage, current and resistance. They can be used to troubleshoot electrical
problems in a wide array of industrial and household devices such as batteries, motor controls,
appliances, power supplies, and wiring systems. There are two categories of multi-meters, analog multi-
meters and digital multi-meters (often abbreviated DMM or DVOM.).

In this assignment a digital multi-meter is to be developed that is capable of acting as an Ohmmeter, a


Voltmeter and a Digitally Controlled Voltage Source (Digital to Analog converter). The interfacing of
the microcontroller with few electronic components like LCD, switches using shift-in register, shift
register to expand outputs, ADC, Operational amplifier, relay and MOSFET is achieved. The above
mentioned components work in an integrated fashion to act as a digital multi-meter. In order to enhance
the features of the multi-meter the features available in the current multi-meters are studied. It was
decided that as far as possible the developed multi-meter should emulate these features. It was decided
that in addition to the above mentioned features out multi-meter should have a feature to retain earlier
measurement for better comparison. It should also provide a feature to check the continuity of a circuit
for debugging which often is the application a multi-meter ends up getting used.

1.1 Design Objective


The following are the design objectives for the developed digital multi-meter:
(i) It should be capable of measuring a resistance value ranging from 1KΩ to 10 KΩ
(ii) It should be capable of measuring a voltage value lying between 0V to 5V
(iii)It should also have the capability of generating a demanded voltage output thus acting as a Digitally
Controlled Voltage Source both using R-2R ladder and PWM.
(iv) It should also provide a feature to check the continuity of a circuit, a feature typically provided by
most multi-meters.
(v) It should, if possible, have power saving techniques.
(vi) It should be user friendly.

1.2 Features of Digital Multi-meter


This section describes the various features of the digital multi-meter developed.

1. Modes of Operation – In order to serve multiple purposes the digital multi-meter has the
following modes of operation:
(i) Ohmmeter Mode – In this mode of the digital multi-meter any value of resistance that lies
between 1K and 10K can be measured. The measured resistance is displayed on the LCD.

Ohmmeter Mode (D0) Voltmeter Mode (D1)


Digitally Controlled Voltage Source using R-2R (D2) Digitally Controlled Voltage Source using PWM (D3)

(ii) Voltmeter Mode – In this mode of the digital multi-meter a voltage from 0V to 5V can be
measured. The measured voltage will be displayed on the LCD.

(iii) Digitally Controlled Voltage Source Mode using R-2R Ladder - In this mode the digital multi-
meter can act as a voltage source generating a voltage between 0V to around 3V. The voltage can be
increased or decreased in steps of around 0.2V. The current voltage will be displayed on the LCD.

(iv) Digitally Controlled Voltage Source Mode using PWM – This mode of the digital multi-meter
resembles the digitally controlled voltage source mentioned previously in its function. However, now
the technique of Pulse Width Modulation is used to obtain voltages ranging from 0V to around 3V. Here
the voltage can be increased or decreased in steps of around 0.07V. The current voltage will be
displayed on the LCD.

(v) Continuity Check Mode – This mode of the digital multi-meter provides the capability to debug
a circuit by providing the ability to check the continuity of a circuit. This feature can be used
simultaneously with any of the above mentioned modes.

Please note that the images shown above are from the actual setup.

2. User Input – The system is based on the input provided by the user. It seeks input from the user
using a set of 8 switches with different roles assigned to each switch based on the current state of the
operation of the digital multi-meter. The following inputs are acquired in different scenarios:
(i) At the beginning the switches D0/D1/D2/D4 can be pressed to select a particular mode.
(ii) Once the user has entered a particular mode the switch D6 provides the option to hold the last
reading and continue with the next measurement.
(iii) The switch D7 also provides the option to return to the main screen.
(iv) In Digitally Controlled Voltage Source Mode switches D4/D5 can be pressed to
decrease/increase the voltage generated by the multi-meter.
(v) Also the user can check the continuity during any of the above mentioned modes by connecting
the two leads available with the circuit to be debugged.
(vi) In any of the above mentioned modes the system can be switched to any of the available modes
without returning to the main screen.

Select Mode Screen


3. Hold On – The multi-meter also provides a feature to hold the last reading and continue with the
next measurement. This feature becomes important when it comes to compare two resistances or two
voltages in a circuit. The current measurement is the one that is blinking on the LCD. Furthermore, it
can be used to hold multiple times with the capability of retaining last two measurements.

Digital Multi-meter with hold on in Digital Multi-meter with hold on in


Resistance Mode Voltage Mode

4. Auto Sleep Mode – In order to save power which is always the case in multi-meter, the system
implements the feature of auto sleep mode. When no key is pressed in idle or any of the modes the
system automatically turns off the LCD in order to saver power. However, the state of LCD i.e. the last
measurement is retained.

5. Visual Cues – In order to be user-friendly the watch has the following features to guide the user:
(i) Display the selected mode on LCD
(ii) Blinking measurement value signifying that it is the current measurement.
(iii)Visual message on 7-Segment with CCCC which stands for continuous circuit during Continuity
Checking.
(iv) Invalid input message feedback when wrong key is pressed.

“CCCC” Message on 7-Segment Display Invalid input message when wrong key is pressed

1.3 User Operation Instructions


The following are the instructions for the user to operate the developed Digital Multi-meter:

1. The digital multi-meter starts with a message i.e. “Digital Multimeter” on the LCD.

2. It will provide the user a visual cue on the LCD asking the user to select a mode out of the available
four modes (D0/D1/D2/D3). The user is expected to press D0/D1/D2/D3 button provided on the
board. In case any other button is pressed it will provide a feedback to the user with a “Invalid
Input!” message on the LCD.

3. When the user presses the D0 button, the Ohmmeter mode is selected. The variable resistance in the
circuit can then be varied to note the change in the value of resistance displayed on the LCD. The
selected mode will be displayed on the LCD in second line.
4. While the multi-meter is in Ohmmeter mode the user can press Hold On (D6) /Main Menu (D7)
button to hold the current reading and continue measuring the next or to return to the main menu.

5. When Hold On (D6) is pressed the multi-meter holds the last reading and moves on to the next
measurement by displaying the current measurement in the second line on LCD. Further mode the
current measurement is the one that is blinking on the LCD. Any further pressing of Hold On (D6)
will retain the latest value of measurement and switch the current measurement value to the other
line.

6. In order to switch mode the user can either return to the main menu by pressing Main Menu (D7) or
simply press the specific mode key (D0/D1/D2/D3). Based on the selection the multi-meter will
operate in the specified mode.

7. In case Voltmeter Mode (D1) is selected the analog voltage from a variable resistor can then be
measured. The value of measurement can be changed by changing the resistance of the variable
resistor. Here also the feature of Hold On (D6) / Main Menu (D7) works as explained above.

8. In case Voltage Mode R-2R (D2) is selected the multi-meter acts as a Digitally Controlled Voltage
Source with current voltage being displayed on the LCD using R-2R ladder. The value of voltage
can be increased in steps of around 0.2V by pressing Increase Voltage (D5) or Decrease Voltage
(D4) key. The key can be held for fast increment or decrement of the value. The feature of Hold On
(D6) / Main Menu (D7) still exists.

9. In case Voltage Mode PWM (D3) is selected the multi-meter acts as a Digitally Controlled Voltage
Source with current voltage being displayed on the LCD now using PWM. The value of voltage can
now be increased more precisely i.e. in steps of around 0.07V by pressing Increase Voltage (D5) or
Decrease Voltage (D4) button. The feature of fast increment or decrement, Hold On (D6) / Main
Menu (D7) still exists.

10. In addition to the above modes the digital multi-meter is by default set to the sleep mode which will
be invoked if the watch is idle for around 45 seconds. In case of sleep mode the LCD is turned off
with its status still retained in the memory. The sleep mode kicks in when the multi-meter is either
idle with no mode selected or it is in any of the modes with no user input.

11. The multi-meter in addition to the above mentioned modes also provides an option to check the
continuity of a circuit. To check the continuity, just connect the two leads provided, to the circuit to
be checked. In case the circuit is found to be continuous the 7-Segement will display a message
“CCCC” signifying continuous circuit. This mode works independent of the other modes can be
used while the multi-meter is in any of the above mentioned modes.
2. Hardware
The following sections deals with the details of the hardware used to implement the digital stop watch.

2.1 List of Components


S. No. Component Quantity
1. BASIC Stamp Kit NX-1000 1
2. BASIC Stamp Module II 1
3. Hitachi LCD Module , HD44780 1
4. 74HC595 Shift Register 1
5. 74HC165 Shift Register 1
6. SPDT Relay 1
7. IRF540 MOSFET 1
8. ADC8031 1
9. LM358 Opamp 1
10. 7-Segment LED Display 4
11. LED 1
12. Switch 8
13. 10K Resistor 2
14. 5K Resistor 1
15. 2K Resistor 6
16. 1K Resistor 3
17. 220Ω Resistor 2
18. 0.1 uF Capacitor 1
19. 10K Variable Resistor 2
20. IN4003 Diode 2

The total cost of the system is around 300$ including the kit.

2.3 Microcontroller (BASIC Stamp 2) Pin Assignment

Pin No. I/O Description


0 Output LCD Enable Pin
1 Output RC Circuit Pin
2 Output ADC0831 Chip Select Pin
3 Output LCD Register Select Pin
4 Output LCD Data Pin
5 Output LCD Data Pin
6 Output LCD Data Pin
7 Output LCD Data Pin
8 Output Shift Register 74X165 Clock Pin
9 Input Shift Register 74X165 Data In Pin
10 Output Shift Register 74X165 Load Pin
11 Output ADC0831 Clock Pin
12 Output ADC0831 Data Pin
13 Output 74HC595 Shift Register Clock Input Pin
14 Output 74HC595 Serial Data Input Pin
15 Output 74HC595 Storage Register Clock Input Pin
The pin directions as defined in PBASIC code is as follows:
DIRL = %11111001

2.2 Hardware Description


Basic Stamp Kit INEX-1000

http://www.mouser.com/catalog/supplier/library/ParallaxMiniCatalog.pdf

1. INEX-1000 is a high-quality prototype and experiment area for all 24-pin BASIC Stamp modules
2. Audio amplifiers with screw terminals for 8 ohm speakers. an audio amplifier for external speakers
and current limit resistors sized for driving more LEDs. 510 ohm resistors allow more LED driving.
3. Board provides socket ports for each BASIC Stamp I/O pin.
4. A parallel LCD with cable.
5. 16 LEDs to monitor I/O pin status.
6. DB-9 connector for program download and debugging.
7. 4-digit LED 7-segment display with common cathode.
8. 8 pushbutton switches (active low without pull-up resistors) 8 DIP switches (with built-in pull-up
resistors)
9. ULN2003 high-current driver for relay and stepper motors
10. Pulse generator for 1Hz, 10 Hz, 100 Hz, and 1 kHz
11. RS-232 interface port for communication with COM program
12. Socket for 24-pin BASIC Stamp modules
13. Parallel LCD module with connector and brightness control
14. Piezospeaker
15. 10K potentiometer
16. 2.5" x 7" breadboard with 800 contact points
17. 7.5V DC 1 amp power supply with polarity protection
Source: http://www.apexvalue.com/basic_stamp/product_id_28135.htm

Basic Stamp II Module


Microcontroller PIC 16C57 C signifies EPROM program memory
Processor Speed Max Operation Frequency 20 MHz
Program Execution Speed ~4,000 PBASIC instructions/sec
Current Draw @ 5 VDC 3mA Run, 50 μA Sleep
Package 28-pin DIP
Max Source / Sink Current by any I/O pin 20mA/25mA
EEPROM (Program) Size: 2 Kbytes ~500 PBASIC instructions
RAM Size: 32 Bytes (6 for I/0, 26 for Variable)

Hitachi LCD Module, HD44780

http://www.nipahut.com.ph
‐ 16 x 2 Alphanumeric characters
‐ 4-bit or 8-bit MPU interface enabled

74HC165 Shift Register

www.seeedstudio.com

This shift register allows a microcontroller to read a large number of digital inputs using just three
microcontroller pins. Each 74HC165 provides 8 input pins. Any number of 74HC165 chips can be
cascaded using the same set of microcontroller pins. It has synchronous serial input.
774HC595 Sh hift Registerr
T 74HC5995 is a shift register whiich is used too expand thee outputs froom the microo-controller.. It 8 bits
The
o data is cloocked into th
of he IC via twoo lines, and when
w third line
l is toggleed, it pops thhese settingss out on 8
o
outputs on thhe IC. So by
y using 3 valuuable lines of
o the microccontroller 8 outputs can be obtainedd. This is
c
called "Shiftting data ou
ut" of the miicrocontrolleer by "synchhronous seriial communiication". Thhe data is
s
shifted seriallly from the micro-controller, where each bit is "shifted
" in" one
o at a timee, then the chhips

http://www
w.solarboticcs.com

o
output the daata in paralleel.

Specificationns:
S
• 8-bit
• Logic Fa amily : HC
• Logical Function
F : Sh
hift Registerr
• Operating Supply Vo oltage (Typ) : 5V
• Output Type
T : 3-Statee
• Propagattion Delay Time
T : 265ns
• Operating Supply Vo oltage (Min) : 2V
• Operating Supply Vo oltage (Max)) : 6V

7
7-Segment D
Display

ADC0831
A
A
ADC0831 is a 8-bit succcessive approoximation A/D
A converterr with a serial I/O. The serial
s I/O is
c
configured too comply wiith the NSC MICROWIR RE™ serial data
d exchangge standard for easy inteerface to
t COPS™ family of prrocessors, annd can interfface with standard shift registers
the r or µPs.
µ The diff fferential
a
analog voltagge input allo
ows increasinng the comm mon-mode reejection and offsetting thhe analog zerro input
v
voltage valuee. In additionn, the voltagge reference input can bee adjusted to allow encodding any smaaller
a
analog voltagge span to thhe full 8 bits of resolution.

K Specificcations:
Key

Paramaaters / Valuees ADC08831


Resolution 8 bits
Input Channels 1
Max KSample Rate 31 ksps
Max Sample Rate 0.031 MSPS

SPDT Relay

http://www.the12volt.com/relays/relays.asp

SPDT Relay: Single Pole Double Throw Relay is an electromagnetic switch, consisting of a coil
(terminals 85 & 86), 1 common terminal (30), 1 normally closed terminal (87a), and one normally open
terminal (87). When the coil of the relay is at rest (not energized), the common terminal (30) and the
normally closed terminal (87a) have continuity. When the coil is energized, the common terminal (30)
and the normally open terminal (87) have continuity. The diagram below center shows the relay at rest,
with the coil not energized. The diagram below right shows the relay with the coil energized. As you can
see the coil is an electromagnet that causes the arm that is always connected to the common (30) to pivot
when energized whereby contact is broken from the normally closed terminal (87a) and made with the
normally open terminal (87).

LM358

http://www.sparkfun.com/

The LM358 is a dual-channel operational amplifier (opamp). LM358 applications include


transducer amplifiers, DC gain blocks and all the conventional opamp circuits.

Features:

• Two internally compensated op-amps


• Internally frequency compensated for unity gain
• Large DC voltage gain: 100 dB
• Wide bandwidth (unity gain): 1 MHz (temperature compensated)
• Wide power supply range:
o Single supply: 3V to 32V
o or dual supplies: ±1.5V to ±16V
2.4 Circuit Diagrams
HD44780 LCD Module Interface Circuit

P4 D4

P5 D5

P6 D6

Hitachi LCD Module


P7 D7 HD44780

P3 RS

P0 E

R/W
4.7K

Vss Vss

P0, P3, P4, P5, P6, P7 are the inputs from microcontroller.
P4-P7 are data pins
P0 is used to enable the LCD module while P3 selects the LCD register to be used.
R/W is grounded since only data is written on the LCD.

Shift Register 74HC165 Interface Circuit


P8: Clock Pin input to 74X165
P9: Data In from the display driver
P10: Load pin input
D0-D7 takes inputs from the corresponding switches (Miniature Single Pole Single Throw Switches)
connected. 10K resistors are pull-up resistors

Digital Ohmmeter Circuit

This circuit consists of a constant resistor of 220Ω, a variable resistor of 10K and a capacitor of 0.1 uF.
When the micro-controller pin P1 is high the capacitor gets discharged. Now, when the pin becomes low
it starts charging and recording the time taken for charging the resistance in the circuit is determined.

Digital Voltmeter Circuit


The digital voltmeter is based on the measurements done using ADC0831. A relay is used in this circuit
as only single ADC was to be connected to micro-controller due to shortage of pins. Thus, the same
ADC is being used in multiple modes to convert analog voltage to digital. Furthermore, in order to
switch the relay a MOSFET IRF540 is used.

Digitally Controlled Voltage Source Using R-2R Ladder & PWM without
Operational Amplifier
The circuit shown above is used to generate digitally controlled voltage using an R-2R ladder without an
operational amplifier. Now, since the voltage generated by the R-2R ladder as well as the voltage
generated using PWM is to be connected to the same terminal of the relay diodes are provided for
isolating the two circuits.

Digitally Controlled Voltage Source Using R-2R Ladder & PWM with Operational
Amplifier

The circuit shown above shows the use of operational amplifier both for R-2R ladder and PWM when
voltage is generated by a digitally controlled voltage source. The use of operational amplifier also
improves the performance of the system as it keeps the output voltage constant even when the load
(LED) is connect to it.
Circuit for Continuity Checking

The circuit shown above shows a simple circuit used to check the continuity in any circuit. The circuit to
be checked is place between a 5V supply and the 7 –segment display with appropriate connections as
shown above. When the circuit is continuous the 7-segment glows.
Complete Circuit Diagram for Digital Multi-meter
3. Software
The following section presents a basic overview of the important commands used while implementing
the system.

The PBASIC version 2.5 is used to program the BASIC Stamp II module [2]. The following special
commands are used to program the module:

1. RCTIME – Measure time while Pin remains in State; usually to measure the charge/discharge time
of resistor/capacitor (RC) circuit.
Syntax: RCTIME Pin, State, Variable

2. PWM - Convert a digital value to analog output via pulse-width modulation.


Syntax: PWM Pin, Duty, Duration
4. Mathematical Methods
4.1 Principle for Digital Ohmmeter
The resistance measurement is based on a RC circuit.

A general RC circuit [1] Circuit used in the system

When a circuit consists of only a charged capacitor and a resistor, the capacitor will discharge its
stored energy through the resistor. The voltage across the capacitor, which is time dependent, can be
found by using Kirchhoff's current law, where the current through the capacitor must equal the
current through the resistor. This results in the linear differential equation

The solution to the above mentioned differential equation is given by:


1

where V0 represents the voltage in the capacitor and is the time constant of the system.
The system takes around four time constant to reach 98.16% of the final value.

In our case the capacitor is first fully discharged and then charged. By measuring the time for the
capacitor is in charged state i.e. its voltage is above 1.4V the resistance in the circuit can be
determined for a known C using the following formula:

4
1.4

However, the resistance values recorded using above formula vary from the actual reading and so
finally a calibration is done and the multi-meter works based on this calibration equation. The details
of calibration are mentioned in the Testing and Calibration section.

4.2 Principle for Digital Voltmeter


The digital voltmeter is based on the principle of conversion of analog voltage to digital voltage
using an Analog to Digital Converter (ADC). The ADC accepts an analog voltage and gives out an
equivalent digital output for the measured voltage which can then be converted to the actual voltage
based on the fact that highest value on the digital scale (255) corresponds to a voltage of 5V and the
lowest value (0) corresponds to 0V.

4.3 Principle for Digitally Controlled Voltage Source Using R-2R Ladder
A resistor ladder is an electrical circuit made of repeating units of resistors [1]. It is a simple and
inexpensive way to perform digital-to-analog conversion, using repetitive arrangements of precision
resistor networks in a ladder-like configuration.

A basic R-2R resistor ladder network is shown in the figure above. Bit4 MSB (most significant bit)
to Bit0 LSB (least significant bit) are driven from digital logic gates. Ideally, the bits are switched
between 0 volts (digital 0) and Vref (digital 1). The R-2R network causes the digital bits to be
weighted in their contribution to the output voltage Vout. In this circuit 5 bits are shown, giving 32
possible outputs. Depending on which bits are set to 1 and which to 0 the output voltage (out) will be
a stepped value between 0 volts and (Vref minus the value of the minimum step, Bit0). The actual
value of Vref (and 0 volts) will depend on the type (technology) of the digital logic gates used to
drive Bit4-0.

For a digital value VAL, of a R-2R DAC of N bits of 0 V/Vref, the output voltage Vout is:

Vout = Vref × VAL / 2N

4.4 Principle for Digitally Controlled Voltage Source Using PWM


Pulse-width modulation (PWM) is a very efficient way of providing intermediate amounts of
electrical power between fully on and fully off. A simple power switch with a typical power source
provides full power only, when switched on. The term duty cycle describes the proportion of on time
to the regular interval or period of time; a low duty cycle corresponds to low power, because the
power is off for most of the time. Duty cycle is expressed in percent, 100% being fully on.
The waveform shown above represents the voltage signal amplitude against time. As the duty cycle
of the pulse is changed the average voltage obtained as output varies based on the pulse on time and
pulse off time.

In our system the variable voltage is developed by varying the on time and off time of the pulse
based on the input provided by the user.
5. Implementation
The following section details the algorithms used along with the various subroutines used to implement
them.

The following figure shows the final setup of the system implemented using NX-1000 Experiment
Board.

5.1 Algorithms

The following section presents the various algorithms used to implement different modes in the system.
The different algorithms used are as follows:

1. Overall System Flowchart


2. Ohmmeter Mode (D0) Flowchart
3. Voltmeter Mode (D1) Flowchart
4. Digitally Controlled Voltage Source Mode using R-2R (D2) Flowchart
5. Digitally Controlled Voltage Source Mode using PWM (D3) Flowchart
5.1.1 Overall System Flowchart
5.1.2 Ohmmeter Mode (D0) Flowchart
5.1.3 Voltmeter Mode (D1) Flowchart
5.1.4 Digitally Controller Voltage Source Mode using R-2R (D2)
Flowchart
5.1.5 Digitally Controller Voltage Source Mode using PWM (D3)
Flowchart
5.2 Subroutines
In order to achieve efficiency the code is subdivided into subroutines so as to have an ability to execute
the same piece of code as and when required. The subroutines used in the program can be categorized in
the following major categories:

1.Initialization Subroutines – The following subroutines are used for initialization of variables and
display messages in different modes:
(i) LCD Initialization – Initializes the LCD for display.

2.Mode Subroutines – The following subroutines are used for implementing different modes available in
the system:
(i) RMode – To implement the digital ohmmeter mode of the system
(ii) VMode – This subroutine implements the digital voltmeter mode.
(iii) DVSR2RMode – This implements digitally controlled voltage source using R-2R ladder mode.
(iv) DVSPWMMode – This implements digitally controlled voltage source using PWM mode.

3.Display Subroutines – The following subroutines are used for display of messages, characters and
digits on LCD and 7-Segment Display:
(i) LCD Write – Writes a character on the LCD module.
(ii) LCD digit display – Displays digit on the LCD module.
(iii) LCD Message Write – Writes EEPROM stored messages on the LCD module.
(iv) LCD Clear All – Clear the entire LCD module.
(v) LCD Clear Line – Clear the first/second line of LCD module.
(vi) Show Resistance – Show resistance value on LCD module.
(vii) VDisp – Read value from ADC and calculate voltage using appropriate calibration equation
(viii) Show Voltage – Display voltage value on LCD module.

4.Hardware Subroutines – The following subroutines are used to read/write on specific hardware present
in the circuit:
(i) Read Switch - Read the switch values from the shift register.
(ii) Out595 – Output data to the shift register 74X595.
(iii) Read0831 – Read data from the ADC0831.

5.Power Saving Subroutines – The following subroutines performs the necessary task of putting the
system in sleep mode for power saving.
(i) Shutdown – Shuts down the LCD and 7-Segment display for power saving and keeps the program
control in a loop until a key is pressed.
(ii) IdleCheck – Increment the system idle counter and check whether the specified time limit has been
exceeded in which case it invokes the Shutdown subroutine.

6.Misc Subroutines – The following subroutines perform the tasks pertaining to the other features in the
system
(i) Hold On – This subroutine takes care of the hold on state of the system in each mode.
6. Testing & Calibration
The designed system was tested for accuracy of the measured value. Also, different calibrations are
carried out in order to improve the accuracy of the system.

6.1 Ohmmeter
The digital ohmmeter showed deviations between the actual resistance value and the measured
resistance value when evaluate using the formula. The following table shows the actual value of the
resistance along with the resistance evaluated.
Test Data for Digital Ohmmeter

S. No.  Actual  RCTIME Charging  Evaluated  Fitted 


Actual Resistance
Capacitance  Time  Resistance  Resistance 
   uF  Ohm  (2 usec)  Ohm  Ohm 
1  0.0000001  16  1  14.21084277  246.99 
2  0.0000001  1010  56  795.807195  1049.44 
3  0.0000001  2000  123  1747.933661  2026.97 
4  0.0000001  3010  191  2714.270969  3019.09 
5  0.0000001  4000  262  3723.240805  4054.98 
6  0.0000001  5005  334  4746.421485  5105.46 
7  0.0000001  5990  399  5670.126265  6053.81 
8  0.0000001  7010  472  6707.517787  7118.88 
9  0.0000001  8005  541  7688.065938  8125.59 
10  0.0000001  9005  612  8697.035774  9161.48 
11  0.0000001  9530  650  9237.0478  9715.9 

Resistance Calibration Curve
y = 14.48x + 166.1
Measured Resistance Fitted Plot R² = 0.999
12000
Actual Resistance (Ohm)

10000

8000

6000

4000

2000

0
0 100 200 300 400 500 600 700

Time from RCTIME (2us)
However, in order to improve the accuracy of the system a calibration plot was obtained between actual
resistance and the charging time measured using RCTIME command. The plot came out to be fairly
linear. So, the linear fit equation is obtained and implement in the system for resistance evaluation for
display. The system has an error of approximately 2% after calibration.

6.2 Voltmeter
A calibration is also carried out for the developed Voltmeter. The measured value came out to be highly
accurate with a regression coefficient of around 1. The system calculates the voltage using the equation
for display as the error is below 0.8%.

Test Data for Digital Voltmeter

S. No.  Actual  Calculated 


Voltage  Voltage 
   V  V 
1  4.96  5 
2  4.49  4.549 
3  4  4.059 
4  3.5  3.529 
5  3  3.039 
6  2.5  2.529 
7  2  2.039 
8  1.5  1.509 
9  1  1.019 
10  0.5  0.509 
11  0  0 

Voltmeter Calibration Curve
Actual Plot Fitted Plot y = 0.989x ‐ 0.004
R² = 1
6

5
Actual Voltage (V)

0
0 1 2 3 4 5 6

Displayed Voltage (V)
6.3 Digitally Controlled Voltage Source

Calibration of digitally controlled voltage source was carried out for both the R-2R ladder with and
without Voltage follower (buffer) and PWM. The following table presents the results obtained for
various voltage levels along for the three different configurations.

Test Data for Digitally Controlled Voltage Source (DAC)

Actual Voltage 
Actual Voltage  Actual 
Output for R‐2R 
Decimal  Output for R‐2R  Voltage 
Binary  ladder without 
ladder with  Output using 
Voltage 
Voltage Follower PWM 
Follower 

      V  V  V 
0  0  0  0.02  0.22 
1  1  0.2  0.16  0.55 
2  10  0.41  0.32  0.89 
3  11  0.62  0.48  1.22 
4  100  0.82  0.63  1.56 
5  101  1.02  0.79  1.89 
6  110  1.23  0.96  2.22 
7  111  1.44  1.12  2.56 
8  1000  1.63  1.26  2.89 
9  1001  1.79  1.41  3.23 
10  1010  1.9  1.57  3.56 
11  1011  2  1.73    
12  1100  2.1  1.89    
13  1101  2.19  2.04    
14  1110  2.29  2.2    
15  1111  2.38  2.36    

It was observed that with the user of the voltage follower circuit though the initial and final voltage
levels came out to be the same, however, the voltage increment was found to be non-linear without a
buffer in the R-2R ladder case. Once the buffer is introduced the voltage increment became highly
linear. The voltage output from the PWM is also highly linear. The system implements these modes
based on calculation due to the observed highly linear character.
Digitally Controlled Voltage Calibration
R‐2R Voltage without Voltage Follower R‐2R Voltage with Voltage Follower
PWM Voltage with Voltage Follower
4

3.5

3
Actual Voltage

2.5

1.5

0.5

0
0 2 4 6 8 10 12 14 16

Voltage Level
7. Discussion
The system still has a scope for improvement. The following is a list of the features that can either
improve the performance of the system or can be an added feature:

ƒ The resistance measurement capability of the system is currently limited to 1KΩ to 10 KΩ. This can
be increased by using multiple RC circuits with appropriate capacitance value. Furthermore the
resistance measurement is not very accurate as it is based on a calibration equation. This can be
eliminated by more rigorous mathematical formulation of the system.

ƒ The system is capable of measuring a voltage ranging from 0V to 5V. This can be improved by
making suitable modification in the circuitry. Furthermore, the resolution of the system is limited to 8
bits (0-255) i.e. the system can detect a voltage increment of 0.01953V (~5/256). This can be made
more precise by increasing the number of bits of the ADC. The maximum sampling rate of the ADC is
limited by its capability to convert an analog input into a digital signal. The typical conversion time for
the ADC0831 is 32us.

ƒ The system can only generate the digitally controlled voltage (DAC) between 0V to 3V using R-2R
ladder. This capability can be improved by providing higher reference voltages in the circuit. Here the
DAC has 4-bits to control the voltage output i.e. it divides the voltage into 16 levels with each around
0.1875V (~3/16V).

ƒ The system can only generate the digitally controller voltage between 0V to 3V using PWM as well.
However, here the available levels are more (40 levels) as the on-time and off-time of the pulse can be
controlled more precisely. So, this mode offers a resolution of around 0.075V (~3/40V) But still the
voltage generated by the system is not very accurate. The accuracy of the system can be improved by
using PWM command available in the PBASIC language which was not used due to unavailability of
micro-controller pins. The PWM is currently being generated using a shift register for expanding
outputs which also contributes to the error.

ƒ The hold on mode is currently capable of retaining the last measurement. It can be improved to hold
multiple measurements.
8. Conclusion
The following design objectives are met:
(i) The digital multi-meter can act as a Ohmmeter, voltmeter and a digitally controller voltage source.
(ii) It provides a facility to check the continuity of the circuit.
(iii) It also has the feature of holding the last measurement vale.
(iv) It implements an Auto Sleep mode.
(v) It provides various visual cues to the user for guidance.
Contribution by each Team Member
Priyanshu Agarwal: Algorithm Coding, Overall system integration, coordination among team members
and lab report.

Dipen Harishbhai Dave: Implementation of Voltmeter and Digitally controlled voltage source.

Ravikiran Chollangi: Implementation for Ohmmeter and ADC switching between R-2R ladder and
PWM mode.

Jason Lieu: Algorithm for modes of the system, circuit diagrams, flow charts and lab report.
Bibliography
[1] Wikipedia, The Free Encyclopedia
Available: http://en.wikipedia.org/wiki/Multimeter
Available: http://en.wikipedia.org/wiki/RC_circuit
Available: http://en.wikipedia.org/wiki/Resistor_ladder

[2] PBASIC Syntax Guide, PARALLAX INC., BASIC Stamp Editor/Development System, Version
2.4.2.
[3] StampWorks Manual Version 1.1a, Parallax Inc.
Appendix
A. PBASIC Code for Digital Stopwatch 

' {$STAMP BS2} 
' {$PBASIC 2.5} 
' ========================================================================= 
' LAB2: DIGITAL MULTIMETER PBASIC CODE 

' GROUP D 

' Priyanshu Agarwal 
' Dipen Harishbhai Dave 
' Ravikiran Chollangi 
' Jason Lieu 

' ========================================================================= 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐CONSTANTS & VARIABLES DEFINITION‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐LCD CONSTANTS & VARIABLES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
E          CON   0                       ' LCD Enable pin  (1 = enabled) 
RS         CON   3                       ' Register Select (1 = char) 
LCDout     VAR   OUTB                    ' 4‐bit LCD data (Pin 4,5,6,7) 
 
ClrLCD     CON   $01                     ' clear the LCD 
CrsrHm     CON   $02                     ' move cursor to home position 
DispOff    CON   8                       ' LCD Display Off 
DispOn     CON   12                      ' LCD Display On 
 
 
Line1      CON   $80 
Line2      CON   $C0 
 
val        VAR   Byte                    ' digit to be displayed on LCD 
char       VAR   Byte                    ' character sent to LCD 
Msg        VAR   Byte                    ' Msg to be displayed on LCD 
indexoffset VAR   Byte                    ' index for reading msg 
index      VAR   Byte                    ' index for current position of cursor on LCD 
indexstart VAR   Byte                    ' Starting index of Msg 
indexend   VAR   Byte                    ' End index of the Msg 
line       VAR   Byte                    ' line in LCD 
 
Msgmode        DATA  "MODE D0 D1 D2 D3" ' preload EEPROM with message (count 16) 
Msgselect      DATA  "SELECT A MODE!  "  ' preload EEPROM with message (count 16) 
Msginvinp      DATA  "INVALID INPUT!" ' preload EEPROM with message (count 14) 
Msgclr         DATA  "                " ' preload EEPROM with message (count 16) 
MsgDigi        DATA  "    DIGITAL     " ' preload EEPROM with message (count 16) 
MsgMulti       DATA  "   MULTIMETER   " ' preload EEPROM with message (count 16) 
MsgResistance  DATA  "Ohmmeter Mode"       ' preload EEPROM with message (count 13) 
MsgVoltmeter   DATA  "Voltmeter Mode"       ' preload EEPROM with message (count 14) 
MsgVoltageR2R  DATA  "Voltage Mode R2R"       ' preload EEPROM with message (count 16) 
MsgVoltagePWM  DATA  "Voltage Mode PWM"       ' preload EEPROM with message (count 16) 
MsgRes         DATA  "R = "' preload EEPROM with message (count 4) 
MsgOhm         DATA  " Ohm" ' preload EEPROM with message (count 4) 
MsgVolt        DATA  "V = "' preload EEPROM with message (count 4) 
MsgV           DATA  " V"' preload EEPROM with message (count 2) 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SWITCH CONSTANTS & VARIABLES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
D0         CON   1     ‘ assign constant for various switches 
D1         CON   2 
D2         CON   4 
D3         CON   8 
D4         CON   16 
D5         CON   32 
D6         CON   64 
D7         CON   128 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SHIFT REGISTER INPUT 74X165 CONSTANTS &VARIABLES‐‐‐‐‐‐‐‐‐‐‐ 
Clock      CON   8        ' shift clock (74x165.2) 
D_in       CON   9        ' shift data (74x165.7) 
Load       CON   10       ' input load (74x165.1) 
 
switches   VAR   Byte      ' inputs switches 
sflag      VAR   Bit 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐'VARIABLES & CONSTANT RELATED TO POWER SAVER MODE‐‐‐‐‐‐‐‐‐‐‐‐‐ 
counterMAX   VAR Word 
idlecounter  VAR Word 
counterPS    CON 100 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐'VARIABLES & CONSTANT FOR RESISTANCE MEASUREMENT‐‐‐‐‐‐‐‐‐‐‐‐ 
RC          CON   1 'Pin for RC Circuit 
time        VAR  Word 
res         VAR  Word 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐'VARIABLES & CONSTANT FOR DIGITAL VOLTAGE ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
EOClock    CON  13        ' shift clock (74x595.11) for expanding output 
EOD_out    CON  14        ' serial data out (74x595.14) for expanding output 
EOLatch    CON  15        ' output latch (74x595.12) for expanding output 
 
DlyTmTot   CON  40        'total pulse time 
DlyTmOn    VAR  Byte        'delay time for on pulse 
DlyTmOff   VAR  Byte        'delay time for off pulse 
 
flagpwm     VAR  Bit    ‘ calibration flag to choose separate calibration for PWM 
pattern  VAR  Byte        ' output pattern 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐'VARIABLES & CONSTANT FOR ADC ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
ADdata  CON  12        ' A/D data line 
ADclock  CON  11        ' A/D clock 
ADcs    CON  2      ' A/D chip select (low true) 
 
result  VAR  Byte        ' result of conversion 
mVolts  VAR  Word        ' convert to millivolts 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐INITIALIZATION‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
Initialize: 
  DIRL = %11111001       ' setup pins for LCD, RC Circuit,ADC0831 
  flagpwm = 0 
  GOSUB LCDinit          ' initialize LCD for 4‐bit mode 
  HIGH Load              ' make output; initialize to 1 
  HIGH ADcs 
 
  pattern = %00000000    ' switch relay to normally connected position 
  GOSUB Out595 
 
  Msg = MsgDigi                  ' display welcome message on LCD 
  indexend = 15 
  line = Line1 
  GOSUB MsgDisp 
  Msg = MsgMulti 
  indexend = 15 
  line = Line2 
  GOSUB MsgDisp 
  PAUSE 1000 
 
  idlecounter = 0 
  counterMAX = 10000 
  sflag = 0 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐MAIN PROGRAM‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
MainMsgRepeat: 
  Msg = Msgmode 
  indexend = 15 
  line = Line1 
  GOSUB MsgDisp 
  Msg = Msgselect 
  indexend = 15 
  line = Line2 
  GOSUB MsgDisp 
 
Main: 
  GOSUB IdleCheck 
  GOSUB ReadSwitches 
  IF (Switches = 0) THEN 
  sflag = 0 
  GOTO  Main 
  ELSEIF (Switches = D0 AND sflag = 0) THEN 
  GOTO RMode 
  ELSEIF (Switches = D1 AND sflag = 0) THEN 
  GOTO VMode 
  ELSEIF (Switches = D2 AND sflag = 0) THEN 
  GOTO DVSR2RMode 
  ELSEIF (Switches = D3 AND sflag = 0) THEN 
  GOTO DVSPWMMode 
  ELSEIF (sflag <> 1) THEN 
  GOSUB InvalidInput 
  ENDIF 
  GOTO Main 
  END 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
 
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SUBROUTINES USED IN THE PROGRAM‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐INITIALIZATION SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐LCD INITIALIZATION‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
LCDinit: 
  PAUSE 500            ' let the LCD settle 
  LCDout = %0011          ' 8‐bit mode 
  PULSOUT E,1 
  PAUSE 500 
  PULSOUT E,1 
  PULSOUT E,1 
  LCDout = %0010          ' 4‐bit mode 
  PULSOUT E,1 
  char = %00001100        ' disp on, crsr off, blink off 
  GOSUB LCDcommand 
  char = %00000110        ' inc crsr, no disp shift 
  GOSUB LCDcommand 
  char = ClrLCD 
  GOSUB LCDcommand 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DISPLAY SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐WRITE ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
LCDcommand: 
  LOW RS            ' enter command mode 
 
LCDwrite: 
  LCDout = char.HIGHNIB        ' output high nibble 
  PULSOUT E,1          ' strobe the Enable line 
  LCDout = char.LOWNIB        ' output low nibble 
  PULSOUT E,1 
  HIGH RS            ' return to character mode 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DISPLAY DIGIT ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
DigDisp: 
  char = line+index      ' set new DDRAM address 
  GOSUB LCDcommand 
  LOOKUP val,["0","1","2","3","4","5","6","7","8","9","."," "],char 
  GOSUB LCDwrite          ' write the character 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐LCD MSG WRITE‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
MsgClrDisp: 
  GOSUB ClrAll 
MsgDisp: 
  FOR index = indexstart TO indexend     ' get message from EEPROM 
    char = line + index                  ' set new DDRAM address 
    GOSUB LCDcommand 
    READ (Msg + index ‐ indexoffset),char           ' read a character 
    GOSUB LCDwrite                       ' write it 
  NEXT 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐CLEAR FULL LCD DISPLAY‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
ClrAll: 
  char = ClrLCD        ' Clear the LCD 
  GOSUB LCDcommand 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐CLEAR LINE 1/2 OF LCD DISPLAY‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
ClrLine: 
  Msg = Msgclr 
  indexend = 15 
  GOSUB MsgDisp 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SHOW RESISTANCE ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
ShowResistance: 
  index = 0 
  GOSUB ClrLine 
 
  Msg = MsgRes 
  indexend = 3 
  'line = Line1 
  GOSUB MsgDisp 
 
  val = res/1000 
  GOSUB DigDisp    'display thousand's digit of Resistance 
  index = index +1 
  val = (res/100)//10 
  GOSUB DigDisp    'display hundred's digit of Resistance 
  index = index +1 
  val = (res/10)//10 
  GOSUB DigDisp    'display ten's digit of Resistance 
  index = index +1 
  val = res//10 
  GOSUB DigDisp    'display one's digit of Resistance 
 
  Msg = MsgOhm 
  indexstart = 8 
  indexoffset = 8 
  indexend = 11 
  'line = Line1 
  GOSUB MsgDisp 
  'PAUSE 10000 
  indexstart = 0 
  indexoffset = 0 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DISPLAY VOLTAGE‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
VDisp: 
  GOSUB Read0831 
 
  IF flagpwm = 0  THEN 
  mVolts = result */ $139C      ' x 19.6 (mv / unit) 
  ENDIF 
 
  IF flagpwm = 1  THEN 
  mVolts = ((result*/ $139C)*/$0006*DlyTmOn)+130 ' obtained from calibration 
  ENDIF 
 
  GOSUB ShowVoltage 'display the voltage 
  'DEBUG HOME 
  'DEBUG "ADC..... ", DEC result, "   ", CR 
  'DEBUG "volts... ", DEC mVolts DIG 3, ".", DEC3 mVolts 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SHOW VOLTAGE ON LCD‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
ShowVoltage: 
  index = 0 
  'GOSUB ClrAll 
  Msg = Msgclr 
  indexend = 15 
  GOSUB MsgDisp 
 
  Msg = MsgVolt 
  indexend = 3 
  GOSUB MsgDisp 
 
  val = mVolts/1000 
  GOSUB DigDisp    'display thousand's digit of milivolt 
 
  index = index +1 
  val = 10 
  GOSUB DigDisp    'display decimal point 
 
  index = index +1 
  val = (mVolts/100)//10 
  GOSUB DigDisp    'display hundred's digit of milivolt 
  index = index +1 
  val = (mVolts/10)//10 
  GOSUB DigDisp    'display ten's digit of milivolt 
  index = index +1 
  val = mVolts//10 
  GOSUB DigDisp    'display one's digit of milivolt 
 
  Msg = MsgV 
  indexstart = 9 
  indexoffset = 9 
  indexend = 10 
  GOSUB MsgDisp 
  indexstart = 0 
  indexoffset = 0 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐MODE SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐RESISTANCE MEASURE MODE‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
RMode: 
  GOSUB ClrAll 
  line = Line2 
  Msg = MsgResistance 
  indexend = 12 
  GOSUB MsgDisp 
 
  line = Line1 
  idlecounter = 0 
 
RModeSetflag: 
  sflag = 0 
 
RModeRepeat: 
  HIGH RC 
  PAUSE 10 
  RCTIME RC, 1, time 
  res = (time*/$0DA6 + 166) 
  GOSUB ShowResistance 
  GOSUB IdleCheck 
  'DEBUG HOME, "RESISTANCE = ", DEC5 time '(1459*time/100 + 2324/10) 
  'DEBUG HOME, "time =", DEC5 time, " Res = ", DEC5 res 
  GOSUB ReadSwitches 
  IF Switches = 0  THEN RModeSetflag 
  IF Switches = D1 THEN VMode 
  IF Switches = D2 THEN DVSR2RMode 
  IF Switches = D3 THEN DVSPWMMode 
 
  IF Switches = D7 THEN 
  sflag = 1 
  idlecounter = 0 
  GOTO MainMsgRepeat 
  ENDIF 
 
  IF (Switches = D6 AND sflag=0) THEN 
  GOSUB HoldOn 
  ENDIF 
 
  IF (Switches <> D6 AND Switches <> 0)THEN 
  idlecounter = 0 
  ENDIF 
  GOTO RModeRepeat 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐DIGITAL VOLTMETER‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
VMode: 
  flagpwm = 0 
  pattern = %00000000 ' switch relay to default position 
  GOSUB Out595 
  GOSUB ClrAll 
 
  line = Line2 
  Msg = MsgVoltmeter 
  indexend = 13 
  GOSUB MsgDisp 
  line = Line1 
  idlecounter = 0 
 
VModeSetflag: 
  sflag = 0 
 
VModeRepeat: 
  GOSUB VDisp 
  GOSUB IdleCheck 
  GOSUB ReadSwitches 
  IF Switches = 0  THEN VModeSetflag 
  IF Switches = D0 THEN RMode 
  IF Switches = D2 THEN DVSR2RMode 
  IF Switches = D3 THEN DVSPWMMode 
 
  IF Switches = D7 THEN 
  sflag = 1 
  idlecounter = 0 
  GOTO MainMsgRepeat 
  ENDIF 
 
  IF (Switches = D6 AND sflag=0) THEN 
  GOSUB HoldOn 
  ENDIF 
 
  IF (Switches <> D6 AND Switches <> 0)THEN 
  idlecounter = 0 
  ENDIF 
  GOTO VModeRepeat 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐DIGITALLY CONTROLLED VOLTAGE SOURCE USING R2R LADDER (DAC)‐‐‐‐‐‐‐ 
DVSR2RMode: 
  flagpwm = 0 
  LOW EOLatch            ' make output and keep low 
 
  GOSUB ClrAll 
  line = Line2 
  Msg = MsgVoltageR2R 
  indexend = 15 
  GOSUB MsgDisp 
  line = Line1 
  idlecounter = 0 
  pattern = %00101000 
 
R2RModeSetflag: 
  sflag = 0 
 
RepeatR2R: 
  GOSUB Out595 
  GOSUB VDisp 
  GOSUB IdleCheck 
  GOSUB ReadSwitches 
  DEBUG CLS, ? pattern 
  IF Switches = 0  THEN R2RModeSetflag 
  IF Switches = D0 THEN RMode 
  IF Switches = D1 THEN VMode 
  IF Switches = D3 THEN DVSPWMMode 
  IF (Switches = D4 AND pattern>32) THEN 
  'DEBUG CLS, ? pattern 
  pattern = pattern ‐ 1  ' decrease voltage 
  ENDIF 
  IF (Switches = D5 AND pattern<64) THEN 
  pattern = pattern + 1  ' increase voltage 
  'DEBUG CLS, ? pattern 
  ENDIF 
  IF Switches = D7 THEN 
  sflag = 1 
  idlecounter = 0 
  GOTO MainMsgRepeat 
  ENDIF 
 
  IF (Switches = D6 AND sflag=0) THEN 
  GOSUB HoldOn 
  ENDIF 
 
  IF (Switches <> D6 AND Switches <> 0)THEN 
  idlecounter = 0 
  ENDIF 
  GOTO RepeatR2R          ' repeat the loop 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐DIGITALLY CONTROLLED VOLTAGE SOURCE USING PWM (DAC)‐‐‐‐‐‐‐‐‐‐ 
DVSPWMMode: 
  LOW EOLatch            ' make output and keep low 
  flagpwm = 1 
  GOSUB ClrAll 
  line = Line2 
  Msg = MsgVoltagePWM 
  indexend = 15 
  GOSUB MsgDisp 
  line = Line1 
  idlecounter = 0 
  DlyTmOn  = 0 
  DlyTmOff = DlyTmTot ‐ DlyTmOn 
 
PWMModeSetflag: 
  sflag = 0 
 
RepeatPWM: 
  pattern = %00110000    ' turn on pulse 
  GOSUB Out595 
  PAUSE DlyTmOn          ' put pattern on 74x595 
  GOSUB VDisp 
  GOSUB IdleCheck 
  GOSUB ReadSwitches 
 
  pattern = %00100000    ' turn off pulse 
  GOSUB Out595 
  DlyTmOff = DlyTmTot ‐ DlyTmOn 
  PAUSE DlyTmOff          ' put pattern on 74x595 
 
  IF Switches = 0  THEN PWMModeSetflag 
  IF Switches = D0 THEN RMode 
  IF Switches = D1 THEN VMode 
  IF Switches = D2 THEN DVSR2RMode 
  IF (Switches = D4 AND DlyTmOn>0) THEN 
  DlyTmOn = DlyTmOn ‐ 1  ' decrease voltage 
  ELSEIF (Switches = D5 AND DlyTmOn<DlyTmTot) THEN 
  DlyTmOn = DlyTmOn + 1  ' increase voltage 
  ENDIF 
 
  IF Switches = D7 THEN 
  sflag = 1 
  idlecounter = 0 
  GOTO MainMsgRepeat 
  ENDIF 
 
  IF (Switches = D6 AND sflag=0) THEN 
  GOSUB HoldOn 
  ENDIF 
 
  IF (Switches <> D6 AND Switches <> 0)THEN 
  idlecounter = 0 
  ENDIF 
  GOTO RepeatPWM          ' continue Repeating PWM Mode 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SWITCH SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐READ SWITCH STATUS FROM 74x165.BS2‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
ReadSwitches: 
  PULSOUT Load,3          ' grab the switch inputs 
  SHIFTIN D_in,Clock,MSBPRE,[switches]  ' shift them in 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐POWER SAVING SUBROUTINES‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SHUTDOWN LCD FOR POWER SAVING‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
ShutDown: 
  char = DispOff          ' turn the LCD Off 
  GOSUB LCDcommand 
ShutLoop: 
  GOSUB ReadSwitches 
  IF Switches <> 0 THEN Start 
  GOTO ShutLoop 
Start: 
  char = DispOn          ' turn the LCD On 
  GOSUB LCDcommand 
  idlecounter = 0 
  sflag = 1 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐MISC‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐INVALID INPUT MESSAGE‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
InvalidInputMsg: 
  line = Line2 
  GOSUB ClrLine 
  Msg = Msginvinp 
  indexend = 13 
  GOSUB MsgDisp 
  PAUSE 200 
  line = Line1 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
'‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐SEND BACK ON INVALID INPUT‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
InvalidInput: 
  idlecounter = 0 
  GOSUB InvalidInputMsg 
  GOTO MainMsgRepeat 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐OUTPUT DATA TO 74X595‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
Out595: 
  SHIFTOUT EOD_out,EOClock,MSBFIRST,[pattern]  ' send pattern to 74x595 
  PULSOUT EOLatch,3            ' latch outputs 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐READ DATA FROM ADC0831‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
Read0831: 
  LOW ADcs 
  SHIFTIN ADdata,ADclock,MSBPOST,[result\9] 
  HIGH ADcs 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐CHECK FOR IDLE COUNTER‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
Idlecheck: 
  idlecounter = (idlecounter + 1) 
  IF idlecounter = counterMAX THEN 
  GOSUB ShutDown 
  ENDIF 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐HOLD PREVIOUS READING‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
HoldOn: 
  sflag = 1 
  IF (line = Line1) THEN 
  GOTO HoldLine1 
  ELSE 
  GOTO HoldLine2 
  ENDIF 
  HoldLine1: 
  line = Line2 
  RETURN 
  HoldLine2: 
  line = Line1 
  RETURN 
' ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐   
B. Data Sheets

B.1 ADC0831, 8‐Bit Serial I/O A/D Converter 

 
Pin Configuration 
B.2 LM358, Low Power Dual Operational Amplifier 
 

 
Pin Configuration 
 
B.3 74HC595 8‐bit serial‐in, serial or parallel‐out shift register with output 
latches

Pin Configuration

You might also like