Computing the LP2980 adjust resistor using Python

The LP2980ADJ is a 50 mA LDO that be configured for an output voltage from 1.23V to 15V using a pair of resistors.

The datasheet lists a formula for the output voltage, however no easy-to-use customizable software is provided that can be used to directly compute the correct resistor in a reproducible way.

Attached to this post is a script based on UliEngineering that not only computes the closest E96 (default, other ranges also available) resistor value and the actual output voltage with the actual E96 resistor value. A usage example is included at the bottom.

#!/usr/bin/env python3
A script that computes the LP2980-ADJ adjust resistor.
See page 17

Based on, see
from UliEngineering.EngineerIO import *
from UliEngineering.Electronics.Resistors import *

__author__ = "Uli Köhler"
__license__ = "CC0 1.0 Universal"
__version__ = "1.0"

def computeLP2980OutputVoltage(r):
    """Compute the actual output voltage of a LP2980-ADJ given the adj resistor"""
    return 1.23 + 1.23 * (r / 51.1e3)

def computeLP2980AdjResistor(u):
    Compute the exact value for the LP2980-ADJ adjust resistor,
    given a target output voltage in volts.
    #Check limits
    if u < 1.23: print("Warning: LP2980-ADJ does not support output voltages below 1.23V")
    elif u > 15: print("Warning: LP2980-ADJ does not support output voltages above 15V")
    return (100 * u - 123) * 51100 / 123

# Usage example: Compute E96 Rlim for U=4.00V
if __name__ == "__main__":
    # Compute theoretical value
    radj = computeLP2980AdjResistor(normalize_numeric("4.00 V"))
    # Compute nearest actual value
    e96_rlim = nearest_resistor(radj, sequence=e96)
    actual_vout = computeLP2980OutputVoltage(e96_rlim)
    # Print results
    print("Theoretical Radj value: %s" % (format_value(radj, "Ω")))
    print("Closest E96 value: %s" % (format_value(e96_rlim, "Ω")))
    print("Output voltage at closest E96 value: %s" % (format_value(actual_vout, "V")))