Non linear voltage mapping/interpolating/scaling - Page 1
Forum section: electronics / beginners

author: John B
author_rank: Frequent Contributor
timestamp: October 27, 2017, 12:18:02 am
content: Lets say you have a simple 0-5V DC control signal. It's simple enough to amplify and add a DC offset, but is there a simple way to map an input voltage to a desired output curve? See pic attached. Let's say the midpoint, 2.5V, can be shifted with a trimpot so that the pink trace represents the output voltage vs input voltage, with any values between 0-2.5v or 2.5v-5v being interpolated, roughly speaking.

author: ebclr
author_rank: Super Contributor
timestamp: October 27, 2017, 12:30:04 am
content: This is named, linearization circuit and can be implemented in many different ways,Some with multipliers and comparators, another with analog switch and opamps, and even with a log-unlog , but none of they are "simple".

author: MasterT
author_rank: Frequent Contributor
timestamp: October 27, 2017, 12:35:25 am
content: If there is a microcontroller presents, approximation 'd be done with Look Up Table (LUT) or polynomial equation. To calculate coefficients you may use Excell, or software running on uCPU itself, LMS - least mean square, probably , the best way to solve a math.

author: Brumby
author_rank: Unknown
timestamp: October 27, 2017, 01:39:59 am
content: Quote from: MasterT on October 27, 2017, 12:35:25 amAn assumption - but one that opens up a whole different world of possibilities...QuoteA look up table would be good for a transform with multiple segments - but for a two segment transform like the one pictured, the simplest and quickest way is to have something as simple as a single IF statement (presuming you take care of limits):If ( Input < 2.5 )Output = Input * 1.2ElseOutput = (Input * 0.6) + 2QuoteOh good lord,NO!For a simple linear process like this, that is an absolutely horrid idea. You will never get the linearity without going to absurd lengths and the execution time is going to be far longer.The effort of going through all the analysis to come up with coefficients might be a fascinating mathematical exercise, but it is just completely OTT for an exercise like this. Please ... never do this in a real world application - unless the circumstancesdemandit.

author: thermistor-guy
author_rank: Frequent Contributor
timestamp: October 27, 2017, 01:52:20 am
content: Your problem reminds me of diode-based circuits that implement a piece-wise linear transfer function. I once saw this being used in an old telephone exchange (loop-disconnect dialling with Ericsson step-by-step mechanical switching - we're talking *old*).The circuit used diodes to combine the outputs of sub-circuits, each with its own gain and offset voltage. With the diodes connected one way, their summing point would equal the maximum of the sub-circuits' outputs. Connected the other way, the diodes provided the minimum of the sub-circuit outputs.If you want a simple analog circuit and only need cater for a few breakpoints, you could consider this diode-based method and see if it meets your requirements.

author: Circlotron
author_rank: Super Contributor
timestamp: October 27, 2017, 03:33:53 am
content: I did something similar many years ago with a series of six trimpots feeding the inputs of a 4051 analog multiplexer. Address lines 1 and 2 select which pot, and PWM address 0 accordingly to select a proportional value partway been two adjacent pots. Low pass filter the 4051 output to get the resulting DC value. Used it as part of an analog advance curve ignition controller. Worked well enough. I used a magnitude comparator to compare the upper 4 bits of a counter that was continually rolling over to some other value to generate the proportional pwm. I still have the hand drawn diagram from about 1990 somewhere.Edit. Here it is.https://pcmhacking.net/forums/viewtopic.php?f=13&t=3520

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 27, 2017, 06:48:37 am
content: Piecewise linear circuits are definitely a thing, yup.If you need more flex, say an exponential interpolation, or a Bezier curve, you can do some things with diodes (note that the above examples are only piecewise-linear when the diode threshold is abrupt -- but real diodes are exponential, and the corners are always a little rounded; usually the rounding depends on temperature, too), but pretty quickly you may find it is easier to solve with a microcontroller (ADC --> function --> DAC). Even an ATtiny can do a modest-order polynomial fit at ~10kSps, and other MCUs much more. An example of curve fitting and implementation for a thermistor curve here:https://www.seventransistorlabs.com/Calc/Thermistor.htmlTim

author: max_torque
author_rank: Super Contributor
timestamp: October 27, 2017, 12:08:02 pm
content: The answer to the OPs request is, of course, another question:With what accuracy and resolution and bandwidth do you need to rescale the characteristic curve?These days, digitising the input signal (with an ADC - Analogue to Digital Convertor) doing some DSP (Digital Signal Processing) and then rebuilding the analogue output signal with a DAC (Digital to Analogue Convertor) is often the way to go. It offers the singular advantage of being very flexible. The hardware doesn't care what the conversion characteristic is (within it's voltage limits and resolution) so you can use the same device with a different calibration very quickly should the requirement change or the need to do a different conversion arise.The down side of the digital domain is that it is, by very definition, discrete. ie, it works in steps, and the size of those steps sets the resolution of the system. If say a step was 1v then you can't output 0.5v. (you'd have to have either 0v or 1v)Typically resolutions of digital interface devices (ADCs DACs etc) are, 8,10,12, 16 bits, giving 256, 1024,4096 and 65535 possible steps (theoretically, the more bits, the less likely you are to be able to actually realise each and every one of them due to things like noise and non-linearity)All circuits also have a bandwidth limitation, ie how quickly they can process from input to output. It's (generally) much easier to build a fast analogue circuit with off the shelf ICs than a digital one.So, if the OP wants to rescale the voltage curve with very high resolution at a very high bandwidth then an analogue approach, which will take longer to develop and be less flexible, would be my choice.However, for more modest resolution and bandwidth requirements, the easier to implement and easy to modify digital approach is likely to be a better bet.

