Last active
January 31, 2019 22:28
-
-
Save rgov/e2c65231cb1174137f248b220f93cc7c to your computer and use it in GitHub Desktop.
Compute time interval/resistance correlation for the TPL5110 system timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
The TPL5110's time interval is configured by the applying resistance between the | |
DELAY pin and GND. The correspondance between time interval and resistance is | |
given starting on page 12 of this document: | |
http://www.ti.com/lit/ds/symlink/tpl5110.pdf | |
The documentation contains lookup tables for common intervals between 100ms to | |
2h. This script can also be used to calculate values between 1s and 2h. | |
''' | |
from math import sqrt | |
coefficients = [ | |
( 1, 5, ( 0.2253, -20.7654, 570.5679)), | |
( 5, 10, (-0.1284, 46.9861, -2651.8889)), | |
( 10, 100, ( 0.1972, -19.3450, 692.1201)), | |
( 100, 1000, ( 0.2617, -56.2407, 5957.7934)), | |
(1000, 7200, ( 0.3177, -136.2571, 34522.4680)), | |
] | |
def solve_r(T): | |
'''Solve for resistance (ohms) given time interval (secs)''' | |
for lo, hi, (a, b, c) in coefficients: | |
if lo < T <= hi: | |
return (100*(-b + sqrt(b**2 - 4*a*(c-100*T)))) / (2*a) | |
raise Exception("Time value is out of range") | |
def solve_t(r): | |
'''Solve for time interval (secs) given resistance (ohms)''' | |
for lo, hi, (a, b, c) in coefficients: | |
T = (a*r**2 + 100*b*r + 10000*c) / 1000000.0 | |
if lo < T <= hi: | |
return T | |
raise Exception("No time found for resistance value") | |
if __name__ == '__main__': | |
time = 1*60*60 # one hour | |
print(solve_r(time), 'ohms') | |
print(solve_t(solve_r(time)), 'seconds') # double check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment