Connect with us

How to "simulate" a logaritmic trimpot

Discussion in 'Electronic Design' started by Henrik [6650], Jul 12, 2006.

Scroll to continue with content
  1. Hello group,

    I am trying to simulate a logaritmic trimpot in software on a small
    microcontroller.

    We have some industrial controllers where some parameters (i.e. max running
    time) is set via potmeters on the front. And one of the potmeters are
    logaritmic to give a finer change in the lower area and a more coarse change
    in the high area.

    My idea is to use a linear trimpot (which we have stocked) to replace a
    logaritmic pot (which we have not stocked). The pot wiper is connected
    directly to the micros internal AD converter and to GND/AVCC of the
    microcontroller. By turning the pot I can now measure 0-1023 (10-bit AD) on
    the micro, that is just fine.

    I need to convert this 0-1023 value to a value between 10 and 54000
    logaritmic. I think a mathematical function or a table lookup is the way to
    go, but I actually cannot figure out how. I think mainly due to my lack of
    knowledge about how such a pot actually works.

    So any help is gladly appreciated.

    Thanking you all in advance.

    Best regards
    Henrik
     
  2. Joerg

    Joerg Guest

    Hello Henrik,
    You could include the math header before compiling and use the log
    function in there. Hoping it contains one, that is.

    However, many pots aren't exactly "log". If your client or the users
    like how the former pot worked take one of these and ohm it out in, say,
    one-degree steps. Mount a knob on it, glue a long thin stick to that and
    keep going. Just don't ever reverse during that measurements series
    because the shaft connection often has slack. Now look at the results
    and divide it into linear sections that follow the curve as a whole
    pretty well. To learn about this strategy look under "piecewise linear
    approximation" which is often done in gain control circuits.

    With piecewise linear your code could be realized with staggered "if"
    statements with an "else" only after the last one or if you want it to
    look clean a "switch" and "case" statement. This avoids huge ROM lookup
    tables for the pot function since uCs often don't have a lot of ROM.

    BTW, questions like this might yield more answers in the embedded newsgroup.
     
  3. Most log-taper pots have about 10% resistance at half a turn.

    Actually you want the inverse function-- a log function grows more and
    more slowly, you need an exp-like function.

    A little doodling with Excel shows that a exponent of about 3 does the
    trick:


    0 0%
    100 0%
    200 1%
    300 3%
    400 6%
    500 12%
    600 20%
    700 32%
    800 48%
    900 68%
    1000 93%

    .... about 12% at half turn, close enuf.

    so one possible formula loks somethng like: (in/1024)^3.0 * 54000 + 10
     
  4. Jon

    Jon Guest

    This is not exactly what you asked for, but there are a couple of
    all-analog tricks for getting a non-linear gain vs position with a
    linear pot. What you describe is actually an exponential (inverse log)
    function, since the slope is small for small values of R, and large for
    large values of R.
    ..
    Use the pot as a rheostat (in series with a small fixed resistor) as
    the input resistor in an op amp inverting amplifier configuration.
    This gives you a large slope at low resistance settings, and a small
    slope at large resistance settings. This is just the opposite of what
    you want; So o the following: Connect this circuit, in series with a
    unity gain inverting amplifier. Connect a fixed resistor to the output.
    Call this block the "feedback element". Use this "feedback element"
    as the feedback resistor of another op amp inverting amplifier. This
    gives you the general shape that you need. By tweaking the resistance
    values, you can get a reasonable approximation to an exponential
    characteristic.
    ..
    Another method is to use a "Tee" network in the feedback path of an
    op-amp inverting amplifier. Call the series Rs R1, R2. Use the
    rheostat connected pot as the shunt resistor, R3 of the "tee".. The
    effective feedback resistance = R1 + R2 + R1R2/R3. The gain vs
    rotation has the general shape that you need. By tweaking the Ratio of
    R3max to R1, you can get very close to an exponential characteristic.
    Regards,
    Jon
     
  5. A simpler way is to just use a high-value pot with a considerably
    smaller load resistor.

    For example, a 10K pot with a 680 ohm load resistor will give you about
    10% voltage at half a turn, going up more steeply after that.
     
  6. Ken Smith

    Ken Smith Guest

    The table method turns the curve into a bunch of straight lines. The
    length of the lines is determined by the number of entries in the table.

    // all integers:

    Index = Input / (Entries - 1)
    Fraction = Input - (Entries - 1)*Index
    Slope = Table[Index+1] - Table[Index]
    Output = Table[Index] + Slope*Fraction

    Chances are, a lookup table with 17 entries will be good enough for your
    pot purpose.
     
  7. Joerg

    Joerg Guest

    Hello Jon,

    It's simpler than that, just one resistor from wiper to top or to
    bottom, depending on which direction you want to "bend". There used to
    be a scan of an old, old magazine page with graphs that Martin Griffith
    (here from s.e.d.) did but that web site is now dead.

    I'll ping Martin in a separate thread, maybe he still has it.
     
  8. Joerg

    Joerg Guest

    Hello Henrik,
    Ok, Martin Griffith posted the old pdf copies again on how to mimick
    that pretty closely without code and just one extra resistor:
     
  9. Ken Smith

    Ken Smith Guest

    [....]
    ooops, I went back and changed the constants to variable names to make it
    clearer and as a result screwed it up

    Here it is more like I started with.
     
  10. Jon

    Jon Guest

    Joerg,
    The method of using a "loaded pot" does indeed give you a non-linear
    characteristic. However, the output/input curve is "S" shaped with
    respect to a straight line drawn between the minimum and maximum
    outputs. By using a load resistor that is extremely small with respect
    to the pot resistance value, you can minimize the change in curvature
    at one end or the other, but you can't eliminate it.
    Regards,
    Jon
     
  11. Joerg

    Joerg Guest

    Hello Jon,


    Yes, it won't be perfect. Then there is the old trick to provide a
    piecewise linear scheme via diodes but this quickly becomes esoteric for
    a simple potmeter application.
     
  12. joseph2k

    joseph2k Guest

    Many posts, many solutions, here is one more:

    1. It can also be understood as a exponential pot.

    2. You want to solve out = a + e^bx for say 4 positions to get a good fit.

    a and b are arbitrary constants (what we are solving for) and out is the
    value curve desired and x is the shaft angle / percentage rotation of the
    linear pot wiper.

    3. Then you can trade off table space versus computational cost for the
    curve fitting. The exponential curve and its relatives are self similar.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-