Go Down

Topic: How to increase sampling rate on 16 channel ADC of Arduino1280 (Read 2554 times) previous topic - next topic

I'm new for Arduino and I'm sorry if i posted wrong topic in this spot.

I have a problem on my project that is I want to use all 16 channels on ADC of Arduino 1280. Each channel should received around 1,000 sampling rate for sending to serial port interfacing with computer.

I also use the prescale but it's still not good sampling rate. I got maximum sampling rate with these 16 channels on 10 bit around 120 sampling rate on each channel that's far from my goal (1,000 sampling rate on each channel).

How do I increase my sampling rate without decreasing the number of bit(I want to use 10 bit). This model can do that?

This is my code.

--------------------------------------------------------------------
#define FASTADC 1

// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

void setup() {
  #if FASTADC
  // set prescale to 16
  sbi(ADCSRA,ADPS2) ;
  cbi(ADCSRA,ADPS1) ;
  cbi(ADCSRA,ADPS0) ;
  #endif
  Serial.begin(115200);
}

void loop() {
  Serial.print("time = ");Serial.print(millis());
  Serial.print(",  ");
  Serial.print(analogRead(A0));Serial.print("  ");
  Serial.print(analogRead(A1));Serial.print("  ");
  Serial.print(analogRead(A2));Serial.print("  ");
  Serial.print(analogRead(A3));Serial.print("  ");
  Serial.print(analogRead(A4));Serial.print("  ");
  Serial.print(analogRead(A5));Serial.print("  ");
  Serial.print(analogRead(A6));Serial.print("  ");
    Serial.print(analogRead(A7));Serial.print("  ");
    Serial.print(analogRead(A8));Serial.print("  ");
    Serial.print(analogRead(A9));Serial.print("  ");
    Serial.print(analogRead(A10));Serial.print("  ");
    Serial.print(analogRead(A11));Serial.print("  ");
    Serial.print(analogRead(A12));Serial.print("  ");
    Serial.print(analogRead(A13));Serial.print("  ");
    Serial.print(analogRead(A14));Serial.print("  ");
  Serial.println(analogRead(A15));Serial.print("  ");
}
--------------------------------------------------------------------



gardner

The 115,200 bps serial line is your bottleneck.  115,200 bps is 11,520 charcters per second.  Your code is writing about 4 or 5 characters per reading, which means 2,560 reading per second.  With 16 lines, you are going to get about 160 readings per line per second.

CrossRoads

Section 21 of the ATMega datasheet discusses the settings needed for higher data rates.
You may have to dig into the code to figure out how to change those settings.
That still doesn't guarantee you can pull the data from ADC and format it for sending out fast enough to obtain the faster rates.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

WillR

Use of the Serial and delay functions slow down the collection enormously. This also applies to using the SD card on the Ethernet Shield for storage where this is very critical.

With this type of work the more you "observe" your results the worse they are.

The "uncertainty principle" at work -- the very act of observing changes the result.

Just another Hacker

FransK

I came across the Teensy microcontroller http://www.pjrc.com/teensy/, which is like, but not quite compatible with, Arduino. There is a plug-in for the Arduino IDE to use it for development.

Rather then using a serial emulation for communication with the host (with several limitations), it uses native USB and can (theoretically) operate at full USB-2 speed.
The software library allows you to program the Teensy to act like one of many standard USB devices (keyboard, mouse, HID, midi, storage, ... ), thus using the default host driver.

A few weeks ago I bought one, but have not used it yet. All I can tell is that uploading the morse-blinking demo from it's tutorial was blazingly fast. Setting it up under openSuse 11.3 linux gave no problem at all (quite different from Arduino).

One type has 12 analog channels, the other 8, so you might end up using 2 controllers. You can connect these using I2C as it uses diffferent pins then the host USB connection.

Go Up