Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

SEP105: Introduction to Programming for Engineers

Project 2

T2 2023

Project 2 - Description

The Turing Moore Engineering company has tasked you with putting together a program that can simulate the different charge and discharge rates of capacitors.

As a  minimum, the  program must display a Welcome  message as the first thing displayed in the program with the following information, each on a separate line:

•    The message “Turing Moore Engineering Capacitor Simulator 1.0”

•    Your name (as shown on the unit site)

•    Your Student ID

•    Date the assignment is due in the format: dd/mm/yyyy

The level of mark you are aiming to achieve (eg Desired Level: HD)

An example of what this may look like is shown below:

Turing Moore Engineering Capacitor Simulator 1.0

Name: Benjamin Champion

Student ID: 123456789

Desired Level: C

The following points apply to this document:

•    This assessment is worth 15% of the total grade.

•    The program must be written entirely by you!

•    The program must be written in C++ targeted at the Windows Operating System. Please use Visual Studio Community Edition to write and compile your code on a Windows PC

•    Only functions, types, etc that was covered in class between weeks 1-7 can  be used in this assessment. Anything else being used may be considered for academic misconduct.

The following information describes the requirement for the different levels in this assignment. Before completing tasks from a higher level all tasks from a lower level must first be completed.

Pass (P) Level (50 - 59):

To achieve a pass for the unit the software must be able to display the following behaviour:

•    Prompt the user with an appropriately formatted message about how to use the software.

•    Ask the user for the voltage that will be applied to the circuit.

•    Ask the user if they would like to enter in resistance or capacitance values.

If resistor values are chosen:

o Prompt the user to enter in up to 5 resistor values. The user should be able to enter less than 5 resistor values if they desire.

o Once all the resistor values have been entered, ask the user if the resistors are in series or parallel.

o Based  off  the  response,  calculate  and  display  the  total  resistance  for  the  circuit rounded to two decimal places in Ohms (the word ohm can be used instead of the symbol  Ω).  See Required  Theory for  information  on  how  to  calculate  series  and parallel resistors.

Based off the entered voltage, calculate and display the total current drawn from the circuit  in  Amps  (A)  rounded  to  two  decimal  places.  See Required  Theory for information on how to calculate the current drawn from the circuit.

•    If capacitor values are chosen:

o Ask the user to enter in up to 3 capacitor values. The user should be able to enter less than 3 capacitor values if they desire.

o Ask the user if the capacitors are in series or parallel.

o Calculate and display the total value of the capacitance for the circuit in Farad (F).

•    Ask the user if they would like to continue by entering the character ‘c’ or exit by entering the character ‘e’. If continue is selected, the program should repeat from just after displaying the welcome message. If exit is selected, the program should end, and an appropriate message should be displayed.

Credit (C) Level (60 - 69):

•    All functionality of the Pass level

•    All answers should be displayed and rounded to 2 decimal places using engineering notation (eg  153278.95 Ω would  be  153.28  kΩ, 0.000001  F  is  1  μF)  and the  appropriate  units and symbols. SeeEngineering Notationfor the required engineering notation. The word ohm can be used instead of the symbol Ω, and au can be used instead of μ.

•    After a capacitance and resistance value has been entered, the program should return the RC time constant for the circuit. SeeRequired Theoryfor information on how to calculate the RC time constant.

•    The user should be prompted to enter in a charge value for the capacitor in volts. The time taken for the capacitor to charge and discharge from this value (assuming the capacitor starts fully charged for discharging, and fully discharged for charging) should be displayed to the user correct to two decimal places. SeeRequired Theoryfor information on how to calculate charging and discharging times for a capacitor.

Distinction (D) Level (70 - 79):

•    All functionality of the Credit level

•    Before prompting the user for the desired charge value, the user should be shown the times and voltage levels for the capacitor to reach 1%, 15%, 35%, 50%, 65%, 85% and 99% charge levels for both charging and discharging.

The user should be able to choose to enter in:

o A desired voltage level where the time to reach that voltage level is returned.

o A desired time where the voltage level of the capacitor at that time will be returned.

•    If the user enters in the character ‘h’ at any time, they should be displayed with a message that tells them how to use the program

