mae576 groupd lab2 report
TRANSCRIPT
-
8/9/2019 MAE576 GroupD LAB2 Report
1/53
LAB 2: MULTIMETER
Mechatronics 576Spring 2010
March 25th
2010
Group D
Priyanshu AgarwalDipen Harishbhai Dave
Ravikiran ChollangiJason Lieu
Department of Mechanical and Aerospace Engineering
State University of New York at Buffalo
Buffalo, New York 14260
-
8/9/2019 MAE576 GroupD LAB2 Report
2/53
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.
-
8/9/2019 MAE576 GroupD LAB2 Report
3/53
Contents
Abstract
Contents
1.Introduction1.1 Design Objective1.2 Features of Digital Multimeter1.3 User Operation Instructions
2. Hardware2.1 List of Components2.2 Microcontroller (Basic Stamp 2) Pin Assignment2.3 Hardware Description2.4 Circuit Diagrams
3. Software4. Mathematical Methods
4.1 Principle for Digital Ohmmeter4.2 Principle for Digital Voltmeter4.3 Principle for Digitally Controlled Voltage Source Using R2R Ladder4.4 Principle for Digitally Controlled Voltage Source Using PWM
5. Implementation5.1 Software Algorithms
5.1.1 Overall System Flowchart5.1.2 Ohmmeter Mode (D0) Flowchart5.1.3 Voltmeter Mode (D1) Flowchart5.1.4 Digitally Controller Voltage Source Mode using R2R (D2) Flowchart5.1.5 Digitally Controller Voltage Source Mode using PWM (D3) Flowchart
5.2 Subroutines
6. Testing & Calibration6.1 Ohmmeter6.2 Voltmeter6.3 Digitally Controlled Voltage Source
-
8/9/2019 MAE576 GroupD LAB2 Report
4/53
7. Discussion8. Conclusion
Bibliography
AppendixA. PBASIC Code for Digital Multimeter
B. Data Sheets
B.1 ADC0831, 8Bit Serial I/O A/D Converter
B.2 LM358, Low Power Dual Operational Amplifier
B.3 74HC595 8bit serialin, serial or parallelout shift register with outputlatches
-
8/9/2019 MAE576 GroupD LAB2 Report
5/53
1. Introduction
A multi-meter, also known as a volt/ohm meter or VOM, is an electronic measuring instrument thatcombines several measurement functions in one unit [1]. A typical multi-meter may include featuressuch 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, aVoltmeter and a Digitally Controlled Voltage Source (Digital to Analog converter). The interfacing ofthe microcontroller with few electronic components like LCD, switches using shift-in register, shiftregister to expand outputs, ADC, Operational amplifier, relay and MOSFET is achieved. The abovementioned components work in an integrated fashion to act as a digital multi-meter. In order to enhancethe features of the multi-meter the features available in the current multi-meters are studied. It wasdecided that as far as possible the developed multi-meter should emulate these features. It was decidedthat in addition to the above mentioned features out multi-meter should have a feature to retain earliermeasurement 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 ObjectiveThe 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 thefollowing modes of operation:(i) Ohmmeter Mode In this mode of the digital multi-meter any value of resistance that liesbetween 1K and 10K can be measured. The measured resistance is displayed on the LCD.
Ohmmeter Mode (D0) Voltmeter Mode (D1)
-
8/9/2019 MAE576 GroupD LAB2 Report
6/53
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 bemeasured. 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 beincreased 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-meterresembles 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. Herethe voltage can be increased or decreased in steps of around 0.07V. The current voltage will bedisplayed on the LCD.
(v) Continuity Check Mode This mode of the digital multi-meter provides the capability to debuga circuit by providing the ability to check the continuity of a circuit. This feature can be usedsimultaneously 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 userusing a set of 8 switches with different roles assigned to each switch based on the current state of theoperation 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 lastreading 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 todecrease/increase the voltage generated by the multi-meter.(v) Also the user can check the continuity during any of the above mentioned modes by connectingthe 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 modeswithout returning to the main screen.
Select Mode Screen
-
8/9/2019 MAE576 GroupD LAB2 Report
7/53
3. Hold On The multi-meter also provides a feature to hold the last reading and continue with thenext measurement. This feature becomes important when it comes to compare two resistances or twovoltages in a circuit. The current measurement is the one that is blinking on the LCD. Furthermore, itcan be used to hold multiple times with the capability of retaining last two measurements.
Digital Multi-meter with hold on inResistance Mode
Digital Multi-meter with hold on inVoltage Mode
4. Auto Sleep Mode In order to save power which is always the case in multi-meter, the systemimplements the feature of auto sleep mode. When no key is pressed in idle or any of the modes thesystem automatically turns off the LCD in order to saver power. However, the state of LCD i.e. the lastmeasurement 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 availablefour 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 InvalidInput! message on the LCD.
3. When the user presses the D0 button, the Ohmmeter mode is selected. The variable resistance in thecircuit can then be varied to note the change in the value of resistance displayed on the LCD. Theselected mode will be displayed on the LCD in second line.
-
8/9/2019 MAE576 GroupD LAB2 Report
8/53
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 nextmeasurement by displaying the current measurement in the second line on LCD. Further mode thecurrent 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 otherline.
6. In order to switch mode the user can either return to the main menu by pressing Main Menu (D7) orsimply press the specific mode key (D0/D1/D2/D3). Based on the selection the multi-meter willoperate in the specified mode.
7. In case Voltmeter Mode (D1) is selected the analog voltage from a variable resistor can then bemeasured. The value of measurement can be changed by changing the resistance of the variableresistor. 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 voltagecan 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 VoltageSource with current voltage being displayed on the LCD now using PWM. The value of voltage cannow be increased more precisely i.e. in steps of around 0.07V by pressing Increase Voltage (D5) orDecrease Voltage (D4) button. The feature of fast increment or decrement, Hold On (D6) / MainMenu (D7) still exists.
10.In addition to the above modes the digital multi-meter is by default set to the sleep mode which willbe invoked if the watch is idle for around 45 seconds. In case of sleep mode the LCD is turned offwith its status still retained in the memory. The sleep mode kicks in when the multi-meter is eitheridle 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 thecontinuity 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 messageCCCC signifying continuous circuit. This mode works independent of the other modes can beused while the multi-meter is in any of the above mentioned modes.
-
8/9/2019 MAE576 GroupD LAB2 Report
9/53
2. HardwareThe 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 12. BASIC Stamp Module II 1
3. Hitachi LCD Module , HD44780 14. 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 813. 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 Description0 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 Pin7 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
-
8/9/2019 MAE576 GroupD LAB2 Report
10/53
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 modules2. 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 motors10.Pulse generator for 1Hz, 10 Hz, 100 Hz, and 1 kHz11.RS-232 interface port for communication with COM program12.Socket for 24-pin BASIC Stamp modules13.Parallel LCD module with connector and brightness control14.Piezospeaker15.10K potentiometer
16.2.5" x 7" breadboard with 800 contact points17.7.5V DC 1 amp power supply with polarity protectionSource: http://www.apexvalue.com/basic_stamp/product_id_28135.htm
Basic Stamp II Module
-
8/9/2019 MAE576 GroupD LAB2 Report
11/53
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 threemicrocontroller pins. Each 74HC165 provides 8 input pins. Any number of 74HC165 chips can becascaded using the same set of microcontroller pins. It has synchronous serial input.
-
8/9/2019 MAE576 GroupD LAB2 Report
12/53
s
t
4HC595 S
he 74HC5f data is cl
utputs on t
alled "Shif
hifted serial
utput the d
pecificatio
8-bitLogic Fa
LogicalOperatin
Output T Propagat Operatin Operatin-Segment
DC0831DC0831 is
onfigured t
he COPS
nalog voltaoltage valu
nalog volta
ey Specifi
Param
ift Registe
5 is a shiftcked into t
e IC. So by
ing data ou
ly from the
ta in parall
s:
mily : HC
unction : Sg Supply V
ype : 3-Stat
ion Delay Tg Supply V
g Supply V
isplay
a 8-bit succcomply wi
family of p
e input all. In additio
e span to t
ations:
ters / Value
register whie IC via tw
using 3 val
t" of the m
micro-contr
l.
ift Registeltage (Typ)
e
ime : 265nsltage (Min)
ltage (Max
essive apprth the NSC
ocessors, a
ws increasi, the voltag
e full 8 bits
s
ch is used tlines, and
able lines
crocontroll
oller, where
http://ww
: 5V
: 2V
: 6V
ximation AMICROWI
d can inter
g the come reference
of resolutio
ADC0
expand thhen third l
f the micro
r by "sync
each bit is "
.solarbotic
/D converteE serial
ace with sta
on-mode reinput can b
n.
31
outputs frine is toggl
controller 8
ronous ser
shifted in"
s.com
r with a seridata exchan
ndard shift
jection andadjusted to
m the micrd, it pops t
outputs can
al commun
ne at a tim
al I/O. Thege standard
egisters or
offsetting thallow enco
o-controller.ese settings
be obtained
ication". Th
, then the c
erial I/O isfor easy int
Ps. The dif
e analog zeing any sm
It 8 bitsout on 8
. This is
e data is
ips
rface to
erential
o inputaller
-
8/9/2019 MAE576 GroupD LAB2 Report
13/53
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 openterminal (87). When the coil of the relay is at rest (not energized), the common terminal (30) and thenormally 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 cansee the coil is an electromagnet that causes the arm that is always connected to the common (30) to pivotwhen energized whereby contact is broken from the normally closed terminal (87a) and made with thenormally open terminal (87).
LM358
http://www.sparkfun.com/
The LM358 is a dual-channel operational amplifier (opamp). LM358 applications includetransducer 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:oSingle supply: 3V to 32Voor dual supplies: 1.5V to 16V
-
8/9/2019 MAE576 GroupD LAB2 Report
14/53
2.4 Circuit DiagramsHD44780 LCD Module Interface Circuit
P4
P5
P6
P7
P3
P0
D4
D5
D6
D7
RS
E
R/W
Vss Vss
4.7K
Hitachi LCD Module
HD44780
P0, P3, P4, P5, P6, P7 are the inputs from microcontroller.P4-P7 are data pinsP0 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
-
8/9/2019 MAE576 GroupD LAB2 Report
15/53
P8: Clock Pin input to 74X165P9: Data In from the display driverP10: Load pin inputD0-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 lowit starts charging and recording the time taken for charging the resistance in the circuit is determined.
Digital Voltmeter CircuitThe digital voltmeter is based on the measurements done using ADC0831. A relay is used in this circuitas only single ADC was to be connected to micro-controller due to shortage of pins. Thus, the sameADC is being used in multiple modes to convert analog voltage to digital. Furthermore, in order toswitch the relay a MOSFET IRF540 is used.
Digitally Controlled Voltage Source Using R-2R Ladder & PWM without
Operational Amplifier
-
8/9/2019 MAE576 GroupD LAB2 Report
16/53
The circuit shown above is used to generate digitally controlled voltage using an R-2R ladder without anoperational amplifier. Now, since the voltage generated by the R-2R ladder as well as the voltagegenerated using PWM is to be connected to the same terminal of the relay diodes are provided forisolating 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 whenvoltage is generated by a digitally controlled voltage source. The use of operational amplifier alsoimproves the performance of the system as it keeps the output voltage constant even when the load(LED) is connect to it.
-
8/9/2019 MAE576 GroupD LAB2 Report
17/53
Circuit for Continuity Checking
The circuit shown above shows a simple circuit used to check the continuity in any circuit. The circuit tobe checked is place between a 5V supply and the 7 segment display with appropriate connections asshown above. When the circuit is continuous the 7-segment glows.
-
8/9/2019 MAE576 GroupD LAB2 Report
18/53
Complete Circuit Diagram for Digital Multi-meter
-
8/9/2019 MAE576 GroupD LAB2 Report
19/53
3. Software
The following section presents a basic overview of the important commands used while implementingthe system.
The PBASIC version 2.5 is used to program the BASIC Stamp II module [2]. The following specialcommands are used to program the module:
1. RCTIME Measure time while Pin remains in State; usually to measure the charge/discharge timeof resistor/capacitor (RC) circuit.Syntax: RCTIMEPin, State, Variable
2. PWM - Convert a digital value to analog output via pulse-width modulation.Syntax: PWMPin, Duty, Duration
-
8/9/2019 MAE576 GroupD LAB2 Report
20/53
4. Mathematical Methods
4.1 Principle for Digital OhmmeterThe 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 itsstored energy through the resistor. The voltage across the capacitor, which is time dependent, can befound by using Kirchhoff's current law, where the current through the capacitor must equal thecurrent 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 thecapacitor is in charged state i.e. its voltage is above 1.4V the resistance in the circuit can bedetermined 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 sofinally a calibration is done and the multi-meter works based on this calibration equation. The detailsof calibration are mentioned in the Testing and Calibration section.
4.2 Principle for Digital VoltmeterThe digital voltmeter is based on the principle of conversion of analog voltage to digital voltageusing an Analog to Digital Converter (ADC). The ADC accepts an analog voltage and gives out anequivalent digital output for the measured voltage which can then be convertedto the actual voltage
-
8/9/2019 MAE576 GroupD LAB2 Report
21/53
based on the fact that highest value on the digital scale (255) corresponds to a voltage of 5V and thelowest value (0) corresponds to 0V.
4.3 Principle for Digitally Controlled Voltage Source Using R-2R LadderA resistor ladder is an electrical circuit made of repeating units of resistors [1]. It is a simple andinexpensive way to perform digital-to-analog conversion, using repetitive arrangements of precisionresistor 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 beweighted in their contribution to the output voltage Vout. In this circuit 5 bits are shown, giving 32possible 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 actualvalue of Vref (and 0 volts) will depend on the type (technology) of the digital logic gates used todrive 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 PWMPulse-width modulation (PWM) is a very efficient way of providing intermediate amounts ofelectrical power between fully on and fully off. A simple power switch with a typical power sourceprovides full power only, when switched on. The term duty cycle describes the proportion of on timeto the regular interval or period of time; a low duty cycle corresponds to low power, because thepower is off for most of the time. Duty cycle is expressed in percent, 100% being fully on.
-
8/9/2019 MAE576 GroupD LAB2 Report
22/53
The waveform shown above represents the voltage signal amplitude against time. As the duty cycleof the pulse is changed the average voltage obtained as output varies based on the pulse on time andpulse off time.
In our system the variable voltage is developed by varying the on time and off time of the pulsebased on the input provided by the user.
-
8/9/2019 MAE576 GroupD LAB2 Report
23/53
5. Implementation
The following section details the algorithms used along with the various subroutines used to implementthem.
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 Flowchart2. Ohmmeter Mode (D0) Flowchart3. Voltmeter Mode (D1) Flowchart4. Digitally Controlled Voltage Source Mode using R-2R (D2) Flowchart5. Digitally Controlled Voltage Source Mode using PWM (D3) Flowchart
-
8/9/2019 MAE576 GroupD LAB2 Report
24/53
5.1.1 Overall System Flowchart
-
8/9/2019 MAE576 GroupD LAB2 Report
25/53
5.1.2 Ohmmeter Mode (D0) Flowchart
-
8/9/2019 MAE576 GroupD LAB2 Report
26/53
5.1.3 Voltmeter Mode (D1) Flowchart
-
8/9/2019 MAE576 GroupD LAB2 Report
27/53
-
8/9/2019 MAE576 GroupD LAB2 Report
28/53
5.1.4 Digitally Controller Voltage Source Mode using R-2R (D2)
Flowchart
-
8/9/2019 MAE576 GroupD LAB2 Report
29/53
5.1.5 Digitally Controller Voltage Source Mode using PWM (D3)
Flowchart
-
8/9/2019 MAE576 GroupD LAB2 Report
30/53
5.2 SubroutinesIn order to achieve efficiency the code is subdivided into subroutines so as to have an ability to executethe same piece of code as and when required. The subroutines used in the program can be categorized inthe following major categories:
1.Initialization Subroutines The following subroutines are used for initialization of variables anddisplay messages in different modes:
-
8/9/2019 MAE576 GroupD LAB2 Report
31/53
(i) LCD Initialization Initializes the LCD for display.
2.Mode Subroutines The following subroutines are used for implementing different modes available inthe 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 anddigits 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 presentin 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 thesystem 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 thesystem(i) Hold On This subroutine takes care of the hold on state of the system in each mode.
-
8/9/2019 MAE576 GroupD LAB2 Report
32/53
6. Testing & Calibration
The designed system was tested for accuracy of the measured value. Also, different calibrations arecarried 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 measuredresistance value when evaluate using the formula. The following table shows the actual value of theresistance along with the resistance evaluated.
Test Data for Digital Ohmmeter
S.No. Actual
CapacitanceActualResistance
RCTIMECharging
Time
Evaluated
Resistance
Fitted
Resistance
uF Ohm (2usec) 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
y = 14.48x + 166.1R = 0.999
0
2000
4000
6000
8000
10000
12000
0 100 200 300 400 500 600 700
ActualResistance(Ohm)
TimefromRCTIME(2us)
ResistanceCalibrationCurve
MeasuredResistance FittedPlot
-
8/9/2019 MAE576 GroupD LAB2 Report
33/53
However, in order to improve the accuracy of the system a calibration plot was obtained between actualresistance and the charging time measured using RCTIME command. The plot came out to be fairlylinear. So, the linear fit equation is obtained and implement in the system for resistance evaluation fordisplay. 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 highlyaccurate with a regression coefficient of around 1. The system calculates the voltage using the equationfor display as the error is below 0.8%.
Test Data for Digital Voltmeter
S.No. Actual
Voltage
Calculated
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
y=0.989x 0.004
R=1
0
1
2
3
4
5
6
0 1 2 3 4 5 6
ActualV
oltage(V)
DisplayedVoltage(V)
VoltmeterCalibrationCurve
ActualPlot FittedPlot
-
8/9/2019 MAE576 GroupD LAB2 Report
34/53
6.3 Digitally Controlled Voltage Source
Calibration of digitally controlled voltage source was carried out for both the R-2R ladder with andwithout 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)
DecimalBinary
ActualVoltage
OutputforR2R
ladderwithout
Voltage
Follower
ActualVoltage
OutputforR2R
ladderwith
VoltageFollower
Actual
Voltage
Outputusing
PWM
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 voltagelevels 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 highlylinear. The voltage output from the PWM is also highly linear. The system implements these modesbased on calculation due to the observed highly linear character.
-
8/9/2019 MAE576 GroupD LAB2 Report
35/53
0
0.5
1
1.5
2
2.5
3
3.5
4
0 2 4 6 8 10 12 14 16
ActualVoltage
VoltageLevel
DigitallyControlledVoltageCalibration
R2RVoltagewithoutVoltageFollower R2RVoltagewithVoltageFollower
PWMVoltagewithVoltageFollower
-
8/9/2019 MAE576 GroupD LAB2 Report
36/53
7. Discussion
The system still has a scope for improvement. The following is a list of the features that can eitherimprove 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 beeliminated 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 bymaking suitable modification in the circuitry. Furthermore, the resolution of the system is limited to 8bits (0-255) i.e. the system can detect a voltage increment of 0.01953V (~5/256). This can be mademore precise by increasing the number of bits of the ADC. The maximum sampling rate of the ADC islimited by its capability to convert an analog input into a digital signal. The typical conversion time forthe 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 expandingoutputs 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/9/2019 MAE576 GroupD LAB2 Report
37/53
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.
-
8/9/2019 MAE576 GroupD LAB2 Report
38/53
Contribution by each Team Member
Priyanshu Agarwal: Algorithm Coding, Overall system integration, coordination among team membersand 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 andPWM mode.
Jason Lieu:Algorithm for modes of the system, circuit diagrams, flow charts and lab report.
-
8/9/2019 MAE576 GroupD LAB2 Report
39/53
Bibliography[1] Wikipedia, The Free Encyclopedia
Available: http://en.wikipedia.org/wiki/MultimeterAvailable: http://en.wikipedia.org/wiki/RC_circuitAvailable: 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.
-
8/9/2019 MAE576 GroupD LAB2 Report
40/53
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 & VARIABLESE CON 0 ' LCD Enable pin (1 = enabled)RS CON 3 ' Register Select (1 = char)LCDout VAR OUTB ' 4bit LCD data (Pin 4,5,6,7)
ClrLCD CON $01 ' clear the LCDCrsrHm CON $02 ' move cursor to home positionDispOff CON 8 ' LCD Display OffDispOn CON 12 ' LCD Display On
Line1 CON $80Line2 CON $C0
val VAR Byte ' digit to be displayed on LCDchar VAR Byte ' character sent to LCD
Msg VAR Byte ' Msg to be displayed on LCDindexoffset VAR Byte ' index for reading msgindex VAR Byte ' index for current position of cursor on LCDindexstart VAR Byte ' Starting index of Msgindexend VAR Byte ' End index of the Msgline 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)
-
8/9/2019 MAE576 GroupD LAB2 Report
41/53
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 & VARIABLESD0 CON 1 assign constant for various switchesD1 CON 2D2 CON 4D3 CON 8D4 CON 16
D5 CON 32D6 CON 64D7 CON 128'
' SHIFT REGISTER INPUT 74X165 CONSTANTS &VARIABLESClock 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 MODEcounterMAX VAR Wordidlecounter VAR WordcounterPS CON 100'
' 'VARIABLES & CONSTANT FOR RESISTANCE MEASUREMENTRC CON 1 'Pin for RC Circuittime VAR Wordres VAR Word'
' 'VARIABLES & CONSTANT FOR DIGITAL VOLTAGE EOClock CON 13 ' shift clock (74x595.11) for expanding outputEOD_out CON 14 ' serial data out (74x595.14) for expanding outputEOLatch CON 15 ' output latch (74x595.12) for expanding output
DlyTmTot CON 40 'total pulse time
-
8/9/2019 MAE576 GroupD LAB2 Report
42/53
DlyTmOn VAR Byte 'delay time for on pulseDlyTmOff VAR Byte 'delay time for off pulse
flagpwm VAR Bit calibration flag to choose separate calibration for PWMpattern VAR Byte ' output pattern'
' 'VARIABLES & CONSTANT FOR ADC ADdata CON 12 ' A/D data lineADclock CON 11 ' A/D clockADcs CON 2 ' A/D chip select (low true)
result VAR Byte ' result of conversionmVolts VAR Word ' convert to millivolts'
'
'INITIALIZATION' Initialize:DIRL = %11111001 ' setup pins for LCD, RC Circuit,ADC0831flagpwm = 0GOSUB LCDinit ' initialize LCD for 4bit modeHIGH Load ' make output; initialize to 1HIGH ADcs
pattern = %00000000 ' switch relay to normally connected positionGOSUB Out595
Msg = MsgDigi ' display welcome message on LCDindexend = 15line = Line1GOSUB MsgDispMsg = MsgMultiindexend = 15line = Line2GOSUB MsgDispPAUSE 1000
idlecounter = 0counterMAX = 10000sflag = 0
'
' ' MAIN PROGRAM' MainMsgRepeat:
-
8/9/2019 MAE576 GroupD LAB2 Report
43/53
Msg = Msgmodeindexend = 15line = Line1GOSUB MsgDispMsg = Msgselectindexend = 15line = Line2
GOSUB MsgDispMain:GOSUB IdleCheckGOSUB ReadSwitchesIF (Switches = 0) THENsflag = 0GOTO MainELSEIF (Switches = D0 AND sflag = 0) THENGOTO RModeELSEIF (Switches = D1 AND sflag = 0) THEN
GOTO VModeELSEIF (Switches = D2 AND sflag = 0) THENGOTO DVSR2RModeELSEIF (Switches = D3 AND sflag = 0) THENGOTO DVSPWMModeELSEIF (sflag 1) THENGOSUB InvalidInputENDIFGOTO MainEND
'
''SUBROUTINES USED IN THE PROGRAM'
'INITIALIZATION SUBROUTINES
' LCD INITIALIZATIONLCDinit:PAUSE 500 ' let the LCD settleLCDout = %0011 ' 8bit modePULSOUT E,1PAUSE 500PULSOUT E,1PULSOUT E,1LCDout = %0010 ' 4bit modePULSOUT E,1char = %00001100 ' disp on, crsr off, blink offGOSUB LCDcommandchar = %00000110 ' inc crsr, no disp shift
-
8/9/2019 MAE576 GroupD LAB2 Report
44/53
GOSUB LCDcommandchar = ClrLCDGOSUB LCDcommandRETURN
'
' DISPLAY SUBROUTINES
' WRITE ON LCDLCDcommand:LOW RS ' enter command mode
LCDwrite:LCDout = char.HIGHNIB ' output high nibblePULSOUT E,1 ' strobe the Enable lineLCDout = char.LOWNIB ' output low nibblePULSOUT E,1HIGH RS ' return to character mode
RETURN'
' DISPLAY DIGIT ON LCDDigDisp:char = line+index ' set new DDRAM addressGOSUB LCDcommandLOOKUP val,["0","1","2","3","4","5","6","7","8","9","."," "],charGOSUB LCDwrite ' write the characterRETURN
'
'LCD MSG WRITEMsgClrDisp:GOSUB ClrAll
MsgDisp:FOR index = indexstart TO indexend ' get message from EEPROMchar = line + index ' set new DDRAM addressGOSUB LCDcommandREAD (Msg + index indexoffset),char ' read a characterGOSUB LCDwrite ' write it
NEXTRETURN'
' CLEAR FULL LCD DISPLAYClrAll:char = ClrLCD ' Clear the LCDGOSUB LCDcommandRETURN
'
-
8/9/2019 MAE576 GroupD LAB2 Report
45/53
' CLEAR LINE 1/2 OF LCD DISPLAYClrLine:Msg = Msgclrindexend = 15GOSUB MsgDispRETURN
'
' SHOW RESISTANCE ON LCDShowResistance:index = 0GOSUB ClrLine
Msg = MsgResindexend = 3'line = Line1GOSUB MsgDisp
val = res/1000GOSUB DigDisp 'display thousand's digit of Resistanceindex = index +1val = (res/100)//10GOSUB DigDisp 'display hundred's digit of Resistanceindex = index +1val = (res/10)//10GOSUB DigDisp 'display ten's digit of Resistanceindex = index +1val = res//10GOSUB DigDisp 'display one's digit of Resistance
Msg = MsgOhmindexstart = 8indexoffset = 8indexend = 11'line = Line1GOSUB MsgDisp'PAUSE 10000indexstart = 0indexoffset = 0RETURN
' ' DISPLAY VOLTAGEVDisp:GOSUB Read0831
IF flagpwm = 0 THENmVolts = result */ $139C ' x 19.6 (mv / unit)ENDIF
-
8/9/2019 MAE576 GroupD LAB2 Report
46/53
IF flagpwm = 1 THENmVolts = ((result*/ $139C)*/$0006*DlyTmOn)+130 ' obtained from calibrationENDIF
GOSUB ShowVoltage 'display the voltage'DEBUG HOME'DEBUG "ADC..... ", DEC result, " ", CR
'DEBUG "volts... ", DEC mVolts DIG 3, ".", DEC3 mVoltsRETURN'
' SHOW VOLTAGE ON LCDShowVoltage:index = 0'GOSUB ClrAllMsg = Msgclrindexend = 15GOSUB MsgDisp
Msg = MsgVoltindexend = 3GOSUB MsgDisp
val = mVolts/1000GOSUB DigDisp 'display thousand's digit of milivolt
index = index +1val = 10GOSUB DigDisp 'display decimal point
index = index +1val = (mVolts/100)//10GOSUB DigDisp 'display hundred's digit of milivoltindex = index +1val = (mVolts/10)//10GOSUB DigDisp 'display ten's digit of milivoltindex = index +1val = mVolts//10GOSUB DigDisp 'display one's digit of milivolt
Msg = MsgVindexstart = 9indexoffset = 9indexend = 10GOSUB MsgDispindexstart = 0indexoffset = 0RETURN
'
-
8/9/2019 MAE576 GroupD LAB2 Report
47/53
' MODE SUBROUTINES
' RESISTANCE MEASURE MODERMode:GOSUB ClrAllline = Line2Msg = MsgResistance
indexend = 12GOSUB MsgDisp
line = Line1idlecounter = 0
RModeSetflag:sflag = 0
RModeRepeat:HIGH RC
PAUSE 10RCTIME RC, 1, timeres = (time*/$0DA6 + 166)GOSUB ShowResistanceGOSUB IdleCheck'DEBUG HOME, "RESISTANCE = ", DEC5 time '(1459*time/100 + 2324/10)'DEBUG HOME, "time =", DEC5 time, " Res = ", DEC5 resGOSUB ReadSwitchesIF Switches = 0 THEN RModeSetflagIF Switches = D1 THEN VModeIF Switches = D2 THEN DVSR2RMode
IF Switches = D3 THEN DVSPWMModeIF Switches = D7 THENsflag = 1idlecounter = 0GOTO MainMsgRepeatENDIF
IF (Switches = D6 AND sflag=0) THENGOSUB HoldOnENDIF
IF (Switches D6 AND Switches 0)THENidlecounter = 0ENDIFGOTO RModeRepeat
'
' DIGITAL VOLTMETERVMode:flagpwm = 0
-
8/9/2019 MAE576 GroupD LAB2 Report
48/53
pattern = %00000000 ' switch relay to default positionGOSUB Out595GOSUB ClrAll
line = Line2Msg = MsgVoltmeterindexend = 13
GOSUB MsgDispline = Line1idlecounter = 0
VModeSetflag:sflag = 0
VModeRepeat:GOSUB VDispGOSUB IdleCheckGOSUB ReadSwitches
IF Switches = 0 THEN VModeSetflagIF Switches = D0 THEN RModeIF Switches = D2 THEN DVSR2RModeIF Switches = D3 THEN DVSPWMMode
IF Switches = D7 THENsflag = 1idlecounter = 0GOTO MainMsgRepeatENDIF
IF (Switches = D6 AND sflag=0) THENGOSUB HoldOnENDIF
IF (Switches D6 AND Switches 0)THENidlecounter = 0ENDIFGOTO VModeRepeat
'
' DIGITALLY CONTROLLED VOLTAGE SOURCE USING R2R LADDER (DAC)DVSR2RMode:flagpwm = 0LOW EOLatch ' make output and keep low
GOSUB ClrAllline = Line2Msg = MsgVoltageR2Rindexend = 15GOSUB MsgDispline = Line1
-
8/9/2019 MAE576 GroupD LAB2 Report
49/53
idlecounter = 0pattern = %00101000
R2RModeSetflag:sflag = 0
RepeatR2R:
GOSUB Out595GOSUB VDispGOSUB IdleCheckGOSUB ReadSwitchesDEBUG CLS, ? patternIF Switches = 0 THEN R2RModeSetflagIF Switches = D0 THEN RModeIF Switches = D1 THEN VModeIF Switches = D3 THEN DVSPWMModeIF (Switches = D4 AND pattern>32) THEN'DEBUG CLS, ? pattern
pattern = pattern 1 ' decrease voltageENDIFIF (Switches = D5 AND pattern
-
8/9/2019 MAE576 GroupD LAB2 Report
50/53
idlecounter = 0DlyTmOn = 0DlyTmOff = DlyTmTot DlyTmOn
PWMModeSetflag:sflag = 0
RepeatPWM:pattern = %00110000 ' turn on pulseGOSUB Out595PAUSE DlyTmOn ' put pattern on 74x595GOSUB VDispGOSUB IdleCheckGOSUB ReadSwitches
pattern = %00100000 ' turn off pulseGOSUB Out595DlyTmOff = DlyTmTot DlyTmOn
PAUSE DlyTmOff ' put pattern on 74x595IF Switches = 0 THEN PWMModeSetflagIF Switches = D0 THEN RModeIF Switches = D1 THEN VModeIF Switches = D2 THEN DVSR2RModeIF (Switches = D4 AND DlyTmOn>0) THENDlyTmOn = DlyTmOn 1 ' decrease voltageELSEIF (Switches = D5 AND DlyTmOn
-
8/9/2019 MAE576 GroupD LAB2 Report
51/53
PULSOUT Load,3 ' grab the switch inputsSHIFTIN D_in,Clock,MSBPRE,[switches] ' shift them inRETURN
'
' POWER SAVING SUBROUTINES
' SHUTDOWN LCD FOR POWER SAVINGShutDown:char = DispOff ' turn the LCD OffGOSUB LCDcommand
ShutLoop:GOSUB ReadSwitchesIF Switches 0 THEN StartGOTO ShutLoop
Start:char = DispOn ' turn the LCD OnGOSUB LCDcommand
idlecounter = 0sflag = 1RETURN
'
' MISC
' INVALID INPUT MESSAGEInvalidInputMsg:line = Line2GOSUB ClrLine
Msg = Msginvinpindexend = 13GOSUB MsgDispPAUSE 200line = Line1RETURN
'
'SEND BACK ON INVALID INPUTInvalidInput:idlecounter = 0GOSUB InvalidInputMsgGOTO MainMsgRepeat
'
' OUTPUT DATA TO 74X595Out595:SHIFTOUT EOD_out,EOClock,MSBFIRST,[pattern] ' send pattern to 74x595PULSOUT EOLatch,3 ' latch outputsRETURN
'
-
8/9/2019 MAE576 GroupD LAB2 Report
52/53
' READ DATA FROM ADC0831Read0831:LOW ADcsSHIFTIN ADdata,ADclock,MSBPOST,[result\9]HIGH ADcsRETURN
' ' CHECK FOR IDLE COUNTERIdlecheck:idlecounter = (idlecounter + 1)IF idlecounter = counterMAX THENGOSUB ShutDownENDIFRETURN
'
' HOLD PREVIOUS READINGHoldOn:sflag = 1IF (line = Line1) THENGOTO HoldLine1ELSEGOTO HoldLine2ENDIFHoldLine1:line = Line2RETURN
HoldLine2:line = Line1RETURN
'
-
8/9/2019 MAE576 GroupD LAB2 Report
53/53
B. Data Sheets
B.1 ADC0831, 8Bit Serial I/O A/D Converter
Pin ConfigurationB.2 LM358, Low Power Dual Operational Amplifier
Pin Configuration
B.3 74HC595 8bit serialin, serial or parallelout shift register with outputlatches