Skip to content

Commit 7112f7b

Browse files
For each resistor found, the series specific error margin is added to the given result
1 parent 3688536 commit 7112f7b

File tree

7 files changed

+53
-6
lines changed

7 files changed

+53
-6
lines changed

bin/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/VoltageDiv/
2+
/Default/

bin/Default/Main.class

99 Bytes
Binary file not shown.

bin/VoltageDiv/GetResistors.class

231 Bytes
Binary file not shown.
159 Bytes
Binary file not shown.

src/Default/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static void main(String args[]) {
4747
if (r.found())
4848
System.out.println("Trying to find value closest to:" + r.getGivenResistorValue_Ohms() + " Ohms. Found:"
4949
+ r.getFoundResistorValue_Ohms() + " Ohms . Actual error:" + r.getActualError_P()
50+
+ "% Series specific error margin +/-:"+r.getSeriesSpecificErrorMargin()
5051
+ "% Found in Series E" + r.getBelongsToESeries());
5152
else
5253
System.out.println("No matching standard value found");
@@ -75,6 +76,7 @@ public static void main(String args[]) {
7576
+ " Voltage error:" + dr.getActualErrorInOutputVoltage_P() + "%");
7677
}
7778

79+
// Get solution with smallest error in output voltage....
7880
DividerResult dr = result.getSolutionWsmallestErrInOutputVoltage();
7981
System.out.println();
8082
System.out.println("Smallest error in output voltage R1=" + dr.getR1_V() + " Ohm R2=" + dr.getR2_V()

src/VoltageDiv/GetResistors.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,52 @@ public static ResistorResult getRValueClosestTo(double rToTest, double allowedEr
102102

103103
if (MathHelper.isInRangeWithinPercentage(allowedError_P, rToTest, standardValueForR * pow)) {
104104

105-
ResistorResult r = new ResistorResult(standardValueForR * pow, rToTest, e, true);
105+
//
106+
// We've found a matching resistor....
107+
//
108+
ResistorResult r = new ResistorResult(standardValueForR * pow, rToTest, e, getSeriesSpecificErrorMargin(e), true);
106109
return r;
107110
}
108111
}
109112
}
110113
}
111-
ResistorResult r = new ResistorResult(0, rToTest, 0, false);
114+
//
115+
// We've found nothing.....
116+
//
117+
ResistorResult r = new ResistorResult(0, rToTest, 0,0, false);
112118
return r;
113119
}
120+
121+
/**
122+
* Returns the specific error margin for the given E- series.
123+
*
124+
* @param e The standard series (E3..E96).
125+
* @return Either 0 if no matching series was passed or the specific error
126+
* margin in percent for the series passed.
127+
*/
128+
129+
static private int getSeriesSpecificErrorMargin(int e) {
130+
131+
switch (e) {
132+
case 3:
133+
return 25; // Error is > +/- 20% so I choose 25%...
134+
135+
case 6:
136+
return 20;
137+
138+
case 12:
139+
return 10;
140+
141+
case 24:
142+
return 5;
143+
144+
case 48:
145+
return 2;
146+
147+
case 96:
148+
return 1;
149+
150+
}
151+
return 0;
152+
}
114153
}

src/VoltageDiv/ResistorResult.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package VoltageDiv;
22

3-
import java.math.RoundingMode;
4-
53
/**
64
* Holds a result for a resistor value found inside in any of the series E3..E96
75
*
@@ -16,15 +14,17 @@ public class ResistorResult {
1614
private double foundResistorValue_Ohms;
1715
private double givenResistorValue_Ohms;
1816
private int belongsToESeries;
19-
private double actualError_P;
17+
private double actualError_P; // Error between value searched and standard value found.
18+
private int seriesSpecificErrorMargin;// Error +/- in percent for the series the resistor belongs to.
2019
private boolean found;
2120

22-
public ResistorResult(double foundResistorValue_Ohms, double givenResistorValue_Ohms, int belongsToESeries,
21+
public ResistorResult(double foundResistorValue_Ohms, double givenResistorValue_Ohms, int belongsToESeries,int seriesSpecificErrorMargin,
2322
boolean found) {
2423
super();
2524
this.foundResistorValue_Ohms = foundResistorValue_Ohms;
2625
this.givenResistorValue_Ohms = givenResistorValue_Ohms;
2726
this.belongsToESeries = belongsToESeries;
27+
this.seriesSpecificErrorMargin=seriesSpecificErrorMargin;
2828
this.found = found;
2929
}
3030

@@ -58,6 +58,10 @@ public int getBelongsToESeries() {
5858
public void setBelongsToESeries(int belongsToESeries) {
5959
this.belongsToESeries = belongsToESeries;
6060
}
61+
62+
public int getSeriesSpecificErrorMargin() {
63+
return this.seriesSpecificErrorMargin;
64+
}
6165

6266
public boolean found() {
6367
return found;

0 commit comments

Comments
 (0)