High Distinction (HD) Level (80 - 100):

•    All functionality of the Distinction level

•    There should  be no limit to the number of resistors and capacitors that the user can enter (baring physical limitations of your PC such as RAM or limitation imposed by your OS).

•    Users should  be able to enter  in a combination of series and  parallel of both resistors and capacitors. Assume that every time a  new combination of series or  parallel capacitors or resistors are entered, they are in series with the previous group of the same type that was entered.

•    The user should be able to clear any previously entered capacitor or resistor values. All values maybe cleared with a single command.

•    An appropriately formatted file should be appended too called “Capacitor Configurations.csv” containing the final calculated resistor value, final calculated capacitor value, RC constant for  that configuration, and charge and discharge times for 1%, 15%, 35%, 50%, 65%, 85% and 99%.  It is expected that each new piece of information is in its own column, with an appropriate  title for that column. Each new combination should be on its own row.

Appendix

Background

The Turing Moore Engineering company has just won a contract to test the new range of capacitors being developed by Panasonic. One part of the contract is to confirm the charge and discharge times of the capacitors against the standard theory. As a new recruit at the company, you have been tasked with writing a program that will calculate the values for the capacitors for different RC configurations. The calculations from your program will then be used to test the capacitors in real world tests.

Prior knowledge

At a minimum to pass this assessment you will need to have skills in the following areas. If you feel  like you are not as strong in these areas as you would like to be, I recommend you go and brush up  on the class content. Please note, depending on how you write your program, and the desired level you are aiming for, you may not use everything listed. That is OK as there are always multiple ways  to write a program with the same functionality.

•    Flow Diagrams

•    Initialising and manipulating variables (int, float, double, etc)

•    Reading and Writing from the console

•    Mathematical Operations

•    Conditionals (&&, ||, etc)

•    Decisions (if, switch)

•    Debugging

•    Looping (for, while, do while)

•    Arrays

•    Structures

•    Vectors

•    Pointers

•    Functions

•    Classes

•    File IO

What to submit

A .zipfolder containing the following items:

•    A flowchart as a PDF – it is highly recommended that you make your flowchart BEFORE writing any software

•    All fully commented code files that pertain to the project (eg the main.cpp file). These files must be the same files that generated the submitted executable file.

•    An .exe of the final code – please note this executable will be tested on a Windows PC. It is up to you to ensure that the software that you write will execute correctly on a Windows PC. If you use a Windows PC and the methods that are described in class, the code will run and execute on a Windows PC. If you use some other operating system (eg MAC, Linux, ChromeOS) there is no guarantee that the software you submit will run, or run correctly. Consider this your only warning, any software that does not run for this reason will generate 0 marks.

•    Any files that you have been asked to generate (for example .csv or .txt files).

•    The entire project folder containing the software. This is independent to the other documents you are required to submit but should be in the same .zipfolder

Hints

•    It is recommended that you develop the program in stages, do not shoot for a High Distinction straightaway. First make a flowchart and program that will achieve a pass. Save this, make a new program, copy in the previous solution and modify the flowchart and program to reach a credit, etc. Make sure you have all of the functionality working of the previous level BEFORE moving onto the next level. You only need to submit the most recent working version of the program you do not need to submit earlier versions of the program.

•    Make your flowchart(s) BEFORE you write any software. This will help you reduce the amount of code you need to write, and help you significantly in debugging your code!

•    While it is tempting to use AI such as Chat GPT to help write your code, in this unit it will be more of a hindrance than a help! As these AI systems do not know what we have covered in class, they will most likely give you code that will not be accepted. Often the code written by these systems is not 100% correct and therefore you will need to manually fix it. You can only do this if you understand the code in the first place (something you will gain in this unit). Finally, you maybe asked about your code, how it works, etc. If you have not written the code you will not be able to answer these questions. This could result in 0 for the assessment, and possibly academic misconduct.

Look at the information provided in Required Theoryand Engineering Notationfor theoretical information that might be needed to complete this assignment outside of what is presented in class

Required Theory

Ohms Law

When we are calculating the voltage drop in a circuit, we use ohms law. Ohms law is defined as:

V = IR

