Skip to content

Commit

Permalink
Fix millivolts calculation for differential ADC mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Sep 27, 2020
1 parent 9a510ef commit e856a46
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions nrf-hal-common/src/saadc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,19 @@ impl<'a> Channel<'a> {
}

pub fn as_millis(&self, value: i16) -> i32 {
let mode = match self.saadc.ch[self.channel].config.read().mode().variant() {
Mode::SE => 1,
Mode::DIFF => 2,
};

let lsbs = match self.saadc.resolution.read().val().variant() {
Variant::Val(Resolution::_8BIT) => 255i32,
Variant::Val(Resolution::_10BIT) => 1023i32,
Variant::Val(Resolution::_12BIT) => 4095i32,
Variant::Val(Resolution::_14BIT) => 16383i32,
Variant::Val(Resolution::_8BIT) => 256,
Variant::Val(Resolution::_10BIT) => 1024,
Variant::Val(Resolution::_12BIT) => 4096,
Variant::Val(Resolution::_14BIT) => 16384,
_ => unreachable!(),
};
} / mode
- 1;

let gain = match self.saadc.ch[self.channel].config.read().gain().variant() {
Gain::GAIN1_6 => (1, 6),
Expand Down

0 comments on commit e856a46

Please sign in to comment.