aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/simulator/circuits/voltagedivider.py
blob: b207bf15414b3c7c70361a147c95fac4a6e935ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
# Xytronic LF-1600
# Open Source firmware
# Voltage divider calculation
#
# Copyright (c) 2019 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""


class VoltageDivider(object):
	"""Voltage divider calculation.
	"""

	__slots__ = (
		"r1",
		"r2",
		"i",
	)

	def __init__(self, r1, r2, i=0.0):
		self.r1 = r1
		self.r2 = r2
		self.i = i

	@property
	def u1(self):
		return self.i * self.r1

	@property
	def u2(self):
		return self.i * self.r2

	def calc(self, uIn):
		self.i = uIn / (self.r1 + self.r2)
		return self.u2
bues.ch cgit interface