2 releases
0.1.1 | Jun 5, 2024 |
---|---|
0.1.0 | May 20, 2024 |
#174 in Embedded development
87 downloads per month
Used in quadrature-encoder
77KB
1K
SLoC
quadrature-decoder
Pure logic-level implementations of quadrature decoders with support for full-, half- an quad-stepping.
Incremental Decoder
use quadrature_decoder::{FullStep, IncrementalDecoder};
let mut decoder: IncrementalDecoder<...> = Default::default();
// Update the decoder with pulse trains `a` and `b` and handle the result:
match decoder.update(a, b) {
Ok(Some(change)) => println!("Change detected: {change:?}."),
Ok(None) => println!("No change detected."),
Err(error) => println!("Error detected: {error:?}."),
}
// Or, if you only care about correctly detected changes:
if let Some(change) = decoder.update(a, b).unwrap_or_default() {
println!("Change detected: {change:?}.")
}
println!("Decoder is at counter: {:?}.", decoder.counter());
See the examples directory for a more comprehensive example.
Indexed Incremental Decoder
An indexed decoder resets its counter whenever a raising edge is detected on the z
pulse train.
use quadrature_decoder::{IndexedIncrementalDecoder};
let mut decoder: IndexedIncrementalDecoder<...> = Default::default();
// Update the decoder with pulse trains `a`, `b` and `z` and handle the result:
match decoder.update(a, b, z) {
Ok(Some(change)) => println!("Change detected: {change:?}."),
Ok(None) => println!("No change detected."),
Err(error) => println!("Error detected: {error:?}."),
}
// Or, if you only care about correctly detected changes:
if let Some(change) = decoder.update(a, b, z).unwrap_or_default() {
println!("Change detected: {change:?}.")
}
println!("Decoder is at counter: {:?}.", decoder.counter());
See the examples directory for a more comprehensive example.
Decoding Strategies
Full-step Decoding
A full-step decoder is able to detect up to 1 change(s) per quadrature cycle.
use quadrature_decoder::{FullStep, IncrementalDecoder};
let mut decoder: IncrementalDecoder<FullStep> = Default::default();
Half-step Decoding
A full-step decoder is able to detect up to 2 change(s) per quadrature cycle.
use quadrature_decoder::{HalfStep, IncrementalDecoder};
let mut decoder: IncrementalDecoder<HalfStep> = Default::default();
Quad-step Decoding
A full-step decoder is able to detect up to 4 change(s) per quadrature cycle.
use quadrature_decoder::{QuadStep, IncrementalDecoder};
let mut decoder: IncrementalDecoder<QuadStep> = Default::default();
Documentation
Please refer to the documentation on docs.rs.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct,
and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
License
This project is licensed under the MPL-2.0 – see the LICENSE.md file for details.
Dependencies
~150KB