Error in Resistor Code Calculator - 5 Band Value to Colours

Feedback and error reporting for Electronics 2000 web site.
Please post any comments, suggestions, errors, omissions, broken links etc. here.
Post Reply
Anxiety
Posts: 3
Joined: Thu Aug 14, 2008 8:14 am

Error in Resistor Code Calculator - 5 Band Value to Colours

Post by Anxiety » Thu Aug 14, 2008 8:31 am

I've been using this page to check myself while learning the color coldes and I noticed an error. If I put in a value of say 9999 your page displays the color code for 1000 ohms, 99999 equals 10,000 ohms, etc. I looked at the javascript (located at http://www.electronics2000.co.uk/calc/calcres3.js) to see what was happening.

I believe the error can be fixed with the change in the the code shown below...

Code: Select all

while(res>=1000)
	{res /=10;
	mult++;
	if(res<1000 && round(res)==1000){
		res=round(res)}
	}
The while loop that is used to figure the multiplier value doesn't account for values that will later be rounded to be equal to 1000. With this code it checks for that and loops again if that is the case. Anyway, I hope this helps other people. I was really getting confused, even though those are really invalid resistor values...lol.

Thanks for the great resource and learning tools.

Chris

Simon (Webmaster)
Site Admin
Posts: 172
Joined: Tue Jan 29, 2008 7:05 pm
Location: Nottingham, UK
Contact:

Re: Error in Resistor Code Calculator - 5 Band Value to Colours

Post by Simon (Webmaster) » Thu Aug 14, 2008 8:57 pm

Hi

Many thanks for spotting that. I remember having the same problem in Electronics Assistant (the downloadable program), which I fixed in the current version. I meant to check the online version but it somehow slipped off the 'to do' list.

I'll modify the code with your fix and chdck it over the weekend.

Thanks again.
Simon Carter
Electronics 2000
http://www.electronics2000.co.uk

Simon (Webmaster)
Site Admin
Posts: 172
Joined: Tue Jan 29, 2008 7:05 pm
Location: Nottingham, UK
Contact:

Re: Error in Resistor Code Calculator - 5 Band Value to Colours

Post by Simon (Webmaster) » Fri Aug 15, 2008 8:22 pm

Update:

I've had a better look at the problem. As stated, 9999 (for example) is an invalid value and cannot be displayed on a 4 or 5-band resistor code. The nearest values that can be displayed are 9990 (white white white brown) or 10000 (brown black black red). Valid codes are displayed correctly.

I'm still deciding how to handle this, I think the best thing is to stick to rounding to 10000 (which is the nearest value that can be displayed) and to show a message warning that the value has been rounded, along with the new value. I also hope to include preferred values in the online calculators; this feature is already built into Electronics Assistant.

In the course of this I have also discovered a bug that I thought I fixed in Electronics Assistant V4.1. Again all valid values are shown correctly, but ome values produce a gold band for the 2nd or 3rd band, and other anomolies. I'll try to correct this in the next version.

All this has shown that converting from colours to value is easy, but converting the other way is harder since invalid values must be handled by one method or another.
Simon Carter
Electronics 2000
http://www.electronics2000.co.uk

Anxiety
Posts: 3
Joined: Thu Aug 14, 2008 8:14 am

Re: Error in Resistor Code Calculator - 5 Band Value to Colours

Post by Anxiety » Fri Aug 15, 2008 10:19 pm

Hey there. I have limited experience with Javascript, but I believe Round(999.9) would round to 1000 and Round(999.4) would round to 999. So in the case that the variable "res" was >= 999.5 it will round to 1000 and loop again. Otherwise it will finish the loop and continue on to determine the first three digit bands. In other words it will round to the nearest valid resistor value on its own. Ie. 9999 would decode to a 10,000 ohm resistor, and 9994 would decode to a 9990 ohm resistor.

On hind sight I think this will work with less code...

Code: Select all

while(res>=1000)
   {res /=10;
   mult++;
   if(round(res)==1000){
      res=round(res)}
   }
Sorry, for adding to your workload. I was only trying to point out an anomaly I found. By the way, your logic for determining the color bands from a numeric value is quite clever. :-)

Chris

Simon (Webmaster)
Site Admin
Posts: 172
Joined: Tue Jan 29, 2008 7:05 pm
Location: Nottingham, UK
Contact:

Re: Error in Resistor Code Calculator - 5 Band Value to Colours

Post by Simon (Webmaster) » Fri Aug 15, 2008 10:31 pm

I believe you are right. I must admit my knowledge of JavaScript is pretty rusty - its a few years since I touched any of the code for these calculators. I'll stick with the rounding and show a warning message if the value has been rounded to avoid confusion.
Simon Carter
Electronics 2000
http://www.electronics2000.co.uk

Simon (Webmaster)
Site Admin
Posts: 172
Joined: Tue Jan 29, 2008 7:05 pm
Location: Nottingham, UK
Contact:

Re: Error in Resistor Code Calculator - 5 Band Value to Colours

Post by Simon (Webmaster) » Wed Aug 20, 2008 4:22 pm

Update:

I've re-written the resistor code calculator, combining the 4 existing calculators into one, with a number of extra functions. Both 4 and 5 band resistors can be selected using the radio buttons at the top of the calculator. Codes can be converted from 4 to 5 band or vice versa by entering the code then changing the resistor type. Colour bands can be selected from a box that appears when you hover the mouse over a colour band on the resistor image (for conversion from colours to value). Preferred resistor values are also calculated, with a number of preferreed series available for selection from E12 - E192.

Hopefully in the midst of all this the original problem is fixed! I'd appreciated if you could take a look and let me know if you have any problems, either the original problem or new ones. The calculator will still give an error at present if you type characters other than 0-9 or '.' into the value box, I'll fix that soon.

I plan to overhaul the other calculators soon, adding the preferred resistance calculation where appropriate, and generally overhauling them. The web has moved on a bit since they were written, so it's time they caught up a bit!
Simon Carter
Electronics 2000
http://www.electronics2000.co.uk

Post Reply