Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are required to design a program to calculate the best possible standard resistors to use for a voltage divider circuit to get the required

You are required to design a program to calculate the best possible standard resistors to use for a voltage divider circuit to get the required circuit gain. The circuit will contain 2 to 4 resistors.

- Write a program to calculate the optimum resistor values for a voltage divider circuit.

- Use the design in the given structure diagrams.

A program design is provided in the given structure diagrams. Write your program from these diagrams. The diagrams only show operational program statements. You also need to write include statements, function prototypes, variable and constant definitions, etc, even though these are not shown on the diagrams.

From Ohm's law, it can be shown that the gain is

= / = 2 / 1 + 2

1 = 1.2 / 1 + 2 2 = 3.4 / 3 + 4

The resistors R1 and R3 must be chosen from the values on the standard E12 scale from 1.0k to 100k ohms.

The E12 numbers are 10,12,15,18,22,27,33,39,47,56,68,82. The allowed resistors in k are: { 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2, 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82, 100, 1e9 }

Note that the last resistor is 1 G, to represent an open circuit. This is allowed because resistors R2 and/or R4 may not be required, in which case they may be replaced by an open circuit. Resistors R1 and R3 cannot be zero. Only resistors R2 and R4 may be this value. The user will enter the required gain, which must be greater than zero and less than one. Then the program will calculate the circuit gain for all the different combinations of resistors, and display the resistor values that produce the gain nearest to the required gain.

main Function Design:

The allowed standard resistor values should be defined in an array in the main function, and this array needs to be passed as a parameter to other functions that need it. The gain variable and resistor variables (R1, R2, R3, R4) must also be defined in the main function and passed to other functions as required. Define R1, R2, R3 and R4 as separate variables (not an array) so you can use them to demonstrate the use of reference parameters.

When the program is run, the Input function will allow the user to enter the required circuit gain. The gain should satisfy this condition: 0 gain < 1

If the user enters zero, the input should stop and the program should end with no calculations being made.

If the gain does not satisfy this condition, the input should loop until a valid gain is entered.

The input should use cin.fail to check for non-numeric input. If input fails, the program should loop for more input until a valid gain is entered.

After a valid input gain has been obtained, pass the gain, standard resistor array and references to the R1 to R4 variables from the main function to the Calculate function.

This function will use for loops to try all possible combinations of R1 to R4 values to find the gain nearest to the required gain.

On completion, this function should return the actual calculated gain and the four resistor values to the main function.

Sustainability Requirements:

To minimise circuit power consumption, when there is more than one solution with the same gain factor, the preferred solution will have the largest possible total resistance (P1 + P2). To minimise program run time, perform as few calculations as possible. See Hints section. Your program should implement these requirements.

Hints:

Use a while or do-while loop to check that the input gain is valid, and repeat the input until a valid value is entered. (Using an if statement is not correct, because after an incorrect entry, the next entered value may also be incorrect.) Use for loops to step through the resistor values for the gain calculations, because the number of loop repetitions is known. Use a single array of standard resistor values from 1.0 to 100 k (inclusive) plus the open circuit value. The values of R1 and R3 can be any of the E12 standard values in the range from 1.0 to 100 k inclusive, but they cannot be the open circuit value. The values of R2 and R4 can be any value in the array.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

" SC 0 7 1 0 "

Answered: 1 week ago