ADS1115 frequency help

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
rouse217
 
Posts: 5
Joined: Wed Dec 12, 2012 5:37 pm

ADS1115 frequency help

Post by rouse217 »

Hi,

I'm attempting to run the ADS1115 16-bit ADC device from the RPi over i2c. I've got a sample loop that iterates 2000 times and acquires the single-ended data from one channel. The total cycle (2000 iterations) takes approximately 6 seconds. This is much slower than I was expecting--for example, I've also set up a similar program acquiring data from an IMU over i2c, which can collect 6 channels of data 2000 times in about 0.5 seconds. If I get values from another single-ended channel, it takes twice as long.

Basically, in each iteration of the loop, it calls adc.readADCSingleEnded from the Adafruit ADC1x15 library (and sample code).

Can anyone tell me why this is taking so long? I'm expecting similar performance as from the IMU.

Thanks very much!

-Elliott

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: ADS1115 frequency help

Post by adafruit »

the max sample rate of the ADX1115 us 860 HZ - and RPi isn't terribly fast either at dealing with real-time data, you've got lots going on in the background with the OS. If you want faster reads, go with the ADS1015, an embedded system or a $500 DAQ board

rouse217
 
Posts: 5
Joined: Wed Dec 12, 2012 5:37 pm

Re: ADS1115 frequency help

Post by rouse217 »

Right--so if I was actually getting 860 Hz, that would be fine. But I'm currently getting ~110 Hz. I will go with the ADS1015, if necessary, but I'd really like the 16-bit version if we can swing it. Also, the IMU that I'm using has no trouble iterating quite fast (~4000 Hz) with the same overhead.

An industrial DAQ board is not an option for this application.

Any thoughts on how I can get the 860 Hz on the RPi? It seems like it should be possible...

Thanks,

-Elliott

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: ADS1115 frequency help

Post by adafruit »

2000 reads in 6 seconds is 350 Hz, not 110 Hz.

you can try changing the sleep delay(), please read the python library code for more details on how the process works, but if you dont delay enough, you wont get good readings. check the datasheet for tons of details about the ads1115/1015. we dont have plans to try and speed up within the next few weeks, no ETA as to when we will revisit this code

Our suggestion: If you need high speed precision ADC reads on the Pi, we suggest working with a software engineer and or embedded engineer to design your project. this stuff is not easy and our pi python code is intended to get you up and running and verify the hardware works! :)

rouse217
 
Posts: 5
Joined: Wed Dec 12, 2012 5:37 pm

Re: ADS1115 frequency help

Post by rouse217 »

Update: The i2c bus was maxed out. I've streamlined the Adafuit code and now I have the ADC sampling all four single-ended channels running at ~350 Hz. This is pretty good since all my previous statements were only sampling one channel. Here's what I did to speed things up:

1) Modify Adafruit_ADS1x15.py to include the data rate of 860 SPS (config bits 7:5). This code should be added to line number ~63: __ADS1015_REG_CONFIG_DR_860SPS = 0x00E0. Then when setting the config bits, use this.

2) Define a new function that reads the single ended values without writing to the config register. Writing to the config register includes four extra bytes that don't need to be sent every time, only set once. The Adafruit function readADCSIngleEnded writes to the config register each time, thereby clogging the bus if you want to sample quickly.

I'll upload my revised version of ADS1x15 for use with the ADS1115 shortly.

-Elliott

rouse217
 
Posts: 5
Joined: Wed Dec 12, 2012 5:37 pm

Re: ADS1115 frequency help

Post by rouse217 »

Modified Adafruit_ADS1x15.py

New function added: readADCSingleEnded_noConfig

It can be called in the same way readADCSingleEnded is called, however no configuration bytes are sent. It's a good idea to call the original readADCSingleEnded first if you're modifying from the default parameters.

-Elliott
Attachments
Adafruit_ADS1x15.txt
Added new function to get single ended channels w/o setting config regs
(7.32 KiB) Downloaded 279 times

rouse217
 
Posts: 5
Joined: Wed Dec 12, 2012 5:37 pm

Re: ADS1115 frequency help

Post by rouse217 »

Update: By using

Code: Select all

$ sudo modprobe -r i2c_bcm_2708 && sudo modprobe i2c_bcm2708 baudrate = 1000000
I am able to increase the i2c frequency to 1MHz. With this bus frequency, I am able to get speeds of almost ~1kHz when sampling from all four channels of the ADS1115.

This is exactly what I was hoping it would do.

Hope this helps others!

-Elliott

randomvibe
 
Posts: 57
Joined: Tue Jan 24, 2012 7:26 am

Re: ADS1115 frequency help

Post by randomvibe »

Will adafruit confirm rouse217 enhancements regarding ADS1115 effective sample rate on the r-pi?

If it works at ~1khz as suggested, adafruit should officially update the ADC1x15 library to live up to the "860 samples/second" claim on your ad.

Thanks.

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: ADS1115 frequency help

Post by adafruit_support_bill »

Hi randomvibe. The 860 samples/sec max is from the manufacturer's spec sheet. The conversion rate is controlled by an internal clock, not the python code that talks to it. You may be able to read from it faster than 860 Hz, but some of those readings will be duplicates.
http://adafruit.com/datasheets/ads1115.pdf
The ADS1113/4/5 can perform conversions at rates up to 860 samples per second (SPS).

randomvibe
 
Posts: 57
Joined: Tue Jan 24, 2012 7:26 am

Re: ADS1115 frequency help

Post by randomvibe »

If adafruit can ensure the R-Pi read faster than 860hz as suggested by rouse217, that will enable customers to integrate other sensors with faster sampling. Why limit the R-Pi and your python library to such low speeds when it's capable of more, much more.

All I'm asking for is a verification of findings made by rouse217, and update your libraries for the benefit of all your customers, the ones who helped you become Entrepreneur of 2012.

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: ADS1115 frequency help

Post by adafruit_support_bill »

If adafruit can ensure the R-Pi read faster than 860hz as suggested by rouse217
Randomvibe. Please read my previous post (and the manufacturer's spec sheet) carefully. You cannot make the ADS1115 sample any faster than 860Hz. This is a hardware limitation and has nothing to do with the drivers or libraries.

Reading from the device faster than the device is actually sampling will only give you redundant stale values and waste valuable processor time.

randomvibe
 
Posts: 57
Joined: Tue Jan 24, 2012 7:26 am

Re: ADS1115 frequency help

Post by randomvibe »

adafruit_support wrote:
You cannot make the ADS1115 sample any faster than 860Hz. This is a hardware limitation and has nothing to do with the drivers or libraries.
With all due respect, you did not read my last post carefully. As I said before, "other sensors" beyond ADS1115 may not be limited to 860hz. Right now, rouse217 found that the R-Pi & library sample at ~110hz - that's worse than your cheapest Arduino. rouse217 also found enhancements to the library that may increase the sampling rate. I'm just asking if you may verify those findings and update your library for the benefit of your customers. Thank you.

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: ADS1115 frequency help

Post by adafruit_support_bill »

The code posted only works for channel 0 (the channel parameter is ignored). And since it does not wait for the conversion to complete, it will not work properly if expanded to handle multiple channels.

randomvibe
 
Posts: 57
Joined: Tue Jan 24, 2012 7:26 am

Re: ADS1115 frequency help

Post by randomvibe »

adafruit_support wrote:And since it does not wait for the conversion to complete, it will not work properly if expanded to handle multiple channels.
Thank you for the check.

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”