Calculating a new range?

Thread Starter

Art

Joined Sep 10, 2007
806
Hi Guys,
I have a value that can be between 680 to 830.
I want to convert this value to a new range between
1137 and 1377.

Is there a formula I could use to convert any original value to the new value?
Cheers, Art.
 

MrChips

Joined Oct 2, 2009
30,704
Do you know how to use graph paper? Think of a graph.
The horizontal scale is the x-axis. The vertical scale is the y-axis.
Do you know the equation for a straight line?
You have two points on the graph, (x1,y1) and (x2,y2).
The points are (680,1137) and (830,1377). Take it from there.
If you need more help, let me know.
 

holnis

Joined Nov 25, 2011
49
Yes! That's a simple linear conversion.

So:

NewValue = (((OriginalValue - OriginalMin) * (NewMax - NewMin)) / (OriginalMax - OriginalMin)) + NewMin


Or to make it a little more readable:

OriginalRange = (OriginalMax - OriginalMin)
NewRange = (NewMax - NewMin)

Thus :

NewValue = (((OriginalValue - OriginalMin) * NewRange) / OriginalRange) + NewMin


Hope this Helps :)
 

Thread Starter

Art

Joined Sep 10, 2007
806
Thanks :)
Since the ranges are constant, it looks like some of that can
be calculated just once and simplified.
ie (Newmax - Newmin) which will make things easier.
 

MrChips

Joined Oct 2, 2009
30,704
The next question is are you doing this on a microcontroller? There are ways to avoid using floating-point arithmetic.
 

Thread Starter

Art

Joined Sep 10, 2007
806
Yes it is for a microcontroller, and I'm stuck with integers.
volts = avoltage * 10 '
volts = volts - 2550 '
volts = volts * 10 '
volts = volts / 575 '
volts = volts * 93 '
volts = volts + 4450 '

This is the best I've come up with so far.
There is some error, but the end display is never more
than 0.1 Volt in error when within range according to my multimeter.
avoltage is the original value, volts is the working variable being converted.

1137 and 1377 (the range to convert to) is a reading
from 11.37 volts to 13.77 volts, but since then, new samples have been taken in order to extend that range.
 
Top