I have a situation where I need to create a function that will work on an input variable to convert the outputs into the values needed to go to PWM.
So here is what I know:
With an input of 30 I need the output to be 0
With an input of 60 I need the output to be 62.5
With an input of 90 I need the output to be 125
With an input of 150 I need the output to be 250
So, what function can I pass a variable with each of those input variables through that will return the listed outputs?
Those points form a line, which can be described with a few forms of an equation. Here is the one that shows you how to figure this out:
out = (in-30)*(62.5/(60-30));
Basically you have find the offset (aka bias) to get to zero (30 in this case) and then scale the result so that the next point will fit by correcting the input value (60-30) in the same way and then multiply by the values you to get. You can reduce the messy 62.5/(60-30) to 2.0833 if you want and multiply out if you want a*x+b type of equation.