Author Topic: Non linear voltage mapping/interpolating/scaling  (Read 2698 times)

0 Members and 1 Guest are viewing this topic.

Offline John BTopic starter

  • Frequent Contributor
  • **
  • Posts: 800
  • Country: au
Non linear voltage mapping/interpolating/scaling
« on: October 27, 2017, 12:18:02 am »
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.
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 2328
  • Country: 00
Re: Non linear voltage mapping/interpolating/scaling
« Reply #1 on: October 27, 2017, 12:30:04 am »
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".
 
The following users thanked this post: John B

Online MasterT

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: ca
Re: Non linear voltage mapping/interpolating/scaling
« Reply #2 on: October 27, 2017, 12:35:25 am »
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.
 
The following users thanked this post: John B

Offline Brumby

  • Supporter
  • ****
  • Posts: 12297
  • Country: au
Re: Non linear voltage mapping/interpolating/scaling
« Reply #3 on: October 27, 2017, 01:39:59 am »
If there is a microcontroller presents
An assumption - but one that opens up a whole different world of possibilities...

Quote
, approximation 'd be done with Look Up Table (LUT)
A 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.2
Else
   Output = (Input * 0.6) + 2


Quote
or polynomial equation.
Oh 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 circumstances demand it.
 

Offline thermistor-guy

  • Frequent Contributor
  • **
  • Posts: 372
  • Country: au
Re: Non linear voltage mapping/interpolating/scaling
« Reply #4 on: October 27, 2017, 01:52:20 am »
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.
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 2328
  • Country: 00
Re: Non linear voltage mapping/interpolating/scaling
« Reply #5 on: October 27, 2017, 02:15:50 am »
 

Offline Circlotron

  • Super Contributor
  • ***
  • Posts: 3180
  • Country: au
Re: Non linear voltage mapping/interpolating/scaling
« Reply #6 on: October 27, 2017, 03:33:53 am »
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
« Last Edit: October 27, 2017, 03:43:44 am by Circlotron »
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21674
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Non linear voltage mapping/interpolating/scaling
« Reply #7 on: October 27, 2017, 06:48:37 am »
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.html

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline max_torque

  • Super Contributor
  • ***
  • Posts: 1280
  • Country: gb
    • bitdynamics
Re: Non linear voltage mapping/interpolating/scaling
« Reply #8 on: October 27, 2017, 12:08:02 pm »
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.


 
The following users thanked this post: jnz

Offline John BTopic starter

  • Frequent Contributor
  • **
  • Posts: 800
  • Country: au
Re: Non linear voltage mapping/interpolating/scaling
« Reply #9 on: October 27, 2017, 06:08:38 pm »
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.
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1437
Re: Non linear voltage mapping/interpolating/scaling
« Reply #10 on: October 27, 2017, 07:06:06 pm »
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.
 

Offline max_torque

  • Super Contributor
  • ***
  • Posts: 1280
  • Country: gb
    • bitdynamics
Re: Non linear voltage mapping/interpolating/scaling
« Reply #11 on: October 28, 2017, 12:06:31 pm »
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 on

It's real easy to reuse these little needle steppers:







« Last Edit: October 28, 2017, 12:08:02 pm by max_torque »
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 2328
  • Country: 00
Re: Non linear voltage mapping/interpolating/scaling
« Reply #12 on: October 29, 2017, 02:12:12 am »
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?
 

Offline f5r5e5d

  • Frequent Contributor
  • **
  • Posts: 349
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf