0000
1
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
2
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Mechatronics Lab Manual
Sabri Cetinkunt, Ph.D.
Professor
Department of Mechanical and Industrial Engineering
University of Illinois at Chicago
c
All
rights reserved.
December 2003, Last Revision: January 04, 2006
2
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Contents
1 Laboratory Experiments
1.1 Familiarization with Lab Tools . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Basic Test and Measurement Tools . . . . . . . . . . . . . . . . . . . . . . . .
1.2.1 Digital Multimeter . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.2 Oscilloscopes: Analog Oscilloscopes and Digital Storage Oscilloscopes
1.2.3 Function Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.4 Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.5 DC Power Supplies . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Experiment 1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4 Experiment 2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.5 Experiment 3: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.6 Experiment 4: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.7 Experiment 5: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.8 Experiment 6: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.9 Experiment 7: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.10 Experiment 8: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.11 Experiment 9: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.12 Experiment 10: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.13 Experiment 11: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.14 Experiment 12: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5
5
7
8
10
12
12
13
20
25
30
35
41
45
51
57
65
69
73
79
3
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
CONTENTS
CONTENTS
4
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Chapter 1
Laboratory Experiments
1.1
Familiarization with Lab Tools
Before working on any lab experiments, students should spend the first week in familiarizing themselves with the tools and components used in building and debugging electronic circuits. Students
should also be instructed about the lab safety. Some points to watch out:
1. Never work on the components while the circuit is powered. Turn OFF the power to the
circuit while assembling and debugging.
2. Never make a short circuit connection (connection with a conductor with almost zero resistance, R ≈ 0 ) betweeen two different voltage potential, ∆V 6= 0, since that would result in
very large current and destroy the circuit components,
i=
∆V
≈∞
R
(1.1)
For instance, never connect the two different potential terminals of a power supply to each
other with a conductor wire. That would most certainly result in destroying the power supply
due to short circuit.
3. Use fuses or circuit breakers to limit the maximum current in circuit inputs. When the rated
current of the fuse or the circuit breaker is reached, they will open the circuit and protect the
rest of the circuit against large currents.
4. It is best to connect all signal grounds at one point such as the power supply ground.
5. Consider the input and output current capacity of components, and use resistors in series
to limit the current passing through a component if necessary. For instance, LEDs have
small resistance. In order to limit current to them from 5V or 12V or similar voltages, it is
recommended to use a small resistance (i.e. 470Ω is common) in series with LEDs. Limiting
5
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.1 Familiarization with Lab Tools
Laboratory Experiments
current through a component is accomplished by adding a series resistor. Let the voltage
across the component be Vc , the resistance of the component be Rc and the resistance of
the current-limiting resistor be Rl. The current through the component without the series
resistor (ic ) and with the series resistor (icl ) are
ic =
Vc
Rc
(1.2)
icl =
Vc
Rc + R l
(1.3)
where the Rl is chosen such that Vc /Rl < imax . Then, even if the component had zero
resistance, the maximum current would be limited by the value of imax . For instance, if
Vc = 10V , and Rl = 1000Ω, the maximum current through a component such as an LED in
series with that resistor is less than
i < imax =
Vc
= 10mA
Rl
(1.4)
The lab setup is shown in Fig.1.1. It has a personal computer (PC) with a development
software environment. The software development tool is the MPLAB IDE (integrated development
environment), which includes built-in editor, assembler (MPASM), linker (MPLINK), debugger
and simulator for PIC microcontrollers. In addition, MPLAB C18 C-compiler is added to the
MPLAB IDE environment and works within the IDE. Hardware components include the PIC
development board for PIC 18F452, MPLAB ICD 2 (In-Circuit Debugger (ICD) hardware and
cables), breadboard for designing interface circuits for the experiments, test and measurement tools
(digital multi meter (DMM), oscilloscope, function generator) and electronic component supply kit.
If a different microcontroller or a DSP is used for the development, the microcontroller development
board and the interface cable between the PC, and the development software tools for the board
will be different. The rest of the development tools are same except that the interface between the
breadboard and the microcontroller board would be specific to each microcontroller.
The PC serves as the program development and debug tool (Fig.1.2). The main software
tool is the MPLAB IDE, an integrated software development environment. Programs are written
on PC, complied, linked, downloaded to the PIC board, run and debugged by communication
between the PC and PIC board. Before downloading a program into the PIC hardware, it can be
debugged by using the simulator (SIM) included in the MPLAB IDE. The simulator is not a real
time simulator, but is still very useful in detecting basic logic errors in the code. The program
development environment is very similar to any other high level programming environment. The
students should read the following product manuals (www.microchip.com),
1. PIC 18Fxx2 Datasheet and Datasheet Errata Manuals: hardware features of PIC 18F452
microcontroller.
6
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.2 Basic Test and Measurement Tools
Development Host with IDE
Test and Measurement Tools
Digital Storage Oscilloscope
IDE Software for
Embedded Target
CD
DMM & Toolbox
PC
Logic Analyzer
Bread Board
Electromechanical
System
Electronic components supply kit
Development Board
(EVM) with microcontroller/DSP chip
Figure 1.1: The components of a development setup for a microcontroller based control system: PC
as host development environment including the development software tools for the microcontroller,
communication cable, microcontroller development board, breadboard, test and measurement tools,
and electronic components supply kit.
2. MPLAB IDE V6.xx (Integrated Development Environment) Software: Quick Start Guide
3. MPLAB C18 C Complier (Quick Start Guide, User’s Guide, Libraries),
4. MPLAB ICD 2 - In Circuit Debugger.
1.2
Basic Test and Measurement Tools
The following test and debug equipment are typically needed when working with electronic circuits
(Fig.1.3):
1. digital multimeter (DMM) used to measure voltage, resistance and current in a circuit. It has
much larger input impedance than the analog multimeter, hence results in smaller loading
error in the measured variable,
7
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.2 Basic Test and Measurement Tools
Laboratory Experiments
Figure 1.2: Development tools for PIC 18F452 microcontroller: PC as host, MPLAB PIC Development Board, MPLAB ICD 2 debugger tool, MPLAB IDE and C18 compiler sofware development
tools.
2. oscilloscope (digital storage type) used to measure and display voltage or current as function
of time on a CRT display,
3. function generator used to generate command or input analog signals to a circuit,
4. “breadboard” wiring board is used as base component for convenient circuit connections
during the development phase of a project.
5. logic probe is used to determine the ON/OFF state of a digital device using an LED indicator,
6. logic clip is multiple LED version of the logic probe,
7. logic pulser is used to temporarily force the state of a digital level into opposite state (if ON
force it to OFF, if OFF force it to ON state) for a few microseconds without destroying the
device.
8. logic analyzer, which is used to test and debug digital circuits. When a small number of
digital lines are involved in testing and accurate timing, a logic probe and a scope are often
needed. When many digital lines are involved, a logic probe and scope may not provide the
sufficient functionality. Hence, a logic analyzer must be used. Ribbon cable connectors with
48-pin, 60-pin or more pins are available as standard connections to logic probes and their
digital state can be monitored simultaneously.
1.2.1
Digital Multimeter
Digital multimeter (DMM) is the most versatile and commonly used test and debug tool for electrical circuits. The basic function of a digital multimeter is to measure the average value of voltage
and current. It displays the measured value with three or four digit accuracy. It does not provide
a history of the signal as a function of time. Instead, the currently measured value of voltage or
current is displayed. If the measured variable is AC, it displays the root mean square (RMS) value
of it (Fig.1.4).
A digital multimeter is used for the following measurements,
8
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.2 Basic Test and Measurement Tools
1. Voltage measurement: Voltage is the potential difference between two points in an electical
circuit. AC and DC voltages are measured (RMS value in case of AC) and numerical value is
displayed. AC voltage is first converted to a DC voltage by a rectifier circuit, then its RMS
value is measured. In addition, the voltage range covered in the measurement is adjustable
(i.e. various ranges in 400 mV to 1000 V ). During the voltage measurement between any two
points on a circuit, DMM forms a parallel circuit between these two points. Hence in order
to minimize the electrical loading error due to the measurement, DMM should have a very
large impedance. Typical input impedance of a DMM is about 10 M Ω. If the resistance of
the measured circuit is nominally around 10 kΩ, the error due to the measurement would be
less than 0.1%.
2. Current measurement: Current is the rate of electron flow through a conductor. Therefore,
the DMM must be in series in the circuit at the point where we want to measure the current.
As a result, current measurement at a point requires disconnecting the circuit at that point
and inserting the DMM between the two leads at that point to complete the circuit. In order
to minimize the loading effect of the DMM in current measurement, the resistance of the
DMM should be as small as possible (opposite of the case for voltage measurement, Fig.1.5).
DMM measures current by passing it through a known precision resistor (Rs) in the DMM
and measures the voltage drop across the the resistor (Vmea ). Then, the current can be
calculated from icalc = Vmea /Rs . AC current is first converted to DC current via a rectifier
circuit and its RMS value is measured.
3. Continuity, Resistor, Capacitor, and Diode Tests: For these tests, the circuit under test
should not be powered (power supply of the circuit should be turned OFF or diconnected,
since DMM provides the test power). DMM can be used to determine whether the electrical
path between any two points has a continuous path that conducts current or it is open that
the current does not conduct. If the circuit between the two points conducts current, the
DMM provides light and sound output (ON/OFF state). Similarly, diode conductivity and
integrity can be tested by a DMM using the same method. Resistor value is measured by
connecting the two leads of the DMM to two leads of a resitor. The DMM measures a
resistance value as follows: using its supply voltage (Vs ) and pass it through a known internal
precision resistor (Rs ), the current can passing over it can be calculated (is = Vs /Rs ). The
the same current sent over the unknown resistor and voltage drop across (Vmea ) the unknown
resistor is measured. Then, the unknown resistor is calculated from R = Vmea /is . Similiarly,
capacitor value is measured by charging the capacitor for a defined period of time (i.e. 1 sec.)
under a constant current flow, and then measure the developed voltage potential. From that
information (measured voltage, current times the time-period- the charge), it calculates the
capacitance. Notice that when resistor, capacitor and diode tests are used, the component
should be removed from the rest of the circuit and the component should be tested as an
individual component.
9
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.2 Basic Test and Measurement Tools
1.2.2
Laboratory Experiments
Oscilloscopes: Analog Oscilloscopes and Digital Storage Oscilloscopes
The operating principle of an analog oscilloscope is shown in Fig.1.6. Digital storage oscilloscopes
are far more commonly used than the analog oscilloscopes. The main reason is the flexibility and
additional data analysis capabilities the digital scopes provide. The basic operating principle of a
digital storage oscilloscope is shown in Fig.1.7. The display section is called the cathode-ray-tube
(CRT). In case of analog scopes, the input signal is amplified by the horizontal or vertical amplifier
and sent to the CRT circuit. Whereas, in digital scopes, the measured signal goes through the
following conversion and processing sequence before being displayed,
1. analog signal is converted to a digital number by an analog-to-digital converter (ADC). The
resolution of the ADC varies between 8, 12 or 16-bits,
2. digital data is stored (and possibly processed, i.e. filtering, smoothing) in the memory buffer.
The fact that the data is stored in memory, the digital oscilloscopes are called storage type,
3. then the digital data is displayed on the monitor (CRT or LCD display)
The performance of an oscilloscope is defined by the following parameters,
1. Bandwidth - the maximum frequency range which the oscilloscope can accurately sample and
display, i.e. scopes upto 100MHz bandwidth are common, and scopes upto 1 GHz bandwidth
being more expensive.
2. Samling rate - the maximum frequency of sampling the data. The bandwidth is limited to
about 1/10 of the sampling rate, since in order to fairly accurately display a transient signal,
there should be about 10 samples within the highest frequency, as a rule of thumb.
3. Resolution of the ADCs and DACs which determines the resolution of measurement, n-bit
ADC and DAC will provide a resolution of 1 part in 2n in the measurement range. For
instance, an 8-bit resolution provides 1 part in 256 resolution, 10-bit provides 1 part in 1024,
and 12-bit provides 1 part in 4096. In order to cover a wide range of signal (i.e. +/ − 5 V or
+/ − 50 V ) without saturating the ADC input range, input probes are available with gains
of X1, X10. The probe is used to prescale the signal so that whole range is measured by
the ADC without saturation.
4. Memory size - determines how many sampled data points can be stored in memory for later
use. The memory buffer is used as a circular buffer. When it is full, the new data over-writes
the oldest data. The time duration for which a signal can be stored depends on the buffer size
and sampling rate. If long periods of signal storage is desired and that the signal frequency
content is low, the sampling rate can be lowered in order to store data for a larger time period
(but less often) in a fixed memory buffer. Let the memory buffer size be Nm bytes, and the
resulution of ADCs be Nr bits, and sampling frequency be fs Hz, the time period of data
that can be stored is
10
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.2 Basic Test and Measurement Tools
t [sec] =
Nm 1
(Nr /8) fs
(1.5)
The storage capability of digital oscilloscope gives significant advantage in measurements. The
data can be easily manipulated and analyzed after it is captured an stored. Most digital storage
oscilloscopes provide the following data manipulation capabilities as a very convenient and useful
tools,
1. measure the value of signal at a particular point on the plot on the CRT,
2. measure pulse width,
3. measure maximum and minimum values,
4. measure rise/fall times,
5. zoom-in and zoom-out to focus more closely on the signal (change the scale in the x-axis and
y-axis with control knobs on the front panel of the scope),
6. appy filtering and smoothing (averaging) functions on the stored data.
Finally, data collection is controlled by trigger logic. Since memory size is finite and data can not
be stored indefinitely, we need to time the start and end of the measurement based on events or
signal levels. Such events that control the start and end of oscilloscope measurement are called
triggers. The trigger signal source can be either internal (internally generated by the scope, i.e.
using the level of the measured signal as trigger. For instance, when the input signal value crosses
0 V level, internal trigger is generated) or external (i.e. a square wave signal or single-shot pulse).
Trigger coupling refers to the filtering of the trigger signal before being used in the trigger logic. For
instance, AC or DC component of the trigger source signal may be passed, or it may be processed
through a low-pass or high-pass filter.
In a two-channel scope, the signals can be displayed either as two separate plots as function of
time (horizontal axis is time, vertical axis has two signals with independent scaling) or one channel
can be connected to the horizontal axis and the other to the vertical axis to display signal in the
x-y plot form where the time is parameterized over the screen plot. Such display modes are useful
in ploting the path of two axis motion system, or measuring the impedance of a circuit between
input and output.
A typical digital storage oscilloscope provides two channels of measurement with sampling
frequency of 100MHz and 10-bit resolution. Digital oscilloscope is a programmable measurement
and display device. Different setup parameters can be saved for quick recall for later use so that
each parameter does not have to be setup for different measurement conditions, i.e. scope may
support 40 different setup conditions that can be stored and recalled later. The setup parameters
include the sampling rate, filtering if any, trigger conditions, scales in the horizontal and vertical
axis, signal source to horizontal and vertical axis (time, channel 1, channel 2) etc.
11
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.2 Basic Test and Measurement Tools
1.2.3
Laboratory Experiments
Function Generator
Function generators are used as analog input signal sources to electronic circuits. A function
generator typically have options to generate some common periodic and random signals. Periodic
signal shape, magnitude, frequency and DC offset value can be defined on the function generator.
Examples include
1. periodic signal types: sinusoidal signals, rectangular periodic pulse signals, saw-tooth or
triangular signals.
2. magnitude range of the signal: 0V to 2V , 0V to 5V , 0V to 10V , −2V to 2V , −5V to 5V ,
−10V to 10V . The magnitude range does not have be even, i.e. −2V to 5V or 2V to 5V .
3. frequency of the signal: i.e. 0.01Hz to 100kHz.
In addition, a function generator can also generate random or pseudo-random signals. Modern
function generators have programming capabilities that allow them to generate a signal with any
arbitrary waveform desired.
1.2.4
Breadboard
The breadboard allows easy plug-in connections between circuit points without soldering (Fig.1.8).
As a result, it is also called solderless breadboard. Unlike soldering, the connections are not permanent. A connection between any two points can be made or broken by simpy connecting or
disconnecting a wire between two holes on the board. The breadboard provides the following,
1. a base for installing electronic components,
2. power bus (Vcc and ground) via horizontal lines where by a simple two point jumper wire,
desired power can be connected to any point on the wire holes. For instance the two rows at
the top and two rows at the bottom are typically connected to 5V DC, GROU N D, −5V DC,
10V DC signals. Once a connection is made to any one of the X1, X2, Y1, Y2 holes, all of the
other holes in that row have the same signal. These signals can be brought to the columns
of the breadboard by a single jumper between any column from the rows (X1, X2, Y1, Y2)
and any hole in the selected column in the main center section of the board. Notice that top
and bottom middle half of the board are such that each column has the same signal.
3. direct connections between the wire holes in a column.
This flexiblity makes the breadboard the standard tool used in the development of electronic circuits. Once the design is completed, the circuit can be implemented on a printed circuit board or
a hard wired (soldered) circuit board. Notice that a component such as a resistor or a capacitor
should never be installed with both terminals on the same column. That would end up providing
the same voltage at the two terminal of the component, rendering it non-functional. Similarly, an
IC should be installed with one side of pins on the upper half and the other side of pin on the lower
half of the breadboard. An IC should never be installed with all pins on one half of the breadboard
12
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.2 Basic Test and Measurement Tools
Digital storage oscilloscope
Function generator
Digital multimeter (DMM)
Digital pulser
Digital probe
Logic analyzer
Figure 1.3: Test and debug measurement tools used in electronic circuit design: digital multi meter
(DMM), digital storage oscilloscope, function generator, logic probe, logic pulser, logic analyzer.
or in the direction of columns. In short, an IC should be installed aligned with the rows of the
breadboard and half of pins should be making contacts on the upper-half and the other half of pins
should be making contact on the lower-half of the breadboard.
1.2.5
DC Power Supplies
Most electronic equipment requires DC power supply. DC power can be provided by batteries or by
converting from AC supply line. A DC power supply is rated by the nominal output voltage it can
provide upto a rated current, (Vout at ir ), within a specified maximum regulation error (∆Vreg or
∆V % expressed as percentage of rated voltage). The ripple refers to the voltage output variations
under constant load conditions. For instance the rated specifications of a DC power supply may
include the following: 12V DC output at 2.0A with load regulation of +
− 1% of maximum output
voltage, and 25mV ripple voltage (peak-to-peak). Therefore, the output voltage variation due
to maximum load can be upto 0.12V , whereas the maximum ripple on the output voltage under
13
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.2 Basic Test and Measurement Tools
Laboratory Experiments
Digital Multi Meter (DMM)
i
Figure 1.4: Operating principle and circuit components of a digital multimeter (DMM).
14
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.2 Basic Test and Measurement Tools
AC Voltage Measurement
Current Measurement
Circuit Power:
OFF to connect meter
ON for measrment
OFF to disconnect meter
DC Voltage Measurement
Resistance measurement
Component testing:
Circuit Power
resistor, capacitor, diode, switch continuity
OFF
Figure 1.5: Applications of a digital multimeter in voltage, current, resistance, capacitance measurements, diode and continuity tests.
15
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.2 Basic Test and Measurement Tools
Laboratory Experiments
Vertical System
Vertical
Attenuator
Amplifier
CRT
Probe
Horizontal System
Trigger
Sweep
Horizontal
System
Generator
Amplifier
Ramp Time Base
Figure 1.6: Operating principle of an analog oscilloscope.
Vertical System
Proccesing
Vertical System
Display
Analog to
Attenuator
Vertical
Digital
Amplifier
Convertor
Digital
Memory
Display
System
Horizontal System
Probe
Sample
Trigger
Clock
System
Clock Time Base
Figure 1.7: Operating principle of a digital storage oscilloscope.
16
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.2 Basic Test and Measurement Tools
(a)
X1
X2
Y1
Y2
(b)
Figure 1.8: Solderless breadboard used for electronic circuit development. Horizontal lines are used
for power and ground connections. Each column below X1 and X2, and above Y1 and Y2 has the
same electrical signal. a) Top view of a solderless breadboard, b) electrical connections under the
cover between the connection points.
17
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.2 Basic Test and Measurement Tools
Laboratory Experiments
constant load conditions can be upto 25mV .
Batteries are used only in mobile applications and avoided whenever possible. A DC power
supply using AC line as its source has three main components for unregulated and four components
for regulated types (Fig.1.9):
1. transformer,
2. rectifier,
3. filter,
4. voltage regulator.
The transformer is a passive device that has an iron core and two coil windings on the core, called
the primary winding and secondary winding. There are two functions a transformer performs,
1. changes the AC voltage level between input and output (it can increase, step-up, or decrease,
step-down the voltage),
2. electrically isolates the input and output terminals since the coupling is strictly magnetic.
The current carrying conductors of the primary winding induce a magnetic field. The strength
of the magnetic field is proportional to the number of turns in the primary coil and the current
magnitude. The magnetic field variation follows the variation of the current. The magnetic field
is coupled to the secondary windings via the iron core. Voltage is induced in each turn of the
secondary coil as the magnetic field varies. This is the result of Faraday’s induction law. The
induced voltage is proportional to the number of windings. In other words, voltage per winding
is constant in the transformer. Most transformers convert the electrical power from primary to
secondary winding at 85 to 90% efficiency. Let us assume that we have an ideal transformer with
100% efficiency, then the input-output relationship between the voltage, current and impedance in
the transformer can be expressed as
N2
· Vin
N1
= Pin ; assume
Vout =
Pout
Vout · iout = Vin · iin
N1
iout =
· iin
N2
(1.6)
100% ef f iciency
(1.7)
(1.8)
(1.9)
A bridge rectifier which converts the AC voltage to a unidirectional voltage uses four diodes in
a bridge configuration (Fig.1.9). When the input voltage to the rectifier is positive, the diodes D1
and D2 are ON, the diodes D3 adn D4 are OFF. When the input voltage is negative, the diodes
D1 and D2 are OFF, and D3 and D4 are ON. The flow of current across the load on the output
terminals are in the same direction. This accomplishes a rectified output voltage.
18
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.2 Basic Test and Measurement Tools
Transformer
Rectifier
D
D
4
D
2
N
1
1
D
3
N
2
V
V
1
Voltage Regulator
Filter
V
V
V
2
Figure 1.9: Components of a DC power supply. Unregulated DC power supply does not have the
voltage regulator element. The voltage regulator may be followed by another low-pass filter to
provide a smoother output DC voltage.
In order to turn the rectified voltage output to a smoother DC voltage, we use an RC filter
to smooth out the oscillating voltage and provide a DC voltage output. The ripple voltage is a
function of the RC filter parameters (Fig.1.9).
The voltage regulator is the component between the RC filter output and the output terminals
of the regulated power supply. Though simpler versions are available as shown in Fig.1.9, a typical
voltage regulator has an output voltage sensing component, reference (desired) voltage generator
circuit, and an operational-amplifier to control effectively the resistance of the regulator transistor
element so that a corrective action is taken to control the error between the reference and the
sensed output voltage. Common integrated circuit (IC) voltage regulators are 7800-series fixed
output voltage regulators (7805 for 5V, 7812 for 12V, 7815 for 15V), LM317-series adjustable
voltage regulators, and 723-series voltage regulators. The IC package has a transistor (in addition
to other op-amps and circuits) which provide the variable resistor functionality. The heat generated
as a result must be dissipated via a heat-sink mounted on the IC. The heat-sink is a metal with
high thermal conductivity coefficient and has large surface area for heat convection. If the voltage
regulator controls the voltage by controlling the power transistor in linear amplifier mode, it is
called the linear DC power supply. If it controls the power transistor in PWM switching mode
(all ON or all OFF, but control just the ON/OFF time periods), it is called the switching power
supply. The typical switching freqeuncy is in 10kHz range. The PWM switching type is more
energy efficient but has more noise than the linear type.
19
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.3 Experiment 1:
1.3
Laboratory Experiments
Experiment 1:
Basic Electrical Circuit Components and Kirchoff ’s Laws
Objectives
1. Confirm by measurements the input-output behavior of basic electrical and electronic circuit
components: resistance measurement, capacitance measurement, diode test.
2. Confirm the Kirchoff’s voltage and current law in a simple DC circuit with resistors.
3. Build a voltage divider circuit and verify the predicted results from Kirchoff’s laws by measurement
4. Build a current divider circuit and verify the predicted results from Kirchoff’s laws by measurement
Theory
The passive components makes up the main building blocks of electrical circuits: resistor, capacitor
and inductor. The input-output relationship of these “ideal” components are as follows. A resistor
has the following current-voltage relationship, also called Ohm’s Law,
V12(t) = R · i(t)
(1.10)
where V12 is the voltage potential across the resistor, i(t) is the current across the resistor and R is
the resistance of the component. In the text, we discussed that the resistance is a function of the
conductor material and its cross section area, its lenght. In addition, resistance of most materials
vary with temperature, a propperty used to design temperature sensors. Here, we will measure the
resistance of various standard carbon resistors used in building electronic circuits.
An “ideal” capacitor has the following current voltage relationship,
V12(t) = V12(t0) +
1
C
Z
t
i(τ )dτ
(1.11)
t0
which says that the voltage across a capacitor is the initial voltage of the capacitor plus the integral
of the current flowing through the capacitor scaled by the capacitance value C. V12(t) is the voltage
across the capacitor at a given time t. Each capacitor will eventually saturate when it stores the
maximum charge it can store. When the current flow stops, there is always some small current
leakage in capacitors. In order to limit the current coming into a capacitor from a DC power supply,
a capacitor is never directly connected to a supply, but through a resistor.
An “ideal” inductor has the following current voltage relationship,
20
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.3 Experiment 1:
V12(t) = L ·
di(t)
dt
(1.12)
which says that the voltage across the inductor is proportional to the time rate of change of current.
Another way of interperting it is that the current is integral of voltage applied across it. If a constant
voltage source is applied, the current would increase as integral of it, scaled by the inductance.
Kirchoff’s voltage law states that the sum of voltages in a closed path of an electrical circuit is
zero (conservation of voltage potential) at any given instant,
V14 = V12 + V23 + V34
(1.13)
Kirchoff’s current law states that the algebraic sum of currents at any point in an electrical circuit
is zero, that is sum of in-coming currents is equal to the sum of out-going currents (conservation
of electrons),
X
i1 + i2 + i3 = 0
(1.14)
The reader should see the textbook for more detailed discussions. Consider the voltage divider
circuit shown in Fig1.10.a and current divider circuit shown in Fig.1.10.b. Notice that a series
of resistors and a voltage supply forms a voltage divider. The voltage across each resistor is
proportional to that resistor value relative to others. Whereas, a set of parallel resistors make up a
current divider circuit. Larger current goes thru the smaller resistor since there is smaller resistance
to the flow of electrons. For the voltage divider circuit
Vs (t) = V12(t) + V23(t)
= R1 · i(t) + R2 · i(t)
Vs (t)
i(t) =
R1 + R 2
R1
V12(t) =
Vs (t)
R1 + R 2
R2
V23(t) =
Vs (t)
R1 + R 2
(1.15)
(1.16)
(1.17)
(1.18)
(1.19)
The last two equations show how the voltage is divided between the series resistors.
For the current divider circuit,
21
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.3 Experiment 1:
Laboratory Experiments
Vs (t) = V12(t)
= R1 · i1 (t)
(1.20)
(1.21)
= R2 · i2 (t)
i(t) = i1 (t) + i2(t)
Vs (t) Vs (t)
=
+
R1
R2
1
1
= (
+
) · Vs (t)
R1 R2
R 1 · R2
Vs (t) =
· i(t)
R1 + R 2
= R1 · i1 (t)
(1.22)
(1.23)
= R2 · i2 (t)
R2
i1(t) =
· i(t)
R1 + R 2
R1
i2(t) =
· i(t)
R1 + R 2
(1.28)
(1.24)
(1.25)
(1.26)
(1.27)
(1.29)
(1.30)
Notice that the last two equations show how the current in the main line is divided over the two
parallel braches of resistors. Current measurement requires the measurement instrument to be
placed in series between the two points through which the current flow is being measured. This
requires disconnecting the circuit at a point, and inserting the current measurement instrument
(i.e. DMM in current measurement mode, ammeter) into the circuit. Such circuit modifications
are not always possible nor convenient. Another way to measure current indirectly is to measure
the voltage across a known resistor, then use the Ohm’s Law to calculate the current. If there is a
resistor of known value at the circuit branch that we want to measure current, then we can measure
the voltage across it, and divide the measured voltage by the resistor value to calculate the current
that passes through that resistor. This method is easier and accurate enough for us to use in the
experiments.
22
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
R
1
V (t)
s
1
2
i(t)
1.3 Experiment 1:
R2
3
V (t)
R2
i(t)
s
R
i (t)
1
i (t)
2
1
(a)
(b)
Figure 1.10: a) Voltage divider circuit, b) current divider circuit.
Procedure
1. Using the digital multi-meter (DMM) and discussions on page 9, and (Fig.1.5.d), measure
the resistance, capacitance of a few resistors and capacitors. Confirm your measurement with
the specifications of the component.
2. Using DMM, measure the direction of conduction of a diode.
3. Using DMM, measure the continuity across a mechanical switch by turning ON/OFF the
switch.
4. Build a voltage divider circuit (Fig.1.10.a). Confirm the Kirchoff’s voltage and current law
on the circuit using various closed paths for voltage law and nodes for current law.
5. Build a current divider circuit. Confirm the Kirchoff’s voltage and current law on the circuit
using various closed paths for voltage law and nodes for current law (Fig.1.10.b).
6. Build the RL and RC circuits discussed (Fig.1.11) in Appendix B of the text book, and
duplicate the predicted results shown in the Appendix B of the textook by measurements.
7. In the RC circuit, increase the value of R significantly which should provide an almost constant
current to the capacitor for a while and measure the almost integral like change in the voltage
across the capacitor.
8. Do the same for RL circuit, and confirm the almost integral like change in the current across
the inductor.
23
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.3 Experiment 1:
Laboratory Experiments
R
A
L
R
A
B
B
i(t)
i(t)
V(t)
C
V(t)
(a)
(b)
Figure 1.11: a) RL circuit b) RC circuit.
24
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.4
1.4 Experiment 2:
Experiment 2:
Transistor Operation: ON/OFF Mode and Linear Mode of Operation
Objectives
1. Understanding operating principles of a NPN type BJP transistor.
2. Design and build a circuit involving a NPN type BJP transistor in common-emitter configuration.
3. Experimentally determine the ON/OFF mode and linear mode of operation, and measure the
relevant voltages.
Components
Item
Resistors as calculated
BJP transistor, NPN type
Breadboard
Set of connection wires
Quantity
2
1
1
1 set
Part No.
276-174
Supplier
Jameco Electronics (www.jameco.com)
Jameco Electronics (www.jameco.com)
Radio Shack (www.radioshack.com)
Jameco Electronics (www.jameco.com)
Theory
The transistor is like an ”electron valve”. It is the electrical analogy of the hydraulic valve. A
hydraulic valve regulates the flow of fluid: it can be fully closed, fully open or partially open. A
transistor is an electrical valve. It regulates the flow of electrons: it can be fully OFF, fully ON
or partially ON. If a transistor is operated only in either fully ON or fully OFF mode, we call it
ON/OFF mode operation. In the OFF mode, it is called the cut-off state. In the fully ON mode,
we call it saturation state. In between them, it operates proportional to the base current and called
to be in linear mode.
The relationships between electrical variables (voltages and currents) and electrical parameters
(resistance, transistor parameters) can be shown as (Fig.1.12) follows. The Kirchoff’s voltage law
between base (B) and emitter (E) indicates
Vin = VAB + VBE
= R1 · iB + VBE
(1.31)
(1.32)
where VBE = VF B = 0.6V to 0.8V range. VF B is the forward bias voltage between base and emitter
and it can be upto 0.6V to 0.8V range typically. This value is a property of a transistor and given
in the datasheet of the transistor. If Vin is so small that that VBE < VF B , then no current flows at
the base iB = 0 and the transistor is in the cut-off (OFF state) mode. Similarly, applying Kirchoff’s
25
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.4 Experiment 2:
Laboratory Experiments
voltage law on the output side of the transistor, and noting that the transistor acts as a current
amplifier between its fully OFF (cut-off) and fully ON states (saturation), which is called the active
linear mode of operation. The current gain (β) is a property of the transistor and provided in its
datasheet. There can be variations in that gain upto 100% due to manufacturing variations. Robust
circuit designs should not rely on exact value of the current gain of the transistor.
iC
= β · iB
Vs = VDC + VCE
= R2 · iC + VCE
(1.33)
(1.34)
(1.35)
Notice that VCE can be between maximum value of Vs (when ic = 0, transistor is in cut-off (OFF)
mode) and minimum drop value of about VCE,min = 0.2V (when the transistor is saturated, fully
ON) which is a property of the particular transistor.
We can measure the two input voltage values of interest: first, the minimum input voltage
necessary to start making the transistor conduct, Vin,min . For input voltages below that the transistor will not conduct (OFF). Second, the value of the input voltage for which the transistor
saturates (fully ON) and collector current and VCE output voltage does not change if input voltage
is increased beyond that value (Vin,sat).
The Vin,min is the voltage value which is necessary to provide the forward bias voltage plus
just a bit more in order to make the transistor to start conducting. So, this value is expected to
the close to the forward-bias voltage of the transistor. This can be determined experimentally by
slowly increasing Vin and monitoring the change in VCE .
The Vin,sat value is the value which provides a base current (iB , and after being amplified results
in iC = β iB such that VCE = VCE,min . Voltages more than that will not result in any change
in the output since the VCE can be no less that VCE,min ≈ 0.2V and the rest of the available
supply voltage is used to generate the current iC . From the voltage relations of the output and
input circuits, we can calculate the input voltage saturation value and experimentailly nmeasure
to confirm it approximately,
iC
=
=
iB =
=
Vin,sat =
=
Vs − VCE
R2
Vs − 0.2
R2
1
· iC
β
1 Vs − 0.2
·
β
R2
R1 · iB + VBE
1 Vs − VCE,min
R1 · ·
+ VF B
β
R2
(1.36)
(1.37)
(1.38)
(1.39)
(1.40)
(1.41)
26
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.4 Experiment 2:
where VCE ≈ VF B = 0.6V to 0.8V range, VCE,min ≈ 0.2V . Exact values of these voltages may
vary from transistor to transistor. However, we can accurately measure them experimentally by
carefully recording when the transistor makes the transition from cut-off state to conducting state
in linear region and from linear region to fully ON saturation region.
Vs
D
R2
C
A
Vin
R1
ic
B
iB
E
Figure 1.12: Circuit of a voltage amplifier using a transistor in a common emitter configuration.
Procedure
1. Design and build the circuit shown in Fig.1.15, 1.16, 1.17.
2. Choose R1 = 10KΩ, R2 = 1.0KΩ, Vs = 12V . Other values for R1 and R2 can be choosen.
And other available DC voltage can be used for Vs .
3. Provide a means of adjusting the voltage input at the base of the aplifier at point A. This
can be done by using either a DC power supply (i.e. 3 V plus an adjustable series resistor
(Rs) that would act as a voltage divider when used in series with the R1 resistor) or through
the DAC output channel of the PIC microcontroller.
4. Measure the voltage at the following points, Vin , VAB , VBE , VCE , VDC , and make a table of
them, each voltage representing a column on the table.
5. Set Vin to different values in increments, i.e. 0.0V , 0.1V , ... , 1.5V , and measure the other
four voltages and record them using your digital multimeter (DMM) or oscilloscope.
27
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.4 Experiment 2:
Laboratory Experiments
Figure 1.13: Picture of the experimet setup for the transistor circuit.
6. Plot the input voltage (Vin ) and output voltage relationships (VCE , VDC ) and conclude in
what range of input voltage the transistor is fully OFF, fully ON, and in proportional (linear)
amplifier mode.
7. Discuss how the input voltage and output voltage relationship would change is the resistor
values R1 and R2 were to change, i.e. R1 = R2 = 10KΩ, or R1 = 10KΩ, R2 = 1.0KΩ.
28
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.4 Experiment 2:
Figure 1.14: Picture of the assembled circuit on bread-board for the transistor circuit.
Vin [V ]
0.0
0.05
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2.0
VAB [V ]
VBE [V ]
VCE [V ]
VDC [V ]
29
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.5 Experiment 3:
1.5
Laboratory Experiments
Experiment 3:
Passive First Order RC Filters: Low Pass Filter and High Pass Filter
Objectives
1. Understanding the theory of filter circuits and their applications.
2. Circuit design of a passive low-pass filter. Build the complete circuit.
3. Circuit design of a passive high-pass filter. Build the complete circuit.
4. Getting familiar with standard measurement tools and signal generators. Measure the input
and output voltage signals of the filter circuit and confirm the expectations with measurements.
Components
Item
Resistor as calculated
Capacitor as calculated
Breadboard
Set of connection wires
Quantity
1
1
1
1 set
Part No.
276-174
Supplier
Jameco Electronics (www.jameco.com)
Jameco Electronics (www.jameco.com)
Radio Shack (www.radioshack.com)
Jameco Electronics (www.jameco.com)
Theory
Filters are used to ”filter” the freqency content of the input signal and present the ”filtered” or
”cleaned-up” version of the input signal as its output signal. Low-pass filters pass the low freqency
content and remove (more accurately attenuate) the high frequency content of the input signal.
High-pass filter does the opposite: remove (filter-out) the low frequency content and pass the high
frequency content. Band-pass filters pass the frequency content in a frequency range, and remove
the freqency content below and above that range. Notch-filters do the opposite: pass all frequency
content except a selected range which is removed.
In this experiment, we will build and test a passive low-pass filter and a passive high-pass filter.
The filters will be built using passive components: a resistor and a capacitor. Fig.1.15 shows the
circuit diagram for a low-pass and a high-pass passive filter.
The input-output voltage relationship for the low-pass filter can be derived as follows. The
voltage across the capacitor is the output voltage and related to the current and capacitance value
as
Vo(t) =
Vo(s) =
Z
1 t
i(τ )dτ
C 0
1
i(s)
Cs
(1.42)
(1.43)
30
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.5 Experiment 3:
The current in the circuit is
Vi (t) − Vo (t)
R
Vi (s) − Vo (s)
i(s) =
R
1
R · i(s) = Vi (s) −
i(s)
Cs
i(t) =
(R +
1
) · i(s) = Vi (s)
Cs
i(s)
Cs
=
Vi (s)
RCs + 1
(1.44)
(1.45)
(1.46)
(1.47)
(1.48)
Hence the transfer function between the output voltage and input voltage is
Vo(s)
=
Vi(s)
Vo(jw)
=
Vi(jw)
Notice that when w =
1
RC [rad/sec],
1
RCs + 1
1
1 + jRCw
(1.49)
(1.50)
the magnitude ratio of the output voltage to input voltage is
|
Vo(jw)
1
| = √ = 0.707
Vi(jw)
2
(1.51)
1
1
where the value wc = RC
[rad/sec] or fc = 2πRC
[Hz] is called the cut-off frequency of the filter, that
is the frequency at which the output signal magnitude is 0.707 times the input signal magnitude in
steady state. In other words, the output signal is attenuated by 3dB in comparison to the input
signal.
Simularly, the input-output voltage relationship can be derived for the high-pass filter. Notice
that the location of resistor and capacitor on the circuit is swapped compared to low-pass filter.
Following the similar derivation process, it is straight forward to derive the input-output voltage
relationship.
Vo(t) = R · i(t)
(1.52)
Vo(s) = R · i(s)
(1.53)
The voltage across the capacitor,
31
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.5 Experiment 3:
Laboratory Experiments
Vi (t) − Vo (t) =
Vi (s) − Vo (s) =
By substituting the relationship for i(s) =
1
R Vo (s),
Vo(s)
=
Vi(s)
Vo(jw)
=
Vi(jw)
Z
1 t
i(τ )dτ
C o
1
i(s)
Cs
(1.54)
(1.55)
it can be shown that
RCs
1 + RCs
jRCw
1 + jRCw
(1.56)
(1.57)
which represents the high-pass filter transfer function. Again, notice that at w = wc where wc =
1
1
RC [rad/sec] or fc = 2πRC [Hz], the magnitude ratio is 0.707. Except that in high-pass filter, the
filter passes the frequency content above this frequency and attenuates the frequency content below
that frequency. The low-pass filter does the opposite.
R
C
V (t)
i
C
(a)
V (t)
o
V (t)
i
R
V (t)
o
(b)
Figure 1.15: Circuit of a 1st order passive filters: a) passive low-pass first order filter, b) passive
high-pass first order filter.
Procedure
1. Design and build a passive low-pass filter and a passive high-pass filter as shown in Figure
1.18 with a cut-off frequency in the range of fc ≈ 1.0kHz. Select proper R and C values.
2. Set up the function generator to produce a sinusoidal wave with an amplitude of 6V (peakto-peak). Notice that we do not need to provide any power to the circuit, only the input
signal, since it is a passive circuit. When we build active filters with Op-amps, we need to
provide power to the op-amp in addition to providing the input signal.
3. Connect an oscilloscope to the input and output of the low-pass filter. Scan the frequency
range of 10Hz to 100kHz and measure the output voltage at each selected frequency.
32
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.5 Experiment 3:
Figure 1.16: Picture of the experimet setup for a 1st order passive filter.
Vi(t)
Vo(t)
Low-pass filter
Vi(t)
Vo(t)
High-pass filter
GND
GND
Figure 1.17: Picture of the assembled circuit on bread-board for a 1st order passive low-pass and
high-pass filter.
4. Obtain oscilloscope screen shots or simply create a sketch at selected frequencies to show the
effect of each filter in time domain.
5. Compare your experimental measurements of frequency response with the analytical predic33
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.5 Experiment 3:
Laboratory Experiments
tions. For analytical predictions, plot the transfer function magnitude as function of frequency,
i.e. using Matlab.
34
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.6
1.6 Experiment 4:
Experiment 4:
Active First Order Low-pass Filter with Op-Amps
Objectives
1. Understanding the theory of filter circuits and their applications
2. Circuit design of an active Op-Amp low-pass filter. Build the complete circuit.
3. Getting familiar with standard measurement tools and signal generators. Measure the input
and output voltage signals of the filter circuit and confirm the expectations with measurements.
Components
Item
LM358 Op-Amp IC
Resistor 820kΩ
Resistor as calulated
Capacitor as calculated
Breadboard
Set of connection wires
Quantity
1
1
1
1
1
1 set
Part No.
23966
30082
276-174
Supplier
Jameco Electronics (www.jameco.com)
Jameco Electronics (www.jameco.com)
Jameco Electronics (www.jameco.com)
Jameco Electronics (www.jameco.com)
Radio Shack (www.radioshack.com)
Jameco Electronics (www.jameco.com)
Theory
For our purpose, a filter is designed as any circuit that produces a prescribed frequency response
characteristic, of which the most common objective is to pass certain frequency range while rejecting
others. Filters may be classified into two major groups: passive filters and active filters. Passive
filters consist of combinations of resistors, capacitors and inductors. Passive RLC structures are
capable of achieving relatively good filter characteristics in applications in the audio frequency
range. But at the lower end of the audio frequency range, a problem occurs due to the high internal
loss of inductors at low frequencies. Active filters consist of combinations of resistance, capacitance,
and one or more active devices, such as Op-Amps, employing feedback. Since inductances are not
required, the difficulties associated with them at low frequencies are eliminated.
From the point of view of the amplitude frequency response, most filters can be classified
as low-pass, high-pass, band-pass and band-rejection (notch) filters. In this experiment we will
concentrate on a low-pass filter design. Figure 1.18 shows an amplitude response of a realistic
low-pass filter. The quantity fc represents the the cutoff-frequency. In an ideal case, the amplitude
response for f < fc is unity, so frequencies in this range are passed by the filter. For f > fc , the
amplitude response is zero, so frequencies in this range are completely eliminated by the filter. In
reality however, there is a transition band in between the pass band and the stop band, where the
amplitude response decreases continuously.
35
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.6 Experiment 4:
Laboratory Experiments
Figure 1.18: Representative amplitude response of a realistic low-pass filter.
Figure 1.19: Circuit of a 1st order active low-pass filter.
Figure 1.19 shows a first order active low-pass filter circuit. The transfer function in frequency
domain between input and output voltages can be derived by following the op-amp idealized assumptions and Kirchoff’s current and voltage laws. The voltage at positive terminal is grounded,
hence the voltage potential at negative terminal is also grounded since v + = v − ,
v+ = 0
v
−
= 0
(1.58)
(1.59)
Then we can calculate the current over the resistor R1.
36
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.6 Experiment 4:
i1 =
Vi
R1
(1.60)
Also note that no current would flow into the op-amp, then the same current must pass thru the
R2 and C combination (noting Kirchoff’s current law),
ii =
=
Vo =
Vi
= iR2 + ic
R1
Vo
+ ic
R2
Z t
1
i(τ )dτ
C 0
(1.61)
(1.62)
(1.63)
where we use the fact that the current flow over the R2 and C is determined by the output voltage
and the ground voltage at the negative input (inverting) terminal. We will add the negative sign
to the input-output voltage relation at the end of the derivation. If we take the Laplace transform
of the above equations, we can easily find the transfer function betwen input voltage and output
voltage,
Vi (s)
Vo (s)
=
+ Cs · Vo (s)
R1
R2
1
R2
·
= −
R1 1 + R2Cs
i1(s) =
Vo(s)
Vi(s)
(1.64)
(1.65)
where we added the negative sign to indicate the sign relationship between input voltage and output
voltage are opposite.
Vo (jw)
1
R2
H(jω) =
·
=−
(1.66)
Vi(jw)
R1 1 + jωR2C
For the case of R1 = R2 = R we have
H(jω) = −
1
1 + jωRC
(1.67)
The cutoff frequency fc is defined as the point where
Vo(jw)
1
|= √
Vi(jw)
2
1
20 · Log10|H(jω)| = 20 · Log10 √ = −3dB
2
|H(jω)| = |
(1.68)
(1.69)
37
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.6 Experiment 4:
Laboratory Experiments
Thus, we can write
1=j
ω
RC
ωc
from that it follow
ωc = 2πfc =
1
RC
(1.70)
(1.71)
and finally
fc =
1
2πRC
(1.72)
Procedure
1. Design an active low-pass filter as shown in Figures 1.19, 1.20, 1.21 with a cutoff frequency
of fc ≈ 1.9kHz and a DC gain of |GDC | = 1. Use R1 = 820kΩ and calculate R2 and C to
meet the design specifications.
2. Build up the circuit and power the OpAmp with a 9V battery or power supply.
3. Set up the function generator to produce a sinusoidal wave with an amplitude of 6V (peakto-peak). What has to be the offset voltage of the signal? (Remember, we use a single voltage
supply!).
4. Connect an oscilloscope to the output of the low-pass filter. Scan the frequency range of
10Hz to 100kHz and measure the output voltage at each selected frequency. Create a table
showing the ratio VVout
for the selected frequencies.
in
5. Use logarithmic paper to plot the amplitude response of the filter (Bode plot). Show |H(jω)|
over f requency. Mark in the 3dB cutoff frequency. Compare the experimental results with
analytical results obtained by plotting equation 1.67 using Matlab.
6. What is the attenuation of the filter per decade in the transition band (that is the slope in
log-log scale, 20log10|H(jw)| versus log10w)?
7. Set up the function generator to produce a square wave with a frequencies of 100Hz, 2.0kHz,
10kHz. Measure the output signal and make a sketch in you solution sheet. Explain the
result in terms of frequency content.
8. If your digital storage oscilloscope is capable of taking FFT (Fast Fourier Transforms), then
take the FFT of both the input signal and output signal. Interpert the results. From the
FFT of input and output signals, obtain the experimental transfer function of the low pass
filter circuit in frequency domain. Interpert the freqnecy response (the transfer function in
freqeuncy domain, that this the ratio of FFT of output signal to the FFT of the input signal)
compared to analytical transfer function evaluated as function of frequency (eqns. 1.17 and
1.19).
38
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.6 Experiment 4:
9. Discuss how you could take the FFT of the input and output signals using the PIC microcontroller. Use ADC channels 0 and 1 for input and output signals. What is the limitation
in microcontroller (hint: available RAM memory).
Figure 1.20: Picture of the experiment for a 1st order active low-pass filter: circuit on breadboard
and the oscilloscope.
39
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.6 Experiment 4:
Laboratory Experiments
Figure 1.21: Picture of the circuit of a 1st order active low-pass filter on the solderless breadboard.
40
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.7
1.7 Experiment 5:
Experiment 5:
LED Control Using the PIC Microcontroller
Objectives
1. Learn to use the integrated development enviroment (IDE) software and PIC microcontroller
development board.
2. Learn the basic hardware and software features of PIC 18F452, and software control a digital
I/O channel.
3. Learn basic hardware interface between a microcontroller, digital output devices (LEDs in
this case) and digital input devices (DIP switches in this case).
4. To drive LED’s under software control by using digital output pins of an I/O port of the
PIC18F452 microcontroller.
5. To change the status of LED’s under software control based on external digital inputs to the
PIC.
Components
Item
LED
100 Ω resistors
DIP Switch
PIC demo board/connector
Quantity
4
12
1
1 set
Part No.
119634
107465
38818
–
Supplier
Jameco Electronics (www.jameco.com)
Microchip Inc. (www.microchip.com)
Theory
The PIC 18F452 microcontroller has five input-output ports, labeled PORTA, PORTB, PORTC,
PORTD and PORTE. These are used to interact with the world outside, consisting of various
sensors, actuators and transduction devices. A picture of the experiment is shown in Fig.1.12 and
the interface circuit schematic is shown in Fig.1.13. Of these, Ports A and E are six bit ports, while
B, C and D are eight bit ports. These ports can be configured as input/output through the use of
the TRIS command. The command syntax for output is:
TRISx = 0;
PORTx = <value>;
where x refers to any of the ports A,B,C,D or E.
The syntax for input is:
41
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.7 Experiment 5:
Laboratory Experiments
Figure 1.22: Picture of the complete circuit for LED control via digital output of PIC microcontroller.
42
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.7 Experiment 5:
TRISx = 1;
value = PORTx
Once a particular port is configured as an output, any (binary) data that is sent to the port
is placed on the port pins on the microcontroller chip. When used as an input, any binary signal
value applied to the input ports is written into that port register in the memory.
Application Software Description
The program code for all the experiments is written in C programming language and compiled
with MPLAB C18 C-compiler. The code can be typed in the MPLAB Integrated Development
Environment (IDE) using the built-in editor or in any standard ASCII editor such as Notepad.
The code is them compiled using C-18 compiler in the MPLAB IDE.
The program code must contain at least two sections. Depending on the state of input switches
selected by the user, the program execution is transferred to a particular section, and that section
is executed. Points to be noted are:
1. Include proper header files provided with C-18 compiler,
#include <p18f452.h>
#include <delays.h>
2. Set the correct ports as input and output using the TRISx command. Clear any existing
values on the ports by setting them to zero.
3. If you are using the ’Watch’ option while debugging in MPLAB to keep track of register
values, note that the values are in hexadecimal.
4. As an example, if we wanted to send out a high signal on pins 0 and 5 of Port D, the code is:
TRISD = 0; /* Set Port D as output */
PORTD = 0; /* Clear existing Port D value */
PORTD = 33; /* Decimal equivalent of 00100001 */
/* Value for Port D in the Watch window in MPLAB is 21 (hex
equivalent of 33) */
43
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.7 Experiment 5:
Laboratory Experiments
Procedure
1. Assemble the circuit on the breadboard as shown in the circuit diagram (Fig.1.23). Take care
not to connect the 5V supply until the entire circuit has been assembled.
2. Connect the four LED’s to each of four pins of PORTB of the PIC microcontroller on the
demo board.
3. Connect at least two switches on the 8-pin DIP switch to pins on the PORTC of PIC demo
board.
4. Open MPLAB environment, and load your project.
5. Your code for the project must contain two separate sections as described earlier: setup
section and logic section. The logic implemented between the input DIP switches and output
LEDs is left to the student. One simple logic implementation may be to display the same
state of DIP switches on the LEDs.
44
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.8
1.8 Experiment 6:
Experiment 6:
Schmitt Trigger With Variable Hysteresis using an Op-Amp Circuit
Objectives
1. Understanding the theory of Schmitt trigger and its applications.
2. Circuit design of a variable hysteresis Schmitt trigger circuit using Op-Amp.
3. Getting familiar with standard measurement devices and signal generators. Measuring the
hysteresis band of the Schmitt trigger circuit.
Components
Item
LM358 Op-Amp IC
Potentiometer (2kΩ)
Resistor 4.7kΩ
Resistor 1kΩ
Battery 9V
Breadboard
Set of connection wires
Quantity
1
1
1
1
2
1
1 set
Part No.
23966
41865
107633
29663
198791
276-174
Supplier
Jameco Electronics (www.jameco.com)
Jameco Electronics (www.jameco.com)
www.jameco.com
www.jameco.com
www.jameco.com
Radio Shack (www.radioshack.com)
Jameco Electronics
Theory
Comparator op-amp circuits employing positive feedback are widely known as Schmitt trigger
circuits. The addition of positive feedback results in an effect called hysteresis. Hysteresis is a
phenomenon in which the transition point for the input voltage is different when switching from
the low state to the high state as compared with switching from the high state to the low state.
Said differently, the transition process is direction sensitive. This process advantages are, first,
the possibility of the undesirable state changes due to spurious noise pickup is minimized by employing hysteresis. Second, the switching process can be accentuated by the positive feedback in
the Schmitt trigger. Finally, the hysteresis effect is a desirbale feature in some ON/OFF control
systems.
Consider an inverting Schmitt trigger op-amp Fig.1.24. The voltage at the (+) terminal is same
as the voltage across R2,
v + = VR2 =
R2
R2
· Vo =
· Vsat
R1 + R 2
R1 + R 2
(1.73)
where Vo = Vsat or Vo = −Vsat, VT = VR2. The output of the amplifier is essentially always
saturated depending on the signals on its input terminals (+) and (-).
45
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
100 kOhm
100 Ohm
100 Ohm
100 Ohm
Laboratory Experiments
100 Ohm
1.8 Experiment 6:
Figure 1.23: Circuit diagram for digital I/O: read status of input switches and turn ON/OFF LED
outputs.
46
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.8 Experiment 6:
v+
Vi
+
v+
Rf
D
Vsat
=
Rf
R1
Vsat
R1
R2
VT =
Ri
Vo
_
+
Ri
VT
+
R2
Vsat
R2
vo
vo
VT
B
Vsat
A
C
-VT
A
Vi
Vo
_
VT
-VT
vi
vi
B
D
- Vsat
(a)
- Vsat
C
(b)
Figure 1.24: Schmitt Trigger: a) non-inverting, and b) inverting configuration, ON/OFF output
with hysteresis function.
Let us trace the operation on the op-amp along the input-output relationship curve that has
the hysteresis loop. Assume that initially we start on the curve from the left hand side,
Vo = Vsat
, v + = VR2
, vi < 0
(1.74)
For the op-amp output to change state, Vo = −Vsat (move to the C part of the curve), the inverting
input (v − ) must slightly exceed non-inverting input (v + ), (vi = v − ) > (v + = VR2). In other words,
we move along B on the input-output curve, neglecting the transient response details of the change
in the output state of op-amp. In order to return to the previous state, now the inverting input must
be slightly more negative than the noinverting input which is at the value of −VR2, (vi = v − ) <
(v + = −VR2 ). Then, the state of the op-amp output switched back to ON (D line along the
hysteresis loop). The non-inverting Schmitt trigger circuit works with the same principle except
the output polarity is different, where,
VT =
Ri
· Vsat
Rf
(1.75)
47
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.8 Experiment 6:
Laboratory Experiments
Procedure
1. Design a non-inverting Schmitt trigger circuit in Fig.1.25 with hysteresis voltage VT varies
from 0.25 to 0.6 Vsat.
2. Assemble the circuit on the breadboard as shown in the circuit diagram. Take care not to
connect the 9V batteries until the entire circuit has been assembled (Fig.1.26, 1.27).
3. Set up the function generator to produce a saw tooth wave with an amplitude of 6V.
4. Connect the oscilloscope to the input and output of the non-inverting Schmitt trigger circuit.
Measure the output voltage.
5. Sketch the input and output voltage signals. Verify the hysteresis effect between the input
and output voltages.
6. Vary Ri value on the circuit and confirm its effect of the hysteresis band.
+9v
-
vo
+
-9v
vi
Ri
Rf
Figure 1.25: Non-inverting Schmitt trigger circuit.
48
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.8 Experiment 6:
Figure 1.26: Non-inverting Schmitt trigger lab setup.
49
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.8 Experiment 6:
Laboratory Experiments
Figure 1.27: Picture of a non-inverting Schmitt trigger circuit built on a breadborad.
50
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.9
1.9 Experiment 7:
Experiment 7:
Analog PID Control Using Op-Amps
Objectives
1. Understanding the theory of differential, summing, inverting, derivative, and integrator Opamps.
2. Build up a complete analog PID control circuit.
3. Test the input-output signal relation of a PID circuit (i.e. P-only, D only, I only, PD, PI,
PID versions of the circuit).
Components
Item
LM358 Op-Amp IC
Resistor 1kΩ
Resistor 4.7kΩ
Resistor 100kΩ
Resistor 470Ω
Capacitor 0.22 µF
Battary 9V
Breadboard
Set of connection wires
Quantity
3
8
4
4
1
2
2
1
1 set
Part No.
23966
29663
107633
29997
107537
25540
198791
276-174
Supplier
Jameco Electronics (www.jameco.com)
Jameco Electronics (www.jameco.com)
www.jameco.com
www.jameco.com
www.jameco.com
www.jameco.com
www.jameco.com
Radio Shack (www.radioshack.com)
Jameco Electronics
Theory
Inverting Op-Amp
The functionality is to amplify the input voltage to output voltage with a negative gain. Neglecting
the transient delay of response between input and output voltages,
Vo (t) = KCL · Vi (t)
(1.76)
Inverting op-amp (Fig.1.28) connects the (+) input terminal to ground, and input signal is connected to the (-) input terminal. There are two resistors around the op-amp: Ri and Rf . Let us
show the relationship between Vi and Vo using the ideal op-amp assumptions. Recall that ideal
op-amp assumptions state, i+ = i− = 0, Ed = v + − v − = 0, if = iin .
51
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.9 Experiment 7:
Laboratory Experiments
v+ = v− = 0
(1.77)
iin = Vi /Ri
(1.78)
if
= iin
(1.79)
Vf
= Rf · if = Rf · Vi /Ri
(1.80)
Hence, since the output voltage will have opposite polarity to Vf ,
Vo = −Vf = −
Rf
· Vi
Ri
Vo = KCL · Vi
(1.81)
(1.82)
where the gain of the invering op-amp
KCL = −
Rf
Ri
(1.83)
Non-inverting Op-Amp:
Non-inverting amplifier simply amplifies an input voltage to output voltage with a positive gain.
This is accomplished by the feedback connections shown in Fig.1.28b. Following the same ideal
op-amp assumptions (v+ = v − , i+ = i− = 0), the input-output relationship (neglecting transient
response differences) can be derived as follows,
v + = v − = Vi
(1.84)
iin = Vi/Ri
(1.85)
if
(1.86)
= iin
V0 = (Ri + Rf ) · if
(1.87)
Since this is a non-inverting amplifier,
R i + Rf
· Vi
Ri
= KCL · Vi
Vo =
(1.88)
(1.89)
where the gain of the non-inverting op-amp is
KCL = 1 +
Rf
Ri
(1.90)
which is always larger than one.
52
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.9 Experiment 7:
R
V
i
R
R
f
R
i
i
V
_
VO
V
i
+
æR
= -çç
èR
f
V
_
o
+
v
f
ö
÷V
÷
ø
VO
=
o
+
(1
+
i
i
(a)
Rf
Ri
) Vi
(b)
Figure 1.28: Basic op-amps with negative feedback: a) inverting op-amp, b) non-inverting op-amp.
Differential Input Op-Amp
The desired function is to determine the difference between two signals and possibly multiply the
difference with a gain,
Vo = K · (V1 − V2)
(1.91)
which is used in closed loop control circuits as the summing junctions, i.e. find the difference
between a command signal and sensor signal. (Fig.1.29a) shows a differential input op-amp circuit.
In its general form, the input-output relationship can be obtained using the superposition principle.
The output is sum of the outputs due to the inverting input and the non-inverting input. The output
due to input at its non-inverting terminal is
v+ =
0
vo =
=
R2
V1
R1 + R 2
R 3 + R4 +
v
R3
R3 + R4 R2
· V1
R3 R1 + R 2
(1.92)
(1.93)
(1.94)
And the output due to input at its inverting terminal is
00
vo = −
R4
· V2
R3
(1.95)
The total output is
00
Vo = vo0 + vo
R2
R3 + R4
R4
Vo = (
)(
) · V1 − ( ) · V2
R1 + R 2
R3
R3
(1.96)
(1.97)
53
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.9 Experiment 7:
Laboratory Experiments
Derivation of this relationship follows the same procedure as the previous op-amp circuits making
use of the ideal op-amp assumptions. The superposition principle can be used in the derivation:
0
i) connect V2 to ground and solve for vo = K1 · V1, and ii) connect V1 to ground and solve for
00
0
00
vo = K2 · V2. Then, add them together to get Vo = vo + vo . Note that when R1 = R2 = R3 = R4,
the input-output relationship os
Vo = V1 − V2
(1.98)
Similarly, when R1 = R3 = R and R2 = R4 = K · R,
Vo = K · (V1 − V2)
(1.99)
One of the main usage of differential op-amps is in amplifying noise sensitive signals. Singleended signals are referenced with respect to ground. Any noise induced on the signal wire coming
into the om-amp would be amplified. This is particularly problem when the noise signal is comprable
to the actual signal magnitude. In such cases, it is best to transmit the signal voltage in differentialended format. That is using two wires and the signal information is the voltage difference between
the two wires. If any noise is induced during the transmission, it would be induced on both lines and
the difference between them would still be unaffected by noise. Amplification of differential-ended
signals is one of the most common application of differential op-amps.
Derivative Op-Amp
The desired function is to take the derivative of the input voltage signal and provide that as output
voltage signal,
d
Vo (t) = K (Vi(t))
(1.100)
dt
Figure 1.29 shows an op-amp circuit for differentiation. Using the ideal op-amp assumptions, the
input-output relationship is derived as follows,
iin = C ·
dVi(t)
dt
(1.101)
if
= iin
(1.102)
Vf
= R · if
(1.103)
Vo = −Vf
(1.104)
Hence,
Vo = (−R C) ·
dVi(t)
dt
(1.105)
54
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.9 Experiment 7:
R
C
Figure 1.29: Some op-amp circuits: differential input amplifier, differentiator, integrator.
55
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.9 Experiment 7:
Laboratory Experiments
Integrating Op-Amp
If we change the locations of the resistor and capacitor in the derivative op-amp, we obtain an
integrating op-amp circuit (Fig.1.29). The desired function is
Z
Vo (t) = K (Vi (τ )dτ ) + Vo (0)
(1.106)
where Vo (0) is the initial voltage. The derivation of the I/O relationship is straight forward,
iin = Vi(t)/R
(1.107)
if
(1.108)
= iin
Z
t
1
if (τ )dτ
C 0
Vo(t) = −Vf (t)
Z t
1
= −
Vi (τ )dτ
C R 0
Vf (t) =
(1.109)
(1.110)
(1.111)
where the initial voltage values in the integrations have been neglected.
Procedure
1. Assemble the circuit on the breadboard as shown in Fig.1.30. Take care not to connect the
9V batteries until the entire circuit has been assembled. Reference voltage can be grounded
2. Set up the function generator to produce a three different wave forms with an amplitude of
6V.
3. Connect the oscilloscope to the output of the differential op-amp, and sketch the output for
the three wave forms.
4. Connect the oscilloscope to the output of the proportional op-amp, and sketch the output for
the three wave forms.
5. Connect the oscilloscope to the output of the derivative op-amp, and sketch the output for
the three wave forms.
6. Connect the oscilloscope to the output of the integrator op-amp, and sketch the output for
the three wave forms.
7. Connect the oscilloscope to the output of the summing op-amp, sketch the output and compare to the original signal.
8. Calculate the proportional, derivative, and integrator gains.
56
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.10 Experiment 8:
Figure 1.30: Analog PID control circuit.
1.10
Experiment 8:
Force and Strain Measurement Using a Strain Gauge
and PIC-ADC Interface
Objectives
1. Build a complete circuit to interface a strain-gage sensor to the A/D converter of the PIC
microcontroller. This includes building a Wheatstone bridge and operational amplifier to
amplify the voltage output of the Wheatstone bridge, and interface it to one of the ADC
channels of the PIC controller.
57
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.10 Experiment 8:
Laboratory Experiments
Figure 1.31: Analog PID control circuit lab setup.
Figure 1.32: Picture of the analog PID control circuit based on op-amps on a breadboard.
58
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.10 Experiment 8:
2. Develop application software to sample the strain-gauge output voltage using the ADC and
estimate/measure the force and strain due to load applied (Fig.1.33).
Components
Item
Strain gauge G=2, R=120Ω
(and bonding adhesive)
LM358 Op-Amp IC
Potentiometer (200kΩ)
Resistor 120Ω
Resistor 100kΩ
Resistor 100Ω
Breadboard
Set of connection wires
PIC Demo Board/connectors
Quantity
1
Part No.
SG-6/120LY11
2
1
3
1
1
1
1 set
1
120862
181972
30082
107764
30081
276-174
–
Supplier
www.omega.com
Jameco Electronics (www.jameco.com)
www.jameco.com
www.jameco.com
www.jameco.com
Radio Shack (www.radioshack.com)
Jameco Electronics
Microchip Inc.(www.microchip.com)
Theory
Force and Strain Relationship
The strain gauge setup consists of an aluminium beam that is fixed at one end to a frame, and
is free at the other. Picture of the experiment setup is shown in Fig.1.33. A schematic of the
mechanical setup is shown in Figure 1.34.
The aluminum cantilever is loaded by deflecting the free end with the aid of a vertically mounted
screw.
Application of a force F on the tip of a cantilever results in a bending moment M = F l, l
being the distance between the force application point and the center of the measurement point
(the strain-gauge location). This moment is balanced by stress, σ, that cause lengthening and
shortening of fibers of material. The amount of extension is called “strain” and is defined as
= ∆l l . The relation between stress and strain is provided by the constitutive law of the material:
σ = E , here E is the Young’s modulus of the material.
There is a linear relationship between the applied force and the induced strain. For a cantilever
beam with rectangular cross section we have the following relations,
59
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.10 Experiment 8:
Laboratory Experiments
Figure 1.33: Picture of the complete circuit for strain gauge sensor the experiment.
60
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.10 Experiment 8:
σmax =
=
=
=
max =
=
M · (h/2)
I
F · l · (h/2)
(1/12) · b · h3
6·F ·l·h
b · h3
6·F ·l
b · h2
1
σmax
E
6F l
E b h2
(1.112)
(1.113)
(1.114)
(1.115)
(1.116)
(1.117)
where l, b, h are the length, width and thickness of the cantilever beam used in this experiment. I
is the area moment of inertia of the cross section of the beam around the neutral axis of bending,
1
I = 12
· b · h3 .
Equation (1.117) shows that measuring the strain results in an indirect measure of the applied
force, at least at steady state conditions. If we can measure strain, then we can estimate/calculate
force if we have the geometric and material property information of the beam (l, b, h, E).
height: h
width: b
Figure 1.34: Strain gauge sensor experiment.
Strain Gauge
The strain measurement may be performed by strain gauge sensors. These devices are applied on
the test part in such a way that they are subjected to the same strain (deformation) as the test part.
61
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.10 Experiment 8:
Laboratory Experiments
The resistance of the small wires that constitute the strain gauge increases when they lengthen, and
decreases when they shorten. It follows that strain variations results in small resistance variations.
The resistance of a conductor of length L and cross section A is given by:
L
(1.118)
A
where, parameter ρ is the resistivity of the material. Taking the logarithm of equation (1.118) and
differentiating we obtain:
ln R = ln ρ + ln L − ln A
(1.119)
∆R
∆ρ ∆L ∆A
=
+
−
(1.120)
R
ρ
L
A
R=ρ
Assuming that the section of the wire is circular, A = π
D2
4 ,
it follows
∆A
2 ∆D
∆L
=
= −2 ν
(1.121)
A
D
L
In equation (1.121) the coefficient of Poisson ν of the material has been used in order to relate
longitudinal and transverse deformations of the wire.
Substituting equation (1.121) into (1.120) the following is obtained:
∆R
∆L ∆ρ
= (1 + 2ν)
+
R
L
ρ
(1.122)
It is common to define the gauge factor G as:
G =
=
∆R/R
∆ρ/ρ
= (1 + 2ν) +
∆L/L
∆L/L
∆R/R
(1.123)
(1.124)
Then,
∆R
= G
(1.125)
R
Equation (1.123) shows that G depends on a geometric term 1 + 2ν and on a microstructural
∆ρ/ρ
term ∆L/L
that relates the variation of resistivity to deformation. This term characterizes the
piezoresistive behavior of the material.
For some materials (like Constantan) the piezoresistive component is smaller then the geometric
one. The strain gauges obtained from these materials are called “metallic”. They have a relatively
small gauge factor (G = 2 for the ones used here). They are stable under temperature variations
and linear in the operating range.
Other strain gauges, made from different materials (i.e. semiconductors) exhibits gauge factors
in the range of G = 70 to 200. Despite the increased sensitivity, their use is more difficult since
they are non linear and may need temperature compensation. For a given strain-gauge, the gauge
factor G is known. Then, if we can measure the change in resistance (∆R/R), then we can calculate
the strain .
62
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.10 Experiment 8:
R2 =
R1=
Vi
Figure 1.35: Circuit diagram to amplify the voltage output of the strain gauge sensor.
Signal Conditioning
The signal conditioner has to convert the variations of resistance of the sensor into a suitable
electrical voltage signal that is compatible with the PIC microcontroller.
These resistance variations are converted to voltage differential by a Wheatstone bridge. For
the applied circuit, see Fig. 1.35, the output voltage is
Vo =
Vi ∆R
4 Ro
(1.126)
Since V0 is typically in the order of millivolts, an amplification stage has to be provided. An
operational amplifier can be used for this purpose. Resistors R1 (1kΩ) and R2(100kΩ) (see Fig. 1.35)
determine the gain. Here, R1 is a low impedence resistance, while the ratio R2/R1 defines the
amplification gain.
R2
Ka =
(1.127)
R1
The low impedance R1 of the amplification stage will strongly affect the output of the bridge
if it is directly connected to it. In order to avoid this effect, a voltage follower stage is provided
(referred also as voltage buffer stage or impedance isolation buffer).
Application Software Description
The software development task includes setting up the registers to configure the pin connected to
the strain gauge sensor, as the ADC channel to be used. This can be done directly by writing to the
specific registers in C or assembly language or by calling the appropriate C library functions which
hides the details of register configuration. The main purpose is to be able to read and display the
voltage level at the ADC pin of the microcontroller. In this lab, no output operation at the I/O
ports are performed. It is only an analog input experiment. Variations on the software can be made
to handle the ADC conversion process either using polling method (i.e. by repeatedly checking if
the ADC conversion is done) or using interrupt method (i.e. the ADC registers can be setup to
63
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.10 Experiment 8:
Laboratory Experiments
generate interrupt when an ADC conversion is completed). If interrupt method is used, then an
interrupt service routine (ISR) must be written and interrupt conditions must be configured by
setting appropriate register bits.
Relevant header files to be included with C-18 compiler are as follows,
#include
#include
#include
#include
<p18f452.h>
<adc.h>
<timers.h>
<delays.h>
Procedure
1. Assemble the circuit on the breadboard as shown in the circuit diagram. Take care not to
connect the 5V supply until the entire circuit has been assembled.
2. Glue the strain gauge onto the fixture using the strain gauge adhesive provided.
3. Connect the strain gauge outputs to one arm of the Wheatstone bridge setup.
4. Open MPLAB and load your project into the workspace. The source code must contain
commands to configure the analog to digital converter on the PIC, and read input voltage at
the ADC pin to which the sensor signal is connected to.
5. Run the program. Then, deflect the aluminum beam on the strain gauge fixture by lowering
the screw at the tip. Take care not to deflect it by more than a few millimeters (about an
eight of an inch at most).
6. Verify that the ADC now shows a value. Now raise the screw by a few turns. This will reduce
the strain on the beam, Read the value of the ACD again. The value in the ADC should now
have reduced to reflect lower strain value.
7. Repeat the procedure for various deflections of the beam, all the while taking care not to
deflect the beam by more than 2 mm. Record the deflection versus the strain measurements.
Plot the results.
64
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.11
1.11 Experiment 9:
Experiment 9:
DC Solenoid Control Using a Transistor and PIC Microcontroller
Objectives
To control an On/Off DC solenoid using a power transistor and PIC 18F452 microcontroller.
Components
Item
On/Off type DC solenoid
Transistor: IRF511(MOSFET)
Diode
PIC Demo Board/Connectors
Quantity
1
1
1
1 set
Part No.
142463
39C4310
76970
—
Supplier
Jameco Electronics (www.jameco.com)
Newark Electronics (www.newark.com)
Jameco Electronics (www.jameco.com)
Microchip Inc. (www.microchip.com)
Solenoid Specifications
• Type: Pull
• 12V DC
• 0.333A current
• Coil resistance:36Ω
• Power consumption: 4.0W
• Holding Force (lbs:@20 0 C) : 0.63 lb
• Wires (in.): 2.0 in
• Shaft Dia.(in.): 0.150 in
• Weight: 0.04 lbs
Theory
A solenoid is a linear displacement actuator. It has a coil, a plunger, and a core to guide the
electromagnetic field between the coil (stator) and plunger (rotor). When current is applied to
the coil, force is generated in the direction to minimize the magnetic reluctance. The direction of
the current does not effect the direction of the force. The force generated is proportional to the
current and inversely proportional to the square of the air gap between the plunger and stopper.
By design, some solenoids are designed to be operated in ON/OFF mode and some are designed
to be operated in proportional mode. In ON/OFF mode of operation, the plunger is intended to
65
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.11 Experiment 9:
Laboratory Experiments
Figure 1.36: Picture of the complete circuit for the DC solenoid control experiment.
66
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.11 Experiment 9:
take one of two positions (fully OPEN or fully CLOSED) based on the current in its coil. In the
proportional mode of operation, the solenoid can take intermediate positions as function of the coil
current. In this experiment we use a solenoid designed to be operated in ON/OFF mode. With
careful real-time control software, it can still be operated in proportional mode, though this is not
attempted in the experiment. Since we intend to control the solenoid in ON/OFF mode, output
signal from the microcontroller to the transistor, which switches the load current to the solenoid,
can be a digital output signal. If we wanted to control a proportional solenoid, then a PWM output
pin of the PIC should be used to drive the transistor.
Application Software Description
The program code essentially configures the PIC to give out a step signal that varies between high
and low based under software control. The circuit is designed to switch the voltage across the
solenoid during the on period of the cycle. In every cycle, when the voltage is high (5V ) the coil
is energized by the current flowing through it. A magnetic field is produced due to the tendency
of ferromagnetic plunger and coil generated magnetic flux to seek the minimum reluctance point.
This magnetic field pulls the plunger in towards the stopper. When the voltage is low (0V ) for
the remainder of the cycle the base current of the transistor falls below a minimum value and it
stops transmitting current to the solenoid. As a result the magnetic field collapses and the plunger
is released. A protection diode is connected in parallel to the solenoid. The header files of interest
to be included in the code are as follows,
#include
#include
#include
#include
<p18f452.h>
<pwm.h>
<timers.h>
<delays.h>
Procedure
1. Assemble the circuit as shown in the circuit diagram. Take care not to connect the power
supply until the entire circuit has been assembled.
2. Configure the output pin as digital output, and turn ON and OFF the output pin under
software control and verify the solenoid motion and force in response to your software.
3. (Optional) Configure the output pin as PWM output (and rewire the transistor base signal
to one of the PWM pins on the PIC if necessary. Note that RC2 pin can be configured either
as a digital I/O or PWM output). Then decide on the PWM frequency and duty cycle.
4. (Optional) Experiment with different duty cycles and PWM frequencies. Try to feel the
net force generated as function of PWM duty cycle while holding the solenoid at a fixed mid
position. The last two items in this procedure would work better with a proportional solenoid.
67
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.11 Experiment 9:
Laboratory Experiments
12 V
Solenoid
12V DC
PIC18F452
IRF511
Port C,Pin Gate
2
1 kOhm
Figure 1.37: Circuit diagram for the DC solenoid control experiment.
68
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.12
1.12 Experiment 10:
Experiment 10:
Stepper Motor Motion Control Using PIC Microcontroller
Objective
Design a complete system for motion control of a stepper motor using the PIC microcontroller and
a step motor controller IC. Write software to control
1. speed, and
2. direction of speed of a stepping motor.
3. run the motor in full-step mode and half-step mode, based on hardware input signal to the
PIC microcontroller.
Components
Item
UCN 5804 IC
Stepper Motor
Potentiometer (200Ω)
DIP Switch
PIC Demo Board/connectors
Quantity
1
1
1
1
1 set
Part No.
01F1912
151861
181972
38818
–
Supplier
Newark Electronics (www.newark.com)
Jameco Electronics (www.jameco.com)
Microchip Inc. (www.microchip.com)
69
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.12 Experiment 10:
Laboratory Experiments
Figure 1.38: Picture of the complete circuit for the stepper motor control experiment.
Theory
Stepper Motor
A stepper motor rotates one step per change in the energized state of its stator windings. The
stepper motor used in the experiment is a unipolar, 4-phase, 7.5 degrees/step, 5V DC stepper
motor. It is manufactured by Airpax, and supplied by Jameco Electronics.
UCN 5804
The UCN 5804 is a popular stepper motor controller IC. It provides the output signal to control
each of four phases of a stepper motor. The only input given to the UCN 5804 is a pulse signal
with a frequency proportional to the required motor speed. The UCN 5804 also has pins to control
direction and select between full- and half-stepping modes. The datasheet is included.
70
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.12 Experiment 10:
Application Software Description
The stepper motor is driven by the UCN 5804 chip, which in turn is given a step input by the PIC
Microcontroller. A schematic of the arrangement is shown in Figure 1.39.
The code generates a pulse signal of the required frequency using one of the port output pins
of the PIC. This is done by simply raising that particular pin to a high status, waiting a certain
delay time, and then lowering it to low. The basic code layout is given below.
1. Clear selected port values, and configure port to act as output.
2. Raise pin to high. Wait for a specified time (depending on required stepping frequency).
3. Drop pin to low. Wait for a specified time (depending on required stepping frequency).
4. Repeat steps or transfer control to a different section of code.
5. Check the status of the desired direction input set by user, then turn on/off direction signal
to UCN5804 based on the input switch status. Verify that the step motor runs as expected.
Procedure
1. Assemble the circuit as shown in the circuit diagram.
2. Compile and run the code to rotate the stepper with a pre-specified stepping speed.
3. Change the status of the direction input signal to change stepping direction.
4. Change the status of the stepping-mode input signal to switch between full- and half-step
modes.
71
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.12 Experiment 10:
Laboratory Experiments
Figure 1.39: Circuit diagram for the stepper motor control experiment.
72
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.13
1.13 Experiment 11:
Experiment 11:
DC Motor Speed Control Using PWM
Objectives
To control the speed of a DC motor using this PWM signal in conjunction with an H-bridge circuit.
Components
Item
DC Motor
Optoisolator
Potentiometer (200 Ω)
IRF511 (MOSFET)
IRF9520 (MOSFET)
1N4003 Diode
PIC Demo Board/connectors
Quantity
1
1
1
2
2
4
1 set
Part No.
154915
114083
181972
39C4310
07B1521
76970
–
Supplier
Jameco Electronics (www.jameco.com)
Newark Electronics (www.newark.com)
Newark Electronics (www.newark.com)
Jameco Electronics (www.jameco.com)
Microchip Inc. (www.microchip.com)
Motor Specifications
The DC motor specifications are:
• 3VDC
• 5200 rpm no-load speed
• 0.32 A current
• 24 gm-cm stall torque
• 0.37 Amp current
• The maximum power output of the motor is 0.323 Watt.
73
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.13 Experiment 11:
Laboratory Experiments
Figure 1.40: Picture of the complete circuit for the DC motor control experiment.
74
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.13 Experiment 11:
Theory
Pulse Width Modulation
Pulse Width Modulation (PWM) allows control of the average level of a voltage signal without
changing the analog magnitude of the signal. This is accomplished by an generating an on-off
signal of a high frequency, and then varying the percentage of time that the signal is in the ON
state. This is called varying the duty cycle. The average value of the signal is equivalent to an
analog signal, provided that the PWM switching frequency is much higher than the frequency the
electromechanical system can respond. For example, assume that a voltage signal between 2.5V
and 3.0V is required to drive a motor, while the supply voltage is a fixed 5V. The PWM signal
will consist of a voltage that varies at a high frequency (i.e. 1KHz) between 0V and 5V. If, in
every one time period, the voltage level is kept high (5V) for 50% of the period, and low (0V)
for the remaining 50%, then the average voltage seen at the output will be 2.5V. In this case, the
duty cycle is 50%. Similarly, if a high voltage is maintained for 60% of the period, and low for the
remaining 40%, then the average voltage is 0.6 × 5V = 3V.
PWM signals are used to drive a variety of devices, and are very well suited in applications
where noise on an analog signal is a concern. The PWM method of conveying the signal is more
immune to noise. The load current is kept flowing through the circuit even during the off period of
the PWM. Then, the load will only see an average voltage level determined by the duty cycle. Care
must be taken to ensure that PWM frequencies are kept reasonably high compared to the bandwidth
of the control system since a low frequency PWM signal may actually be seen as varying, and not
continuous, voltages, especially for loads with smaller electrical inertia. Typical PWM frequencies
are of the order of a few kHz.
75
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.13 Experiment 11:
Laboratory Experiments
H-Bridge Circuit
The motor is driven using the H-Bridge circuit comprising of two field effect transistor pairs (FET)
IRF9520 and IRF511, four diodes (1N4003) and the motor itself. Each FET pair is build of one
P-channel (IRF9520) and one N-channel (IRF511) transistor. This connection scheme results in
one transistor being conductive while the other one is closed and vice versa. Each PWM channel
is connected to one pair of transistors. The reason for using 2 pairs of transistors is to be able to
run the motor in both directions.
Assuming PWM channel 1 is active while channel 2 is not: As a result, the N-channel transistor
of the left pair (IRF511) will be conductive while its P-channel counterpart (IRF9520) will be
closed. At the same time, the N-channel transistor of the right pair will be closed because the
second PWM channel does not carry a signal. Thus, the right pair P-channel transistor will be
conductive. This results in an electrical current flowing through the motor form the upper right
FET to the lower left FET.
Assuming PWM channel 2 is active while channel 1 is not: The switching pattern will be opposite to the above case. Thus, the left P-channel and the right N-channel FETs will be conductive
resulting in the motor running in the other direction.
Application Software Description
The program code essentially configures the PIC to output two PWM signals of the required
frequency and duty cycle. These are controlled by the CCP1RL and CCP1CON registers for PWM
pin 1, and CCP2RL and CCP2CON registers for PWM pin 2. PWM pin 1 (RC2) controls the
current in one direction, while PWM pin 2 (RC1) controls the current in the opposite direction.
By choosing to turn on which one of the PWM outputs, we control the direction of current, hence
the direction of the torque generated by the motor. By controlling the magnitude of the current in
the PWM pin, we control the magnitude of the current, hence the magnitude of the torque.
The circuit is designed to vary the voltage across the motor inversely to the PWM signal, i.e. as
the PWM voltage level increases, the voltage across the motor decreases. It is possible to entirely
stop the motor by raising the PWM signal to a level that is high enough.
76
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.13 Experiment 11:
Procedure
1. Assemble the circuit as shown in the circuit diagram. Take care not to connect the 5V supply
until the entire circuit is assembled. To be safer, connect the 5V supply to the motor via a
switch.
2. Calculate the values of the PWM frequency and duty cycle, and implement the code for these
values.
3. Close the switch, and run the program. The motor speed will change based on the duty cycle.
4. Vary the duty cycle value in the code gradually to force the motor to correspondingly increase
or decrease its speed.
5. Change the direction and magnitude of the speed under software control.
77
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
IN4003
IN4003
IN4003
Laboratory Experiments
IN4003
1.13 Experiment 11:
Figure 1.41: Circuit diagram for DC motor speed control experiment.
78
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.14
1.14 Experiment 12:
Experiment 12:
Closed Loop DC Motor Position Control
Objectives
To control the position of a DC motor using a position feedback sensor and PWM output signal in
conjunction with an H-bridge circuit.
Components
Item
DC Motor
Optoisolator
Potentiometer (200 Ω)
IRF511 (MOSFET)
IRF9520 (MOSFET)
1N4003 Diode
Opto-interrupter
Disk with holes
PIC Demo Board/connectors
Quantity
1
1
1
2
2
4
2
1
1 set
Part No.
154915
114083
181972
39C4310
07B1521
76970
273560
—
–
Supplier
Jameco Electronics (www.jameco.com)
Newark Electronics (www.newark.com)
Newark Electronics (www.newark.com)
Jameco Electronics (www.jameco.com)
Jameco Electronics (www.jameco.com
A tick paper or plastic disk
Microchip Inc. (www.microchip.com)
79
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
"Home Made" Encoder Disk
E
D
+
+
100 Ohm
100 KOhm
To Microcontroller
2
+5 VDC
+5 VDC
Figure 1.42: A “home-made” incremental encoder to sense the position change of the motor shaft. Two opto-interrupters
and a disk are used to make a simple incremental encoder.
Laboratory Experiments
Opto-interrupters
1.14 Experiment 12:
80
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.14 Experiment 12:
Theory
In this lab we will implement a closed loop position control a DC motor. In order to perform closed
loop position control, we need a position sensor. For the purpose of understanding the incremental
encoder working principles and low cost, we will construct a a very simple “home-made” incremental
encoder. For that we need two things (Fig.1.42):
1. A disk that has evenly spaced hole that will block and pass the light alternately. For our
purposes, we will have 4 or 8 holes on the disk. The higher the number of holes, the better the
position sensor resolution, but more difficult for us to mechanically assemble the experiment.
So, we will experiment with relatively low resolution home-made incremental encoder. This
disc can be made from a thick paper or plastic or glass.
2. Two opto-interruptors. Opto-interruptors are placed over the disk. As disk rotates, the light
path is interrupted by the disk or not interrupted by the holes and solid sections of the disk. If
we use only one opto-interruptor, we can detect the change of position, but we can not detect
the direction of position change, that is we can not detect direction of speed. So, the second
opto-interruptor is used for that purpose. The second opto-interruptor is mechanically placed
at a 900 mechanical phase angle relative to the first opto-interruptor position over the holesolid sections of the disk. If the disk is rotating in clockwise direction (forward), the digital
output signal from opto-interrupter #1 would lead the signal from the opto-interrupter #2 by
900 phase angle. If the disk is rotating in counter clockwise direction (reverse), the opposite
would happen.
We can also implement a timex 4 (X4) resolution improvement in the position measurement
accuracy by noting that fact that the two opto-interruptors are 900 out of phase. At any given
time, by evaluating the state of two opto-interrupters within a cycle, we can determine where the
position is within 1/4 of that cycle (see the textbook on the discussion of incremental encoders for
more details).
Application Software Description
In microcontrollers for motion control applications, there is a dedicated chip to interface to the
encoder and count the position change pulses as well as calculate the speed. However, in the
PIC microcontroller we use, such a circuit is not available. We will implement that functionality
using discrete input lines. We can either connect the two opto-interrupter signals to two digital
inputs and sample them fast enough so that we do not loose any pulse or we can connect them to
hardware interrupt lines (Fig.1.43). In later case, everytime a pulse transition occurs, an interrupt
is generated. At the interrupt service routine, we would determine the direction of the motion and
increment or decrement the position count. In microcontrollers with dedicated incremental encoder
interface (also called quadrature decoder circuit), the microcontroller does not have to service the
interface for each pulse. Rather, at any given time it would read the counter register since the
interface circuit handles the counting process.
81
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.14 Experiment 12:
Laboratory Experiments
Once we know the actual position, we can digitally calculate the actual (estimated) speed of
the shaft. Then, if we have a programmed (desired) position or velocity, then we can determine
the PWM output based on a PID type control algorithm, i.e. PD algorithms
// Assume
//
xd - the desired position variable, programmed.
//
vd - the desired speed variable, programmed.
//
x - the measured position
//
v - calculated speed based on measured position
//
Kp - proportional gain of the PD control algorithm: a constant.
//
Kd - derivative gain of the PD control algorithm: a constant
// The PD closed loop control position control algorithm
PWM_Out = Kp * (xd- x ) + Kd * (v -vd)
// If the objective is only to control speed, but not the position, then the
// PWM output calculation should not be function of position information, i.e.
//
a proportional closed loop speed control algorithm.
PWM_Out = Kd * (v -vd)
82
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
1.14 Experiment 12:
PW M O/P
PO RT C, inP 2
O pto#2 P
I/
PO RT D, iPn 0
PIC 18F
452
PW M O/P
PO RT B, inP 3
Encoder
O pto#1 P
I/
PO RT D, iPn 1
Opto #1 signal
Optointerrupter
circuit
+ 5V
100 Ohm
Opto #2 signal
+ 5V
+ 5V
+ 5V
100 O hm
+
+
+
+
To M icrocontroller
To M icrocontroller
D
D
E
E
100k Ohm
100k O hm
90 degrees phase shift
83
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Figure 1.43: Circuit diagram for DC motor closed loop position control experiment.
Laboratory Experiments
1.14 Experiment 12:
Laboratory Experiments
Procedure
1. Decide on the hardware interface method of the opto-interrupters to the PIC microcontroller.
2. Assemble the circuit. Keep the motor control and PWM circuit as in the previous lab
(Fig.1.44).
3. Implement software to meaure actual position and speed.
4. Program different position and speed control trajectories as function of time in the control
algorithm and test the closed loop position control. For instance, command 1/4 rev rotations
in forward and reverse directions, command slow and fast speeds in forward and reverse
direction. In closed loop position control mode, while holding current position, try to distrub
the rotor position, does the motor react to keep its current position ?
84
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.
Laboratory Experiments
1.14 Experiment 12:
Figure 1.44: Picture of DC motor closed loop position control experiment.
85
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis for testing or instructional purposes only to
students enrolled in courses for which the textbook has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful.