Lab PDF

advertisement
EE 355 Lab 2 – First Step Response
1 Introduction
In this programming assignment you will write a simple C++ program to compute
the transient response of a simple RC (resistor/capacitor) circuit over time.
This assignment should be performed INDIVIDUALLY. This is a peer evaluated lab
where your grade will be determined by 2 peer evaluations. Please see the
guidelines for peer evaluated labs provided by the instructor. You will submit your
lab via Vocareum (see instructions at http://bits.usc.edu/ee355/lab-submissionand-grading/ )
2 What you will learn
After completing this programming assignment you will:
1. Write a non-trivial C++ program from scratch
2. Use cin to accept input
3. Use cout to produce output along with I/O manipulators to
4. Use a loop and if statements to compute desired values.
3 Background Information and Notes
Consider the response of an RC circuit to a step-input, similar to what you have
seen in a linear circuits course such as EE 202L. (You may reference the website:
http://www.electronics-tutorials.ws/rc/rc_1.html if you have not taken EE 202L).
You are given a simple RC-Circuit that is energized by a battery producing a voltage,
Vs, through a switch. The voltage at the capacitor, Vc, is 0V before t=0 at which
time the switch is turned on. Vc varies according to:
𝑡
𝑉𝑐(𝑡) = 𝑉𝑠 [1 − 𝑒 −𝑅𝐶 ]
4 Requirements
[Important:] Your program must follow the input and output formats described
here or you will likely lose points. Please take care to meet the specified formats.
Your program shall meet the following requirements for features and approach:
1. Query the user for the circuit and simulation time parameters: Vs, R, C, and T as
double values. Print this prompt:
"Enter Vs, R, C, and T separated by spaces:"
2. Using those values print a table of time versus the capacitor voltage (Vc). You
should have a row in the table for each value of t from time t=0 to t=T
Last Revised: 1/14/2016
1
EE 355 Lab 2 - First Step Response
[inclusive] in units of T/25 seconds (i.e. there should be 26 rows in your table).
Show the time in the first column and the voltage on the capacitor in the next.
Each column should be 15 characters in width with values right justified. In
addition, use the setprecision and fixed I/O manipulators to make sure only 2
digits to the right of the decimal point are printed. You must use appropriate
I/O manipulators to achieve the column width display and 2-digit precision.
Output a header row that looks like this:
Time
Vc
See the examples later on in this document and ensure your table matches the
format.
3. Using if statements, detect & print the rise time of the signal. The rise time of a
signal is computed as the time it takes the signal to transition from 10% to 90%
of the final voltage (i.e. Vs). Compute this value by checking the capacitor
voltage at each time step that you compute it. Record the first time step at
which the voltage reaches at least 10% of Vs and then record the first time step
at which the voltage reaches at least 90% of Vs. The rise time is the difference
between these values.
Output the rise time again using 2 digits after the decimal point:
Rise time is: XX.YY seconds
If Vc never reaches one or both of these thresholds, simply output
No rise-time available
5 Prelab
To compute certain common mathematical functions, you can use the standard C
library. You can use these functions by including them in your program by inserting
the line:
#include <cmath> in your source code.
What is the name of the cmath function you would use to compute the following
values. You do not have to turn this in, but look it up for your own reference.
a. ex:
_____________________
b. ln x:
_____________________
5
c. x :
_____________________
6 Procedure
Perform the following.
1. Write a program named 'rc_circuit.cpp' to meet the requirements given above
2
Last Revised: 1/14/2016
EE 355 Lab 2 - First Step Response
2. Compile your program using the following command line. Correct any compile
errors.
$ g++ -g –Wall -o rc_circuit
rc_circuit.cpp
3. Execute your program using the following command line. Correct any run-time
errors.
$ ./rc_circuit
4. Try the values shown in the examples below and ensure your output matches
and follows the exact format.
5. Try a different set of values and make sure you know what you expect the right
answer to be and ensure that your T value is long enough to account for your
chosen R, C values. Recall it takes about 5* for Vc to reach Vs. Plug in a few
other testcases to make sure your program works correctly.
6. Submit your rc_circuit.cpp on Vocareum. See the instructions at:
http://bits.usc.edu/ee355/lab-submission-and-grading/
Test Case 1:
Enter Vs, R, C, and T separated by spaces:
3 1 1 5
Time
Vc
0.00
0.00
0.20
0.54
0.40
0.99
0.60
1.35
0.80
1.65
1.00
1.90
1.20
2.10
1.40
2.26
1.60
2.39
1.80
2.50
2.00
2.59
2.20
2.67
2.40
2.73
2.60
2.78
2.80
2.82
3.00
2.85
3.20
2.88
3.40
2.90
3.60
2.92
3.80
2.93
4.00
2.95
4.20
2.96
4.40
2.96
4.60
2.97
4.80
2.98
5.00
2.98
Rise time is: 2.20 seconds
Last Revised: 1/14/2016
3
EE 355 Lab 2 - First Step Response
Test Case 2:
Enter Vs, R, C, and T separated by spaces:
5 .4 .75 .5
Time
Vc
0.00
0.00
0.02
0.32
0.04
0.62
0.06
0.91
0.08
1.17
0.10
1.42
0.12
1.65
0.14
1.86
0.16
2.07
0.18
2.26
0.20
2.43
0.22
2.60
0.24
2.75
0.26
2.90
0.28
3.03
0.30
3.16
0.32
3.28
0.34
3.39
0.36
3.49
0.38
3.59
0.40
3.68
0.42
3.77
0.44
3.85
0.46
3.92
0.48
3.99
0.50
4.06
No rise-time available
See next page for evaluation/grading criteria
4
Last Revised: 1/14/2016
EE 355 Lab 2 - First Step Response
7 Evaluation Criteria
1. [1 pt.] The program provided appropriate prompts when asking for the input values.
2. [2 pt.] The output was printed in the correct tabular format for the capacitor voltage.
3. [2 pt.] The program produces the correct capacitor voltage output in the table for the
inputs shown in test case 1 above.
4. [2 pt.] The program prints the correct rise time for test case 1.
5. [1 pt.] The program correctly outputs "No rise-time available" if Vc does not reach the
90% rise time threshold. Use the inputs from test case 2 above to verify.
6. [1 pt.] The program passes another reasonable test case for both the table
output and rise time output. If the test case fails, the evaluator will post the
inputs he/she provided along with the actual output from your program and
the expected output of the program. [Be sure you provide sufficient time for
the given R and C value to let the voltage rise to 90% of Vs.]
7. [1 pt.] Code was appropriately indented when opened in ‘gedit’ on the Linux
VM.
Last Revised: 1/14/2016
5
Download