Where V is the voltage in the circuit measured in volts, I is the current in the circuit measured in amps (A), and R is the total resistance of the circuit measured in Ohms (a). For example, if we want to calculate the current flowing inFigure 1, we use simply use Ohms lawas:

Figure 1

V = 12 V

R = 500 Ω

Therefore:

V = IR

I = = = 0.024A = 24 mA

Resistors in Series

Often, we have more complex circuits where we will have multiple resistors in the circuit. There are two configurations the resistors can be in, in series or in parallel.

When the resistors are in series, we simply add the values of the resistors together. Or:

RT  =  R1  +  R2  +  R3  +   … … + Rn

Where RT  is the total resistance of the circuit. For example, we can calculate the total resistance

Figure 2:

Figure 2

In this case:

R1  = 500 Ω

R2  = 600 Ω

R3  = 1k = 1000 Ω

Therefore:

RT  =  R1  +  R2  +  R3

RT  =  500 +  600 +  1000

RT  =  2100Ω = 2. 1 kΩ

Once we know the total resistance of the circuit, we can again use ohms law to calculate the current for a given voltage. For example, if we are given the circuit inFigure 3:

Figure 3

We have already calculated the total resistance when we looked atFigure 2, so:

V = 9 V

R = RT  = 2100 Ω

Therefore:

V = IR = IRT

I = = = 0.0042A = 4.2 mA

Resistors in Parallel

The other configuration the resistors can be in is parallel. When a set of resistors are in parallel, there are  multiple  paths for the  electricity to take. When we calculate the total  resistance for  parallel resistors, we use the following equation:

1 = 1 + 1 + 1 + … + 1

R T          R1       R2       R3                            Rn

For example,to calculate the total resistance of the circuit shown inFigure 4:

Figure 4

= + +

R T(1) =  100(1)0 + 40(1)0  + 10(1)0  =  200(27)0

RT  =  227(00)0  = 74.074 Ω

Now we know the total resistance, we can use Ohms law with a given voltage shown inFigure 5to calculate the total current in the circuit.

Figure 5

V = 6 V

R = RT  = 74.074 Ω

Therefore:

V = IR = IRT

I = = = 0.081A  = 81 mA

Capacitors in Series

A capacitor is like averry small battery in a circuit and allows the circuit to hold and release a small   amount of electrical charge, generally very quickly. The size of a capacitor is measured in Farads (F). When capacitors are placed in series or parallel, we calculate the total capacitance in the opposite    way to how we calculate resistance. So, when capacitors are placed in series, we can use the

following equation to calculate the total capacitance:

1 = 1 + 1 + 1 +   … … + 1

CT          C1        C2        C3                            Cn

Where CT  is the total capacitance of the circuit.

For example, to calculate the total capacitance inFigure 6when three capacitors are in series:

Figure 6

= + +

= + + =

CT  = = 0.6 μF

Capacitors in Parallel

When capacitors areplaced in parallel, we can use the following equation to calculate the capacitance:

CT  =  C1  +  C2  +  C3  +   … … + Cn

For example, to calculate the total capacitance when three capacitors are in parallel as shown in Figure 7:

Figure 7

CT  =  C1  +  C2  +  C3

CT  =  1 +  5 +  7 = 15 μF

Charging and discharging a capacitor

In theory, a capacitor will change and discharge instantaneously. In practice, this will never happen due to the resistances of the circuit. Every wire has a small resistance that will limit the speed a

capacitor can charge or discharge! Often, we want to control the speed in which a capacitor chargers and discharges. The speed in which the capacitor is charged or discharged, with a series resistance, is dictated by the time RC time constant, τ, defined as:

τ = RC

Where τ is the time constant, R is the total resistance of the circuit and C is the total capacitance of the circuit. To determine the voltage level of the capacitor at anytime after a voltage is applied or    removed from the circuit, the following equation can be used:

v =  VF  + (Vi  −  VF)e

Where:

v = the voltage level of the capacitor at time t

VF  = the final voltage level of the capacitor (generally the battery voltage for charging, or 0 for discharging)

Vi  = the initial voltage of the capacitor (generally 0 for charging, or the battery voltage for discharging)

