I'm using an ADS1115 to digitize data in my project. After sorting out a few issues with the ADS1x15 library, the basic system works if i do a single conversion read data in the "Loop" section of the code.
I need more precise timing on the sampling rate. One option is to run the ADS1115 in continuous conversion mode and catch a interrupt from the Alert/Rdy pin, and read the value. According to TI data sheet, there will be an 8 uS pulse to signal the conversion is complete. So far no luck to get an ISR working.
Another option I considered is using a timer interrupt every 4mS to trigger a single conversion read from the ADS1115. I tried using TimerOne library, but all attempts cause the Arduino to hang when I try to read the ADC.
Any suggestions or sample code would be appreciated.
The original Adafruit_ADS1x15 library that I downloaded, looked like the code was intended primarily for the ADS1015 chip. The constants ...REG_CONFIG_DR... were only defined for ADS1015, so I added constants specifically for ADS1115. Also, in the method readRegister, it was hard coded for the CONVERSION register even though the parameter "reg" was passed as a parameter.
I added a couple more methods:
startContinuousADC_differential_0_1() -- Setup the ADC for continuous conversions, this seems to work
getLow(); -- Read the Low Threshold register, to debug that register has the expected value
getHigh() -- Read the High Threshold register, to debug that the register has the expected value
So far,I don't get the expected values back. Perhaps the source of my problem.
According to the TI datasheet for ADS1115, to setup the ALERT/RDY pin, you need to set:
MSB of the high threshold register = 1
MSB of the low threshold register = 0
COMP_POL bit continues to function ... I set to default, Active Low
COMP_QUE bits can disable the pin .... I set COMP_QUE bits = 00, Assert after one conversion
COMP_MODE ... no longer controls any function
COMP_LAT ... no longer controls any function
Pullup resister used as stated in the data sheet
My idea was to catch the 8 uS pulse on the Alert/Ready pin and trigger an interrupt to read the ADC value for constant sampling rate 250 SPS. (every 4mS). Eventually I want to save the ADC values to an SD card. I have some concerns that 4mS may not be enough time to write to the SD card and be ready for the next sample. Any thoughts on this are appreciated.
Currently when I run the sketch, the ARDUINO just hangs.
My main routines are attached. Any comments are appreciated.....
I updated the main routine and uploaded a new copy. The ARDUINO hangs as soon as the sketch is uploaded and begins to run. If I comment out the line "getLastConversionResults(), in the interrupt routine, the program runs.
Thanks, Good catch. Looks like another bug from the original library. In continuous mode, the Conversion register always contains the latest result, so no need to delay for the conversion to complete. I made the correction and it looks like the sketch is running as desired. I appreciate the help.
Les
what was the solution to your problem?
I'm facing the same problem:
In continous mode, using the Adafruit library, the Arduino freezes and i cannot seem to get a value.
Just commenting out the delay in the getLastConversionResults() Method does not solve the problem for me. Any hints?
Its a good idea, when a thread has yielded an answer to your problem, to mark it
as solved (and document the solution if its not already in the thread).