Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to improve reading speed. #14

Open
RaulTrombin opened this issue Oct 20, 2023 · 1 comment
Open

How to improve reading speed. #14

RaulTrombin opened this issue Oct 20, 2023 · 1 comment

Comments

@RaulTrombin
Copy link

I'm using this crate to read a ADS1115 sensor on a raspberry pi4.
It's something like follows:

        let dev = I2cdev::new("/dev/i2c-1").unwrap();
        let address = adc_Address::default();
        let adc = Ads1x1x::new_ads1115(dev, address);
        ...
        adc.reset_internal_driver_state();
        adc
            .set_full_scale_range(ads1x1x::FullScaleRange::Within4_096V)
            .unwrap();
        ....    
        pub fn read_adc(&mut self, channel: AdcChannel) -> f32 {
        let conversion_volts: f32 = 0.000_125; // According to data-sheet, LSB = 125 μV for ±4.096 scale register, navigator's default
        block!(self.adc.read(channel.into())).unwrap() as f32 * conversion_volts
    }
       ...
        pub fn read_adc_all(&mut self) -> ADCData {
        ADCData {
            channel: [
                self.read_adc(AdcChannel::Ch0),
                self.read_adc(AdcChannel::Ch1),
                self.read_adc(AdcChannel::Ch2),
                self.read_adc(AdcChannel::Ch3),
            ],
        }
    }

Actually to read a single channel (SingleA0) , all ( A0..A4), I've something like:

read_adc                time:   [9.9452 ms 9.9682 ms 9.9893 ms]
read_adc_all            time:   [39.947 ms 40.032 ms 40.107 ms]

adding a self.adc.set_data_rate(DataRate16Bit::Sps860).unwrap();
It was improoved like follows:

`read_adc                time:   [3.0672 ms 3.0759 ms 3.0840 ms]
                        change: [-69.244% -69.143% -69.034%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 23 outliers among 100 measurements (23.00%)
  17 (17.00%) low severe
  1 (1.00%) low mild
  4 (4.00%) high mild
  1 (1.00%) high severe

read_adc_all            time:   [12.350 ms 12.375 ms 12.409 ms]
                        change: [-69.174% -69.086% -68.976%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 23 outliers among 100 measurements (23.00%)
  14 (14.00%) low severe
  1 (1.00%) low mild
  3 (3.00%) high mild
  5 (5.00%) high severe`

Can I reach more faster data for the 4 channels?

@RaulTrombin
Copy link
Author

RaulTrombin commented Oct 20, 2023

Changing it to continuos mode I reached near 1ms now,

Ads1x1x::new_ads1115(dev, address).into_continuous().ok().unwrap();();

Should I discard the first lecture ?

`    pub fn read_adc(&mut self) -> f32 {
        let conversion_volts: f32 = 0.000_125; // According to data-sheet, LSB = 125 μV for ±4.096 scale register, navigator's default]
        self.adc.select_channel(&mut ads1x1x::channel::SingleA0).unwrap();
        self.adc.read().unwrap() as f32 * conversion_volts
    }`
read_adc                time:   [952.43 µs 955.02 µs 957.28 µs]
                        change: [-69.097% -68.695% -67.807%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 25 outliers among 100 measurements (25.00%)
  15 (15.00%) low severe
  3 (3.00%) low mild
  3 (3.00%) high mild
  4 (4.00%) high severe

The continuous mode lecture does not wait till a new value measurement, i don't have the RDY pin in use to prevent this, ignore this last report.

The faster I have actually is the 3.0759 ms on one-shot mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant