final report, lab 3: embedded systems - sites at penn...
TRANSCRIPT
Final Report, Lab 3: Embedded Systems
Digital Potentiometer Subsystem
EE 300W, Section 2, Professor Tim Wheeler
Nicholas Oppman, Joe Mertz, Chris Polasko, Marlon Gil
1
Table of Contents
Table of Contents………...…………………………………………………………………..…1
Abstract…………………………………………………………………………………………..2
Introduction……………………………………………………………………………………....3
Rationale…………………………………………………………………………………………4
Implementation…………………………………………………………………………………..6
Verification Testing…………………………………………………………………….10
Validation Testing……………………………………………………………………...11
Results from Integrated Systems…………………………………………………....12
Discussion………………………………………………………………………………………14
Conclusion…………………………………………………………………............................16
Appendices……………………………………………………………………………………..17
Appendix A: Financial Statement…………..………………………………………..17
Appendix B: Gantt Chart……………..……………………...………………………..18
Appendix C: Block Diagrams…………………………………………………………19
Appendix D: Black Box Diagnostics………… ……….……………………………..20
Appendix E: mbed code………………………………………………………………..22
2
Abstract:
Team G Money designed and built a sub-system able to modulate an analog
signal sent from the DAC sub-system with amplitude of 3.3V outputting the specific
voltages requested by the user to the black box. The amplifier uses a standard TL074CN
op-amp that features a voltage divider at the non-inverting terminal in addition to a
digital potentiometer as the feedback resistor, providing the variable gains necessary to
achieve all desired outputs. The digital potentiometer’s resistance is controlled by
hexadecimal commands originating from an mbed device and relayed through a
controller area network (CAN). The mbed serves as the primary tool of communication
to other sub-systems, acting as both the interpreter and the controller of our circuit by
understanding commands sent from other sub-systems, and creating the hex
commands to set the digital potentiometer. The mbed is controlled by C++ coding,
adopting a state machine model, each state outputting a pre-determined hex value
required to achieve a specific output value. Our circuit is powered by a +/- 15V source
and the mbed’s built in 5V source.
3
Introduction:
Today technology is constantly evolving, and improving itself with each new
iteration adding everything from features to reduced size. This level of complexity no
longer allows for a single solution, and instead utilizes the idea of embedded systems,
breaking the main function into many tasks each controlled by a smaller more
manageable sub-systems. Our system will help determine the function of a ‘black box’
by converting a digital signal into an analog signal with set amplitude, scaling this output
to a user requested value and outputting to the black box, the resulting waveform being
converted back to digital to be analyzed this is broken down into four sub-systems DAC,
Digital Potentiometer, Keyboard, and ADC. Team G Money is responsible for providing
the gain to the system. Our sub-system must be able to digitally communicate with the
keyboard sub-system, modulate the DAC subsystem’s output amplitude to 0V no DAC
signal, or to either +1, 2, 3, 4, or 5V which is determined by a user requested command
originating from the Keyboard sub-system. Our sub-system must be able to output
these scaled waveforms to the black box with an accuracy of ± 0.1V.
4
Rationale:
To obtain output voltages from an analog input of 3.3V, the core of our sub-
system utilizes one op-amp that will apply a gain to the input depending on resistor
values. An op-amp was chosen over other methods due to our group’s familiarity with
the device, small footprint, and its simplicity to implement. Previous experience with the
device proved to be very cost effective, allowing for quickened design and
implementation processes. Since an op-amp applies a gain to the input our op-amp
utilizes a voltage divider at the input to scale the original input down to a value much
lower than the lowest required output. This low input voltage can then be amplified meet
all required outputs, including values less than 3.3V. Requiring positive output values,
the input is wired to the non-inverting terminal of the op-amp to achieve a positive gain.
To obtain varying output voltages the sub-system utilizes a digital potentiometer
in series with a fixed resistor connected to ground at the inverting terminal of the op-
amp. The fixed resistor is connected to ground, assuring the input voltage to the
inverting terminal equal to the input at the non-inverting terminal allowing for simpler
calculations while the potentiometer allows for varying feedback resistance, and
variable gain. The digital potentiometer was chosen over a manually adjustable
potentiometer due to its ability to adjust its resistance solely on hexadecimal commands
sent from the mbed device.
We implemented a state machine into the mbed using C++ code, in order to
achieve the required output voltages each state corresponds to the specific
hexadecimal command that sets the digital potentiometer to a value that outputs each
required output voltage. The state machine is very practical to the user, providing a
straightforward approach to achieve the desired outputs. C++ offers a simple way to
implement a state machine, over other languages such as labview.This simple
implementation reduced the time spent on design and implementation, leaving more
time for verification testing on both the circuit and system level, improving accuracy, and
the overall quality for the final product.
The mbed was chosen over more complex devices such as the MyDAQ as our
primary means of digital communication due to its functionality and ease to implement.
Compared to the multi functioning MyDAQ , the mbed also functions as a power source
offering both 3.3V and 5V, while being designed to excel at sending and receiving
commands to and from multiple devices, a feature crucial to meet our requirement for
sub-system communication. Offering both sources reduced the number of instruments
needed for testing, powering parts of our circuit and functioning as the 3.3V input.
Moreover costing around $55 it is also far more cost effective when compared to the
MyDAQ costing around $200. Compared to the cost of the other parts and devices used
5
in our implementation, using the mbed significantly reduced our production costs.
Finally a CAN device was implemented as a transfer device that relays the hexadecimal
commands generated by the mbed to the digital potentiometer due to its ability to
transfer data bi-directionally. Communication between sub-systems could also be done
using a similar method, implementing an mbed device in the keyboard sub-system. This
will generate commands, transferred through CAN devices to the other meds found in
each sub-system. Like the mbed in ours these will control the functions of that particular
sub-system. The first command sent from the keyboard sub-system will determine and
establish communication the appropriate sub-system, the following commands will
dictate what actions that subsystem will do. This connection will be cutoff only when a
user inputs the value pertaining to the main menu, this command will restart the
keyboard, such that its next command will determine another sub-system to
communicate with, and also be sent to the receiving sub-system telling it to stay put and
continue its previous function. This allows the user to individually adjust each sub-
system functions to get the outputs they desire.
6
Implementation:
Our sub-system must be able to output a range of required voltages from a fixed
3.3V analog input from the DAC. To scale the input our sub-system utilizes one op-amp,
this will apply a gain to the input and provide various outputs depending on resistor
values. However, the op-amp will only scale the input with a minimum factor of one, to
accommodate our op-amp utilizes a voltage divider at the input to scale the original
input down to a value much lower than the lowest required output which we chose to be
.5V.
Using a simple voltage division equation, the appropriate resistor values are
determined:
𝑉𝑜𝑢𝑡 = 𝑉𝑖𝑛 ∗ (𝑅2/(𝑅1 + 𝑅2))
Setting Vout= .5V, and Vin= 3.3V, we find R2 = 7500 Ω and R1= 42000 Ω
The lower input voltage now allows us to scale the input to all required voltages,
including values less than 3.3V. We are also required to only output positive voltages,
meaning we must have a positive gain, this is achieved by wiring the voltage divided
input to the non-inverting terminal of the op-amp, creating a simple non-inverting op-
amp.
To vary the output voltages the sub-system features a digital potentiometer in
series with a fixed resistor connected to ground at the inverting terminal of the op-amp.
The digital potentiometer offers a varying feedback resistance, and thus has the ability
to produce a variable gain. The fixed resistor is connected to ground, to assure the input
voltage to the inverting terminal equal to the input at the non-inverting terminal making
calculations simpler.
The fixed resistance value was determined by solving the inverting op-amp gain
equation:
0 = ((𝑉𝑖𝑛(−𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙))/𝑅3) + ((𝑉𝑖𝑛(−𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙) − 𝑉𝑜𝑢𝑡)/𝑅𝑝𝑜𝑡)
When the potentiometer is maxed we will obtain the largest gain. The maximum
resistance for the digital potentiometer was determined by using a DMM, and found to
be 44694 Ω . So plugging in the related values Vin=.5V, Vout= 5V, and Rpot= 44694 Ω.
We calculate the fixed resistance to be R3= 4966 Ω.
7
To find the required potentiometer resistances that will achieve the other required
output voltages, we plug in the input voltage, fixed resistance and desired output
voltages and resolve the previous equation for Rpot. Which we found to be:
Rpot resistance (Ω) Vout (V)
4966 Ω 1 V
14898 Ω 2 V
24830 Ω 3 V
34762 Ω 4 V
44694 Ω 5 V
Table 1: Rpot resistance for various outputs
Setting the digital potentiometer’s wiper to achieve these values is accomplished
by sending a hexadecimal value to the potentiometer. These values were determined by
using the positioning equation given on the potentiometer datasheet:
Figure 1:Wiper Position Calculation
Our circuit connects PB directly to ground, knowing this we only needed to use
the second equation for Rwb. Plugging in the max resistance Rab, appropriate
constants, and the different values of Rpot, we solved for the appropriate hex value Dn
required for each case which we found to be:
Required Voltage Corresponding Hex Value
8
1V 0xF6
2V 0xC4
3V 0x8C
4V 0x55
5V 0x1C
Table 2: Required hex value to position wiper
The hexadecimal command is generated by an LPC1768 mbed microcontroller.
Code is written to the microcontroller that designates where to position the wiper on the
digital potentiometer.
The code allows communication between the CAN bus, the mbed, and the digital
potentiometer. Information sent from the keypad is received through the CAN bus and
the code that is compiled on the mbed microcontroller will interpret the information
received. The data received from the CAN bus has a specific identification number that
designates which portion of the system it is trying to communicate with. The designation
for our portion of the embedded system was the number 2. It also has a number that will
designate which value of gain to apply if the keypad is communicating with our circuit.
The following excerpts from our code will interpret this received data:
CANMessage msg;
This establishes a variable “msg” that the code will recognize as the data
received on the CAN bus.
if(can1.read(msg)&&(msg.id==2))
This if statement will check if there is a message received on the CAN bus and
also if that message contains the identification number, 2, meaning the keypad is
communicating with our circuit.
If both of these statements are true then the code within the if statement will
execute. Contained in this code is the case structure that allows the value of the digital
potentiometer to be changed by the keypad.The keypad will send data to the CAN bus
that will designate which case to execute. Each case sets the wiper of the potentiometer
at a different position changing the feedback resistance and in turn, the gain. This
portion of code is as follows:
9
switch (*msg.data)
// cases for voltage that the subsystem outputs
case '1':
cs = 0; - Select the digital potentiometer chip
spi.write(0x13); - Write to the command bit of the potentiometer chip
spi.write(0x1C); - Position the wiper of the potentiometer
cs = 1; - Deselect the potentiometer chip
break; - Exit the case structure
The “*msg.data” is the portion of data received on the CAN bus that designates
which case to execute. Within each case there is a line to select the digital
potentiometer chip, a line to write to the command bit, and a line to implement each
change in potentiometer resistance value. The line writing to the command bit is telling
the digital potentiometer to implement the change in wiper position on the chip. Then
the calculated hex value for the specific wiper position is written to the chip for each
case. After the wiper position is set, the chip is then deselected and the switch
statement ends.
10
Verification Testing:
Figure 2: Schematic of System
In order to test our circuit design we used the 3.3V output from the mbed
microcontroller to simulate the input voltage received from the digital to analog
converter. We also powered our operational amplifier with +/- 15V. The results from the
initial testing are shown in Figure below. Once the resistance value for each gain was
calculated and the corresponding wiper position value was found we tested our circuit.
We implemented the value onto the digital potentiometer chip and measured the value
of resistance being executed. After some minor circuit debugging we were able to
obtain each desired resistance value across the digital potentiometer. We then tested
the gain. The case structure was coded onto the microcontroller and we integrated our
circuit with the keypad in order to test the code. The keypad sent commands to our
circuit to change the gain from the input signal of 3.3V to values of 1,2,3,4, or 5V. Each
case was executed and the actual values were recorded and are shown in the chart
below. The values obtained from testing passed the verification test because each value
was within 0.1V of the desired value. This testing verified that our implementation of the
circuit design and code, was now ready to be integrated into the entire system.
Table 3: Testing Results
11
Validation Testing:
The gain circuit was integrated into the system and we began testing. The results
obtained from these tests almost exactly matched our subsystem testing results and
each value was within 2% error of the required value.
Required Voltage Actual Voltage Percent Error
1V 0.98V 2.00%
2V 1.99V 0.50%
3V 2.96V 1.30%
4V 3.97V 0.75%
5V 5.00V 0.00%
Table 4: Accuracy and Percent Error Calculations
The gain portion accurately amplified the square or sine wave that was received
from the digital to analog converter. Our team did many different testing runs, producing
sine and square waves of different frequencies and amplitude. Before running these
signals through the black box to obtain the transfer function, we used an oscilloscope to
view the signals generated by our system. After analyzing the resultant signals on the
oscilloscope we deduced that each portion of the system was functioning properly.We
could change shape, frequency, and amplitude and each change was measured
accurately using the oscilloscope. The accuracy of these produced signals is extremely
important because then our results obtained from the output of the black box will be
more accurate and easier to quantify as a transfer function. After testing the entire
integrated system and analyzing the results, our design was validated.
12
Results from Integrated System:
Appendix D shows graphs made using the data that was imported to Excel after
being recorded in the ADC subsystem. This data was recorded after running the
system for inputs that the black box could receive. We made several observations after
analyzing the graph in Figures. From the graph, we concluded that the output does not
depend on frequency as changing it from 1Hz to 10Hz does not show a shift in phase or
a change in amplitude from the graphs in Appendix D. When changing the voltage of
the input, the output also change when it is the same type of wave and frequency. We
were able to determine a transfer function after seeing how much the output change by
observing that the output was inverted from the input and the peak to peak voltage also
decreased. We observed that the output’s max was one and that the output was the
input multiplied by a gain that was less than one. After analyzing the gain of the
maximum value of the input and the minimum value of the output for each wave from
the data that was imported from the ADC subsystem, we concluded that the gain was
−1
8. From the previous observations, we concluded that the black box had the following
transfer function:
𝑉𝑜 = 1 −1
8∗ 𝑉𝑖𝑛
Where𝑉𝑜is the output of the black box, and 𝑉𝑖𝑛is the input to the black box.
In order to get this transfer function, the team realized that the black box needs to
be a Differential Amplifier, similar to the one shown in Figure 3. By applying the
following equation:
𝑉𝑜 = 𝑉2 ∗ (𝑅𝑔
𝑅2+𝑅𝑔) ∗ (
𝑅1+𝑅𝑓
𝑅1) − 𝑉1 ∗ (𝑅𝑓/𝑅1)
By setting𝑅𝑓
𝑅1=
1
8 and, 𝑉2 ∗ (
𝑅𝑔
𝑅2+𝑅𝑔) ∗ (
𝑅1+𝑅𝑓
𝑅1) = 1, 𝑉1= 𝑉𝑖𝑛 and 𝑉2 = 15 V, the transfer
function above is realized. 15 V is what powers the black box so having a gain of 1
15gives the 1V. These gains are then achieved implementing the appropriate resistor
resistance values in the gain formula for an op-amp.
13
Figure 3: Differential Amplifier
http://en.wikipedia.org/wiki/Differential_amplifier
14
Discussion:
In our approach to building the module our design was effective, not only meeting
all requirements, but utilizing very few parts: one CAN, an op-amp, one digital
potentiometer, and a single mbed device. Not only was our design able to keep the
integrity of the product by meeting all requirements, the minimum of parts allowed for
simpler design and implementation. Cutting the costs of the overall project by reducing
the number of materials needed and reducing the to work hours to design and produce.
The approach to building the DigiPot circuit was also effective. Using the digital
potentiometer as the feedback resistor on the op-amp design proved to be functional
applying all gains necessary to output the required voltages. The simplicity of our design
reduced breadboard clutter allowing for easier debugging, this also makes the core of
our sub-system easy to replicate and thus reducing costs to produce.
Our method to communication from sub-system to the other subsystems was
also effective. Having each sub-system have its own mbed to generate commands
allowed each sub-system to take only the specific commands from its mbed. Reducing
the probability of one sub-system taking multiple commands at once and
malfunctioning. The CAN devices were also an effective method to transfer commands
from within and between sub-systems, sending commands from the keyboard sub-
system to accurately establish communication with one of the various sub-systems, and
sending commands which allow each sub-system to function correctly. The wire
connections and connections between the input and outputs were also straight forward
and effective to establish, it only required us to connect our operational amplifier to a
power supply that supplied 15V and -15V, the CAN transceiver to the other subsystem's
transceivers, the input from the DAQ subsystem and output the signal to the black box
to our subsystem. This simplicity also allowed for simpler debugging. We also chose to
share a common ground which reduced the noise between sub-systems giving better
accuracy in results The mbed and DigiPot were effective because the code that
controlled the subsystem and was easy to modify, requiring only to change a few lines
of code. However, our method of debugging was not effective, despite the simplicity of
our circuit, we spent two lab sessions debugging the DigiPot attempting to move the
circuit to another spot on the breadboard, rewiring the circuit, and changing different
parts of the code. During those two sessions, our output voltage of the subsystem was
not changing when changing the resistance value in the code. We ultimately overcame
this obstacle, by realizing the op-amp was not powered by the correct voltages and
changing the voltage powering the operational amplifier to these values, we also added
a while loop in the code to have our circuit continue to function even without constant
input. The CAN bus was useful as a means to communicate with our subsystem
because the code for the microcontroller only required to add two lines of code in order
15
for the CAN bus to communicate with our mbed. SPI is an alternate method to using
the CAN bus but would have not have been as appropriate since the keyboard only
need to communicate with one subsystem at a time and SPI is more suited to
communicating with multiple subsystems at once.
During the integration of our design, we made two modifications to our code. On
Table 1, there is a column for the adjusted Rpot values determined through testing.
Testing the code, we found that changing the hex value of the D value for the DigiPot by
one (hex) would change the output voltage by a value .02 V and adjustments to the hex
found on Table 2. This slight modification to the hex value, generated all required output
voltages to within +/- .05 V, providing better accuracy than what was required. The other
change we made after testing our subsystem with the keyboard subsystem. The
keyboard subsystem used “9” to go back to the menu in their subsystem. After testing,
our subsystem would not remember the value that the keyboard gave it. This was
because when or subsystem received a value that was not “1” through “5” it would go to
a default value. In order to fix this, we added a while case in the code, shown in
Appendix E, so that when “9” was pressed, it would remember the value and not
change its function.
In this lab, we had a problem involving all team members. Due to being limited to
one computer and workspace. This hindered progress, and limited our work efficiency.
To fix this issue for future labs, we will take time at the beginning to organize an attack
strategy and plan our task and resources, such that every member has a task and
always has something to do. For example some tasks including updating code could be
done outside the lab, leaving the computer free for more testing and research. We will
also have more open communications with the other teams, this will allow us to track
each other’s progress and plan accordingly. It also opens opportunity for more
debugging ideas and can help our efficiency. Although there are some tasks that only
our team could do, it would be beneficial to all of our teams in our system if we were
able to coordinate how our systems would communicate and how to design our
subsystem to better integrate with the other subsystems.
16
Conclusion
Our team, G Money, has created a subsystem modulates a given signal,
receives commands from the keyboard, and outputs the waveform to the black box.
Using the CAN bus and the mbed microcontroller, our subsystem is able to read the
command sent by the keyboard and modulate the signal created by the DAQ using the
non-inverting amplifier made using the DigiPot and the operational amplifier. Our
subsystem is able to modulate the amplitude of the signal to 1, 2, 3, 4, or 5V with an
accuracy 0.1V depending on the command and output it to the black box. In
conjunction with the other teams in our system, our subsystem was integrated with the
other subsystems in order to find the transfer function of the black box. The transfer
function was found after analyzing and comparing the output of the black box to the
input. To improve our subsystem for future work, we could design it so that it does not
output a signal if it has not received a command or if the the keyboard sends a
command to the the ADC subsystem to stop sampling to reduce power consumption
when the system is not gathering data.
17
Appendices:
Appendix A: Financial Statement (Bill of Materials):
18
Appendix B: Gantt Chart:
19
Appendix C: Block Diagrams:
Figure 4: Block Diagram of entire system
Figure 5: Block Diagram of DigiPot Subsystem.
20
Appendix D: Black Box Diagnostics:
Figure 6: 1Hz Sine wave at 4Vpp
Figure 7:1Hz Square wave at 3Vpp
Figure 8:10Hz Sine wave at 5Vpp
21
Figure 9:10Hz Square wave at 2Vpp
22
Appendix E: mbed code:
#include "mbed.h"
SPI spi(p11, p12, p13); // mosi, miso, sclk
DigitalOut cs(p14);
CAN can1(p30, p29);
int main()
// Chip must be deselected
cs = 1;
// Setup the spi for 8 bit data, high steady state clock,
// second edge capture, with a 1MHz clock rate
spi.format(8,3);
spi.frequency(1000000);
CANMessage msg;
while(1)
if(can1.read(msg)&&(msg.id==2))
switch (*msg.data)
// cases for voltage that the subsystem outputs
case '1':
cs = 0;
spi.write(0x13);
spi.write(0x1C);
cs = 1;
break;
case '2':
cs = 0 ;
spi.write(0x13);
spi.write(0x55);
cs = 1;
break;
case '3':
cs = 0;
spi.write(0x13);
spi.write(0x8C);
cs = 1;
23
break;
case '4':
cs = 0 ;
spi.write(0x13);
spi.write(0xC4);
cs = 1;
break;
case '5':
cs = 0 ;
spi.write(0x13);
spi.write(0xF6);
cs = 1;
break;
// needed to keep value after keypad moves to ADC subsystem
case '9':
break;
default:
cs = 0 ;
spi.write(0x13);
spi.write(0x00);
cs = 1;
break;