author: John B
author_rank: Frequent Contributor
timestamp: October 27, 2017, 06:08:38 pm
content: Thanks all for the great suggestions. My first thought was actually a micro with lookup tables, but I thought it would be an interesting building block to build as an analogue circuit for other uses too. However I think I will go with a micro in this case. It's part of an engine tachometer circuit, so the micro will read a 0-23kHz square wave, convert the frequency to a PWM duty cycle, then RC filter and buffer into a relatively DC signal, which an air core gauge driver uses to give the correct needle deflection. It's a bit of a crude way, but response time of the gauge isn't crucial - as long as it's fast enough for the human eye.

author: MrAl
author_rank: Super Contributor
timestamp: October 27, 2017, 07:06:06 pm
content: Hi,Analog circuits are much harder to calibrate than microcontroller solutions. That's partly because of temperature stability when using mechanisms like break points.The general topic here is known as "curve fitting". That's where you use a bunch of data points to come up with a formula that you can use in your program. The complexity of the formula can range from simple linear to simply polynomial to just about anything else. The complexity depends on required accuracy and speed.One of the most used methods is called the "Least Squares Method" and is based on the sum of squared errors between the data and the prediction. The calculation is fairly simple for polynomial approximations.

author: max_torque
author_rank: Super Contributor
timestamp: October 28, 2017, 12:06:31 pm
content: Most modern (ie made i the last 20 years) "analogue" Driver Display instruments use stepper motors to drive the needles around, and that stepper is driven directly from the micro. In fact, you'll see a lot of instruments doing a "calibration" sweep at power up, so the system can ensure a known starting position and just step track from then onIt's real easy to reuse these little needle steppers:

author: ebclr
author_rank: Super Contributor
timestamp: October 29, 2017, 02:12:12 am
content: Unfortunately, the word is analog, not digital, and the interface between real word and electronics will be analog forever.Do you know any digital voltage reference?

author: f5r5e5d
author_rank: Frequent Contributor
timestamp: October 29, 2017, 02:42:57 am
content: https://en.wikipedia.org/wiki/Josephson_voltage_standard