Computing the LP2980 adjust resistor using Python

The LP2980-ADJ 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

Attached to this post is a script based on Resistors.py 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.

LP2980.py download
#!/usr/bin/env python3
"""
A script that computes the LP2980-ADJ adjust resistor.
See http://www.ti.com/lit/ds/symlink/lp2980-adj.pdf page 17

Based on Resistors.py, see
http://techoverflow.net/blog/2015/05/19/finding-the-nearest-e96-resistor-value-in-python/
"""
from Resistors import *

__author__ = "Uli Koehler"
__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(4.00)  # volts
    # Compute nearest actual value
    e96_rlim = findNearestResistor(radj, sequence=e96)
    actual_vout = computeLP2980OutputVoltage(e96_rlim)
    # Print results
    print("Theoretical Radj value: %s" % (formatResistorValue(radj)))
    print("Closest E96 value: %s" % (formatResistorValue(e96_rlim)))
    print("Output voltage at closest E96 value: %s" % (formatValue(actual_vout, unit="V")))