ADS1299 sample rate / threading
Hi,
can s.o. tell me where and how the sample rate is set in the arduino code? or what is the limiting factor?
i wrote a small c programm to log the raw data without the processing stuff and i measure a fluctuating sample rate of about 243Hz.
I was thinking, the limiting factor is the throughput of the Arduino, but the sample rate did not improve, when i fastened the code in the loop() function.
can s.o. tell me where and how the sample rate is set in the arduino code? or what is the limiting factor?
i wrote a small c programm to log the raw data without the processing stuff and i measure a fluctuating sample rate of about 243Hz.
I was thinking, the limiting factor is the throughput of the Arduino, but the sample rate did not improve, when i fastened the code in the loop() function.
Comments
To set the divider, see the initialize() method of the ADS1299.cpp file in our Arduino library: https://github.com/OpenBCI/OpenBCI/blob/master/Arduino/Libraries/ADS1299/ADS1299.cpp
After the ADS1299 has taken a sample, the ADS1299 pulls the DRDY pin HIGH (or LOW, I can't remember). The software on the Arduino looks for this pin to switch to that state, at which point the Arduino code asks for the sample values from the ADS1299 and pushes them data out over the serial link to the PC.
This "look for the pin to switch" can either be done via an interrupt routine on the Arduino, or it can be done every time through the Arduino's loop() function. I use the loop() function, as can be see in my "ADSManager.isDataAvailable()" call:
https://github.com/OpenBCI/OpenBCI/blob/master/Arduino/Sketches/StreamRawData/StreamRawData.ino
It then gets the data via the line "ADSManager.updateChannelData();". This method is in the ADSManager.cpp library:
https://github.com/OpenBCI/OpenBCI/blob/master/Arduino/Libraries/ADS1299/ADS1299Manager.cpp
Note that, even at the slowest sample rate (250 Hz), it's a lot of data for the Arduino serial link...so you really have to make sure that you set your baud rate high enough.
Hope this helps...
Chip
thanks for your answer.
I've set
#define SCK_MHZ (8)
in ADS1299Manager.h to get a higher SPI speed.
I've also set the sampling rate of the ADS1299 to 500 SPS with this:
ADS1299::WREG(CONFIG1,0b10010101); delay(1);
in the initialize() function.
But I still get only about 243 SPS.
For testing, i changed the Arduino's loop() to these 2 lines:
sampleCounter++;
ADSManager.writeChannelDataAsBinary(MAX_N_CHANNELS,sampleCounter);
and called
startRunning(OUTPUT_BINARY_OPENEEG);
in setup()
So it sends the same (nulled ?) samples as fast as it can.
But still the same incoming SPS on my computer...
Changing the serial baud rate isn't helping, too (i can decrease the sampling rate to 150 by halving the baud rate).
Did you ever try a higher sampling rate than 250 with the Arduino Uno?
Thanks for any help with this!
The fault was at my program, it needed some threading to get all of the data.
https://www.google.com/search?q=eeg+sample+rate+drift
http://www.dtic.mil/get-tr-doc/pdf?AD=ADA561715
Can you say what software you're using? For example, OpenViBE in the Acquisition Server, has the ability to do "drift correction". By dropping or adding samples. I've not looked at the code but this might use some form of interpolation. I don't believe it is doing a complete formal "resampling" (over all samples) by using using spline interpolations, that's slow.
http://openvibe.inria.fr/acquisition-server/
The ADS1299 can also be configured with it's own external clock oscillator; not sure how easy that is, would require some hardware modding. Some other boards we know that use ADS1299 have an external clock. That would give you more accuracy.
re: erratic behavior on long sessions. What you're seeing may correspond to some other reports of long session anomalies,
http://openbci.com/forum/index.php?p=/discussion/324/data-stream-freezes-during-long-sessions
I believe your battery setup is fine there, I use the same Adafruit Powerboost with LiPo cell. It's designed to put out 5.2 V.
http://www.atmel.com/Images/doc8161.pdf
http://openbci.com/forum/index.php?p=/discussion/comment/1932/#Comment_1932
Basically a single LiPo cell at 3.7v would not give you much margin over 3.3v. But when the revised board is available with new regulator, then with two series connected cells (up to 8.4v) should be ok.