|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+//! Calculator for hardware debouncing using an RC filter as described in
|
|
|
2
|
+//! https://my.eng.utah.edu/~cs5780/debouncing.pdf.
|
|
|
3
|
+
|
|
|
4
|
+use std::io::{self, Write};
|
|
|
5
|
+
|
|
|
6
|
+fn main() {
|
|
|
7
|
+ let supply = read_float("supply voltage [V]:");
|
|
|
8
|
+ let high = read_float("high input threshold voltage [V]:");
|
|
|
9
|
+ let low = read_float("low input threshold voltage [V]:");
|
|
|
10
|
+ let leakage = read_float("max. leakage [uA]:") * 0.000001;
|
|
|
11
|
+ let time = read_float("debounce time [ms]:") * 0.001;
|
|
|
12
|
+
|
|
|
13
|
+ let c = 0.0000001; // 0.1uF
|
|
|
14
|
+ let r_pullup = -time / (c * ((supply - low) / supply).ln());
|
|
|
15
|
+ println!("pullup: {} Ohm", r_pullup);
|
|
|
16
|
+ let r_pulldown = -time / (c * (high / supply).ln());
|
|
|
17
|
+ println!("pulldown: {} Ohm", r_pulldown);
|
|
|
18
|
+}
|
|
|
19
|
+
|
|
|
20
|
+fn read_float(label: &str) -> f64 {
|
|
|
21
|
+ println!("{}", label);
|
|
|
22
|
+ io::stdout().flush().unwrap();
|
|
|
23
|
+
|
|
|
24
|
+ let mut input = String::new();
|
|
|
25
|
+ match io::stdin().read_line(&mut input) {
|
|
|
26
|
+ Ok(_) => input.trim().parse().unwrap(),
|
|
|
27
|
+ Err(error) => panic!("invalid input: {}", error),
|
|
|
28
|
+ }
|
|
|
29
|
+}
|