1
- # https://en.wikipedia.org/wiki/555_timer_IC#Astable
2
1
from __future__ import annotations
3
2
4
3
"""
5
- This function can calculate the frequency and duty cycle of an astable 555 timer
6
- The function takes in the value of the external resistances (in OHMS) and
7
- capacitance (in microFARADS), and calculates the following:
4
+ Calculate the frequency and/or duty cycle of an astable 555 timer.
5
+ * https://en.wikipedia.org/wiki/555_timer_IC#Astable
6
+
7
+ These functions take in the value of the external resistances (in ohms)
8
+ and capacitance (in Microfarad), and calculates the following:
8
9
9
10
-------------------------------------
10
11
| Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz
11
12
-------------------------------------
12
13
where Freq is the frequency,
13
- R1 is the first resisitance ,
14
- R2 is the second resistance,
15
- C1 is the capacitance
14
+ R1 is the first resistance in ohms ,
15
+ R2 is the second resistance in ohms ,
16
+ C1 is the capacitance in Microfarads.
16
17
17
18
------------------------------------------------
18
19
| Duty Cycle = (R1 + R2) / (R1 + 2 x R2) x 100 | ... in %
19
20
------------------------------------------------
20
- where R1 is the first resisitance,
21
- R2 is the second resistance,
22
-
21
+ where R1 is the first resistance in ohms,
22
+ R2 is the second resistance in ohms.
23
23
"""
24
24
25
25
@@ -36,17 +36,15 @@ def astable_frequency(
36
36
Traceback (most recent call last):
37
37
...
38
38
ValueError: All values must be positive
39
- >>> astable_frequency(resistance_1=0 , resistance_2=0 , capacitance=2 )
39
+ >>> astable_frequency(resistance_1=45 , resistance_2=45 , capacitance=0 )
40
40
Traceback (most recent call last):
41
41
...
42
42
ValueError: All values must be positive
43
43
"""
44
44
45
45
if resistance_1 <= 0 or resistance_2 <= 0 or capacitance <= 0 :
46
46
raise ValueError ("All values must be positive" )
47
- else :
48
- frequency = (1.44 / ((resistance_1 + 2 * resistance_2 ) * capacitance )) * 10 ** 6
49
- return frequency
47
+ return (1.44 / ((resistance_1 + 2 * resistance_2 ) * capacitance )) * 10 ** 6
50
48
51
49
52
50
def astable_duty_cycle (resistance_1 : float , resistance_2 : float ) -> float :
@@ -68,11 +66,7 @@ def astable_duty_cycle(resistance_1: float, resistance_2: float) -> float:
68
66
69
67
if resistance_1 <= 0 or resistance_2 <= 0 :
70
68
raise ValueError ("All values must be positive" )
71
- else :
72
- duty_cycle = (
73
- (resistance_1 + resistance_2 ) / (resistance_1 + 2 * resistance_2 ) * 100
74
- )
75
- return duty_cycle
69
+ return (resistance_1 + resistance_2 ) / (resistance_1 + 2 * resistance_2 ) * 100
76
70
77
71
78
72
if __name__ == "__main__" :
0 commit comments