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.
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.
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
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.
The next question is are you doing this on a microcontroller? There are ways to avoid using floating-point arithmetic.
Being conversant with fractions is a great help in doing fixed point arithmetic on a microcontroller.
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.