瀏覽代碼

Added a debounce resistor value calculator.

Mathias Gottschlag 5 年之前
父節點
當前提交
23e6e6bdb7
共有 3 個文件被更改,包括 43 次插入0 次删除
  1. 5
    0
      other/debounce-calculator/Cargo.lock
  2. 9
    0
      other/debounce-calculator/Cargo.toml
  3. 29
    0
      other/debounce-calculator/src/main.rs

+ 5
- 0
other/debounce-calculator/Cargo.lock 查看文件

@@ -0,0 +1,5 @@
1
+# This file is automatically @generated by Cargo.
2
+# It is not intended for manual editing.
3
+[[package]]
4
+name = "debounce-calculator"
5
+version = "0.1.0"

+ 9
- 0
other/debounce-calculator/Cargo.toml 查看文件

@@ -0,0 +1,9 @@
1
+[package]
2
+name = "debounce-calculator"
3
+version = "0.1.0"
4
+authors = ["Mathias Gottschlag <mgottschlag@gmail.com>"]
5
+edition = "2018"
6
+
7
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
+
9
+[dependencies]

+ 29
- 0
other/debounce-calculator/src/main.rs 查看文件

@@ -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
+}

Loading…
取消
儲存