Digital-to-Analog Converter Subsystem: Team Johnny Bravo
Digital-to-Analog Converter Subsystem: Team Johnny Bravo
Converter subsystem
T e a m me mb e r s :
De n g f e n g L i
Er i c Hi l l
Go n g h a o Su n
2 0 1 4 / 5 / 3
Team Johnny Bravo
1
Table of Contents
ABSTRACT: ............................................................................................................................................... 2
INTRODUCTION: ...................................................................................................................................... 2
RATIONALE: ............................................................................................................................................. 2
IMPLEMENTATION ................................................................................................................................... 3
CODE AND CIRCUITRY ........................................................................................................................................... 3
1. Main Function ...................................................................................................................................... 3
2. DAC Function ........................................................................................................................................ 4
3. Log function .......................................................................................................................................... 5
BLOCK DIAGRAM ................................................................................................................................................. 6
FLOW CHART ....................................................................................................................................................... 6
VERIFICATION TESTING .......................................................................................................................................... 7
1. Description (and sketch) of sensor and relation to overall system ...................................................... 7
2. Module and interface schematics (complete with mbed) .................................................................... 8
3. Method of testing and verification of requirements ............................................................................ 8
4. Testing results (plots, tables, etc.) ........................................................................................................ 9
5. Percentage Error Analysis .................................................................................................................. 11
VALIDATION TESTING .......................................................................................................................................... 11
RESULTS FROM INTEGRATED SYSTEM ..................................................................................................................... 11
DISCUSSION ........................................................................................................................................... 12
VALUE STATEMENT ................................................................................................................................ 14
CONCLUSION ......................................................................................................................................... 14
APPENDIX .............................................................................................................................................. 14
2
Abstract:
A diagnostic suite was designed using 4 mbed controllers and related circuitry to analyze the
input-output response of a black box circuit. This suite consists of a DAC subsystem, digital
potentiometer subsystem, ADC subsystem, and keypad subsystem. The keypad is the control
subsystem that communicates to the others through a common CAN bus. Team Johnny Bravo was
responsible for the DAC subsystem, which outputs sine and square waves with an amplitude of 3.3 v,
with frequency of either 1 or 10 Hz, all controlled by the keypad subsystem through the CAN bus.
Introduction:
In this lab, a system of systems was created using 4 mbed controllers and accessory circuits that
control the input and characterize the output of a black box circuit. The subsystems for the
diagnostic suite consist of a DAC, digital potentiometer, ADC, and keypad control. The DAC is to
put out a sine wave or square wave with a frequency of either 1 Hz or 10 Hz, at 3.3 V, the digipot
then shifts the amplitude of this wave to levels of 1, 2, 3, 4, or 5 v. This signal is then input into the
black box circuit, and the resulting waveform outputted is written to a CRV file on a computer for
characterizing. The DAC subsystems importance in this system is to create a waveform of
appropriate shape and frequency which is then used to excite the black box circuit, so that it
generates an output that can be characterized.
In order to accomplish these criteria, our group created code for the mbed controller that outputs the
appropriate waveform depending commands addressed to it through the CAN bus. The output waves
themselves are selected using a switch-case structure, the case that is selected depending on the input
commands.
Rationale:
The DAC that team Johnny Bravo was charged with building is essentially a digital signal
generator with settings that can be controlled by the user through a central keypad attached to a CAN
bus. Per the design requirements for the lab, this DAC signal generator was required to output a sine
wave and a square wave, each with selectable frequencies of 1 Hz or 10 Hz. These analog
waveforms would then be scaled by a digipot module, and then fed into the circuit of interest to see
how the circuit would respond.
In order for our module to receive commands for the central keypad module, it needed to be hooked
up to some kind of common data bus. The data bus protocol specified for this lab was CAN
3
(Controller Area Network). CAN allows multiple independent microcontrollers, such as mbeds, to
communicate to each other asynchronously, which makes integrating subsystems into a larger system
easier. In order to prevent messages from colliding with each other on the CAN network, CAN
implements a sort of bit dominance, in which the logic 0 is the dominant bit and logic 1 is the
recessive bit. When two nodes start transmitting CAN messages at the same time, the node with the
more dominant (i.e. numerically smaller) ID will override the other nodes message.
Implementation
Code and Circuitry
For the code of DAC subsystem, there are 3 main parts including the main function, DAC
generate function, and log function.
1. Main Function
Figure 1: Main Function Code
The main function code is showed in Figure 1 above. We can receive a 3-byte code sent by the
keypad to control the switch, wave form, and frequency of our module via the CAN bus. The
4
keyboard subsystem first sends an ID number to the CAN bus. This ID number is then compared
with our group ID of 2, and if it matches only then is the CAN message data read and acted upon.
In the case of our module, the first three characters after the message ID controlled the setting.
The protocol for this is listed below in figure 2.
Value
Byte
0 1
msg.data[0] Switch OFF Switch On
msg.data[1] Square wave Sine Wave
msg.data[2] 10 Hz 1 Hz
Figure 2: protocol
2. DAC Function
Figure 3: DAC function code
In order to generate two waveforms at different frequency, our group used a while loop to
generate the required waveforms in real-time in unison with a microsecond counter. We set the
frequency by changing the time period of the waveforms. The time period would be 0.1 second
for the frequency of 10 Hz while the time period would be 1 second for the frequency of 10 Hz.
Our group used the following methods to generate the sinusoid waves and square waves.
5
For the square wave, the voltage changed every half time period. To accomplish this, we used the
modulus operator to calculate the remainder and determine how far into a cycle the loop was.
The time unit is set in microsecond since we are looking for the most accurate waveform after the
delay. When the frequency is set at 1 Hz, the voltage is equal to 3.3 volts if the reminder is less or
equal to the 0.5 seconds. We can also regard it as the first half part of one time period. The
voltage is equal to 0 volts when the remainder is greater than the 0.5 second. The principle also
works when the frequency is set at 10 Hz, but instead we need to compare the value with 0.05
seconds.
For the sinusoid wave, since the range of the sine wave is from -1 to 1, we add 1 in the function
in order to shift the wave above the x-axis. So, the range of the sine wave is changed to 0 to 2
volts and then we produced the 3.3 volts peak to peak sine wave by multiplying a factor of 3.3/2.
3. Log function
Figure 4: log function code
A log function was created to send data back to the computer to confirm proper operation. It
takes formatted string as parameters, which is convenient for us to debug the program if we did
not get the message on the computer.
6
Block Diagram
Figure 5: Block Diagram
Flow Chart
Figure 6: Flow Chart
7
Verification Testing
1. Description (and sketch) of sensor and relation to overall system
In this project, four groups cooperated together to complete the overall system including the
keyboard subsystem, Digital-to-Analog Converter subsystem, Digital Potentiometer, and
Analog-to-Digital Converter. The keyboard subsystem controls the settings and parameters of the
other three groups. The keypad subsystem sends commands to the DAC subsystem to start/stop
and select the waveform, to the Digital Potentiometer subsystem to select waveform amplitude,
and to the ADC subsystem to start/stop sampling. Also, the keypad subsystem receives user input
from a digital keypad, which is then interpreted into the commands via the mbeds coding. The
CAN bus, as a media, transfers this information among the various subsystems. For our DAC
group, the physical integrated circuit is showed below:
Figure 7: Physical circuit for connecting CAN bus with Microcontroller
8
2. Module and interface schematics (complete with mbed)
Figure 8: Module and interface schematics (complete with mbed)
3. Method of testing and verification of requirements
For the method of testing, we connected the output of DAC converter chip to the oscilloscope to
verify whether the waveform and frequency matched up with the desired values. The ideal
waveforms and frequencies were sinusoid waves at 1 Hz and 10Hz, and square waves at 1 Hz
and 10 Hz. The requirements for verification were that the error should less than 10%, which
means our frequencies should be in the range from 0.9, Hz to 1.1 Hz for 1 Hz and 9 Hz to 11 Hz
for 10 Hz.
9
4. Testing results (plots, tables, etc.)
Figure 9: Sinusoid wave at 1 Hz
Figure 10: Sinusoid wave at 10 Hz
10
Figure 11: Square wave at 1 Hz
Figure 12: Square wave at 10 Hz
11
5. Percentage Error Analysis
%error for sinusoid wave at 1 Hz: (1 0.92) / 1 = 8%
%error for sinusoid wave at 10 Hz: (10 9.2) / 10 = 8%
%error for square wave at 1 Hz: (1 0.93) / 1 = 7%
%error for square wave at 1 Hz: (10 9.3) / 10 = 7%
The percentage errors are all less than 10% which means our results are valid for the following
experiment.
Validation Testing
The requirements for our Digital-to-Analog Convertor Subsystem are:
Create square and sinusoidal waves at 1 Hz and 10 Hz spanning 0 to +3.3 V.
Receive commands from the Keyboard subsystem to stop/start and select the waveform.
As the verification test showed above, our DAC subsystem meets the requirements. (Figure 9-12)
we can generate square and sinusoidal waves at 1 Hz and 10 Hz spanning 0 to 3.3 V. Also, we
are able to successfully receive commands from the Keypad Control group to select desired
waveform and frequency. The success of our group also paves the way for the Potentiometer
group in order to let them rearrange the amplitude from 1 V to 5 V. It is significant to acquire
square and sinusoidal waves at 1 Hz and 10 Hz from 1 V to 5 V for the analysis of the black box
since we will get 20 sets of data to figure out what exactly the black box is.
Results from Integrated System
A series of diagnostic tests using the integrated system were carried out on a black box circuit
of unknown contents. Based on the response to these tests, the black boxs transfer function was
determined to be approximately:
This equation was determined by examining the output of sine and square waves at frequencies
of 1 Hz and 10 Hz and amplitudes of approximately 1, 2, 3, 4, or 5 V. In actuality, due to
limitations of the DAC equipment and the digipot design, the actual amplitudes of the inputs
were slightly different from the ones listed here. Regardless, the gain of the black box was still
easily found from these values. A sample of the graphs used for this analysis is available in the
12
appendix of this report, with the average values of the input waves listed in the graphs (Figure 16
and 17).
Based on the transfer function of the black box circuit, it was inferred that the circuit was likely
an inverting op amp with a fractional gain of 0.1, with a positive offset of 1 volt achieved by the
application of 1 volt to the non-inverting terminal. A possible diagram of this configuration is
available below:
Figure 13: Schematic of Black Box
Discussion
Our system needs to receive the command from Keyboard system through CAN bus; then we select
MCP2551 (High-Speed CAN Transceiver) as our receiver because it can be driven by 5 volt with
low current standby operation and high transmission rate up to 1 Mb/s. In the implementation, we
use the ticker function to repeatedly check the CAN bus message each second and if there is a
message in the CAN bus with the correct ID we extract the commands from the message. In addition,
we implemented a logging system and simple LED indicator for debugging. The CAN bus is really
effective. Whenever there is a message on the CAN bus, the LED on our mbed will flash and, if the
13
message is sent to our group, we will use the logging system to send the command and our systems
current status back to the terminal on the PC through USB serial port. This logging system helps us
to debug our system efficiently. Compared to the CAN bus, there is also an alternative called SPI
(Serial Peripheral Interface) bus that could have been used in the project. SPI bus is a synchronous
serial data link which is used for short distance, and single master communication. There is one
master device communicating in master/slave mode with other slave devices in order to transfer
information. However, the disadvantage of using the SPI is that there are many existing variations,
making it difficult to find development tools like host adapters that support those variations. Also,
the cost of CAN bus is cheaper than the SPI bus. Considered the factors above, CAN bus is the first
pick for our project.
We optimized accuracy and smoothness of the output signal. Originally we delay milliseconds to
simulate a time counter; then we change the interval to microseconds, which vastly improve the
amplitude accuracy. But there is a tradeoff between the accuracy of the amplitude and the accuracy
of the frequency. On the one hand, the higher delay resolution, the higher amplitude accuracy. On the
other hand, the higher delay resolution, the lower frequency accuracy. Through large amount of
testing, we find that setting time interval to 1000 microseconds is the equilibrium point.
During the lab time, our team members read the assignment handout first. Then for the diagnostics
system block diagram, we clarified that our DAC subsystem received command from the keyboard
subsystem and sent out the analog signal wave through CAN bus. We made consensus on time
schedule and planned to try to finish this lab in 5 weeks. We separated work on this project and had
extra group meeting besides the regular lab time in order to make forward steps prior to the time
schedule. Our group also communicated well with the other groups. We came up with a way to
follow the order through the CAN bus by the keypad control group. Instead of broadcasting the
message with unique commands for each group, each group is assigned a unique ID and each
message only carries the commands to one group. Our group ID is 2 and therefore we only care
about the message with group ID of 2. As for communicating with other groups, they all have good
habits on recording the labs progress on the notebook. This is the greatest think we can improve on
and we could better perform if we had done this lab again.
14
Value Statement
Throughout this lab3, we had a taste of system engineering, which is a crucial part in our future
careers. Since each subsystem may communicate with other groups, we develop a high quality
protocol so that groups can implement their subsystem independently by strictly following the
protocol.
From this assignment, we improved our programming style by separating the code into different files
so that as the code increases in complexity, others can still easily read and continue working on the
code. After having to solve the dilemma between signal accuracy and signal smoothness, we will pay
more attention to the chips specification to make sure we can select the correct chip to avoid any
design conflict in our next project. Furthermore, in our DAC subsystem, the log system that detects
message on the CAN bus as well as tracking our systems current status, and sends the log
information back to PC through serial port, reduces our debug time vastly during the implementation
and whole systems integration.
Conclusion
It has been shown that our DAC subsystem can successfully receive commands from the keyboard sy
stem and produce desired output signal. After integration and verification test, the diagnostic suit wa
s able to consistently operate. The cumulative error, the amplitude of the signal that sent to the black
box deviate from the requirements, draws attention to us. In conclusion, this embedded system impro
ves our skills in system engineering design and communication among team members.
Appendix
Name lists Prices per Unit Quantities Costs
Breadboard $35.00 1 $35.00
CAN bus (MCP2551) $2.11 2 $4.22
DAC convertor (MCP4725) $4.95 1 $4.95
Microcontroller (LPC1768) $49.95 1 $49.95
1-k resistors $0.10 2 $0.20
Power Supply Cables $3.59 3 $10.77
Jumper Wires $6.50 1 $6.50
Engineer Time $35.00 3x20hrs $2100
Total Costs: $2211.59
Figure 14: Bill of Materials for the DAC Subsystem
15
Stages Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7
Team Inventory
Subsystem Block
Diagram
mbed Code Flow Chart
Testing Plan
Build
Integration and Testing
Black Box Diagnostics
Final Report
Figure 15: Gantt chart
Figure 16: Response to listed wave (frequencies are identical)
Figure 17: Response to listed wave (frequencies are identical)
0
0.2
0.4
0.6
0.8
1
1.2
0 100 200 300 400 500
Sine wave, amp = 2.47, f = .881 Hz
0
0.2
0.4
0.6
0.8
1
1.2
0 5 10 15 20 25 30
Square Wave, f = 9.1 Hz, Amp = 2.34