t = the current time

τ = the RC time constant

For example, what will be the value of the voltage at the capacitor in Figure 8150 μs after the switch is closed? Assume the capacitor is fully discharged (0 V) first.

VF  = 50 V

Vi  = 0 V

t = 150 μs

R = 8.2 kΩ = 8200 Ω

C = 0.01 μF

RC constant:

τ = RC

τ = 8200 0.00000001 = 0.000082 S =  82

Therefore, voltage at 150 μs is:

v =  VF  + (Vi VF)e

v =  50 + (0 50)e

v = 41.97 V

Figure 8

μs

What is the voltage of the capacitorFigure 940 μsafter switch 1 is opened? Assume the capacitor is fully charged (20 V) when the switch is opened.

VF  = 0 V

Vi  = 20 V

t = 40 μs

R = 5 kΩ = 5000 Ω

C = 0.01 μF

RC constant:

τ = RC

τ = 5000 ∗ 0.00000001 = 0.00005 S = 50

Figure 9

μs

Therefore, voltage at 40 μs is:

v =  VF  + (Vi VF)e

v =  0 + (20 0)e0(0.)00005(000040)

v = 8.99 V

If we know the desired voltage of the capacitor, but not the time it will take for the capacitor to get there, we can simply rearrange the equation to make time the subject:

t =  −τloge

For example, for the given circuit inFigure 10, how long would it take to for the capacitor to reach 50% charge when the switch is closed? Assume the capacitor is initially fully discharged.

Figure 10

VF  = 5 V

Vi  = 0 V

v = 0.5 * 5 = 2.5 V

R = 1 kΩ = 1000 Ω

C = 6 μF

RC constant:

τ = RC

τ = 1000 0.000006 = 0.006 s = 6 ms

Therefore, the time to reach 50% charge is:

t = −τloge

t =  −0.006loge

t = 0.0042 s = 4.2 ms

Circuits with Multiple resistors and capacitors

Often, we have a more complex circuit involving several resistors and capacitors. We can use the techniques we have seen to simplify the circuit down into one containing just a resistor and a capacitor, then perform the same equations to find the charge/discharge time of the capacitor!

For example, find the time it will take for the capacitor to reach 3V in the circuit shown inFigure 11 once the switch is closed. Assume the capacitor is initially fully discharged.

Figure 11

VF  = 5 V

Vi  = 0 V

v = 3 V

C = 5 μF

First, calculate the equivalent resistance. As the resistors are in series:

RT  =  R1  +  R2  +  R3

RT  =  500 +  200 +  3000 = 3700 a = 3.7 ka

Next, calculate the time constant:

τ = RC

τ = 3700 0.000005 = 0.0185 s = 18.5 ms

Therefore, the time required for the capacitor to reach a charge of 3V:

t = −τloge

t =  −0.0185loge

t =  0.017s = 17ms

What will be the voltage level of the capacitor shown inFigure 121.8 ms after the switch is opened? Assume the capacitor is fully charged before the switch is opened.

Figure 12

VF  = 0 V

Vi  = 7 V

t = 1.8 ms = 0.0018 s

C = 1 μF

First, calculate the equivalent resistance. As the resistors are in parallel:

= + +


1

= RT

1

1000

+

1

6000

+

1

10000

=

19

15000

RT  = = 789.47 Ω

Next, calculate the time constant:

τ = RC

τ = 789.47 0.000001 = 0.000789 S = 0.79 mS

Finally, calculate the voltage after 1.8ms

v =  VF  + (Vi VF)e

v =  0 + (7 0)e 000078(0.0018)9

v =  0.72 V

How long will it take to charge the capacitors to 65% of there total value in the circuit shown in Figure 13after the switch is closed? Assume the capacitors are fully discharged before the switch is closed.

Figure 13

VF  = 7 V

Vi  = 0 V

v = 0.65 * 7 = 4.55 V

R = 15 kΩ = 15000 Ω

First, calculate the total capacitance of the parallel capacitors:

CT  =  C1  +  C2  +  C3

CT  =  0.3 +  0.2 +  1  = 1.5 μF = 0.0000015 F

Next, calculate the time constant: