summaryrefslogtreecommitdiffstats
path: root/src/devices/features
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-17 07:51:12 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-17 07:51:12 +0100
commit9d005392012213dc12527b913a9ea4f72b97368c (patch)
treea7636f5dacb56190aaa15f06d2524ed8d6b9c753 /src/devices/features
parent5f58ec2dbf656e9c29e14c28103a87c125797d52 (diff)
downloadads1x1x-async-9d005392012213dc12527b913a9ea4f72b97368c.tar.gz
ads1x1x-async-9d005392012213dc12527b913a9ea4f72b97368c.tar.xz
ads1x1x-async-9d005392012213dc12527b913a9ea4f72b97368c.zip
Add support for setting the full-scale range (PGA)
Diffstat (limited to 'src/devices/features')
-rw-r--r--src/devices/features/tier2.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/devices/features/tier2.rs b/src/devices/features/tier2.rs
index 25b618a..067139a 100644
--- a/src/devices/features/tier2.rs
+++ b/src/devices/features/tier2.rs
@@ -2,8 +2,9 @@
//!
//! These are the features included only in ADS1x14, ADS1x15
-use { Ads1x1x, Error, interface, ic, ComparatorMode, ComparatorPolarity,
- ComparatorLatching, ComparatorQueue, Register, BitFlags, conversion };
+use { Ads1x1x, Error, interface, ic, FullScaleRange, ComparatorMode,
+ ComparatorPolarity, ComparatorLatching, ComparatorQueue, Register,
+ BitFlags, conversion };
impl<DI, IC, CONV, MODE, E> Ads1x1x<DI, IC, CONV, MODE>
where
@@ -11,6 +12,25 @@ where
IC: ic::Tier2Features,
CONV: conversion::ConvertThreshold<E>
{
+ /// Set the input voltage measurable range
+ ///
+ /// This configures the programmable gain amplifier and determines the measurable input voltage range.
+ pub fn set_full_scale_range(&mut self, range: FullScaleRange) -> Result<(), Error<E>> {
+ use BitFlags as BF;
+ let config;
+ match range {
+ FullScaleRange::Within6_144V => config = self.config.with_low( BF::PGA2).with_low( BF::PGA1).with_low( BF::PGA0),
+ FullScaleRange::Within4_096V => config = self.config.with_low( BF::PGA2).with_low( BF::PGA1).with_high(BF::PGA0),
+ FullScaleRange::Within2_048V => config = self.config.with_low( BF::PGA2).with_high(BF::PGA1).with_low( BF::PGA0),
+ FullScaleRange::Within1_024V => config = self.config.with_low( BF::PGA2).with_high(BF::PGA1).with_high(BF::PGA0),
+ FullScaleRange::Within0_512V => config = self.config.with_high(BF::PGA2).with_low( BF::PGA1).with_low( BF::PGA0),
+ FullScaleRange::Within0_256V => config = self.config.with_high(BF::PGA2).with_low( BF::PGA1).with_high(BF::PGA0),
+ }
+ self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.config = config;
+ Ok(())
+ }
+
/// Set comparator lower threshold
pub fn set_low_threshold(&mut self, value: i16) -> Result<(), Error<E>> {
let register_value = CONV::convert_threshold(value)?;