Hello Arduino Forum, though I've used PIC uC for a year, but I'm very new to Arduino, and in fact this is my first forum post.
My project with Arduino UNO is an PC oscilloscope, the serial communication handling, plotting results and other data analysis is performed by Wolfram Mathematica. I'm almost done but I've a few questions:
I've tried to maximize the sampling speed by setting prescaler to 16 and storing 300 samples and their acquisition time in two integer arrays. And then Arduino sends the stored the data via serial com which takes about 300ms. While the data being sent via serial, no ADC operation is performed. Is there any way to multitask these two without loosing the sampling rate?
int inByte=0;
unsigned int time[300];
unsigned int sample[300];
unsigned long timeStart;
void setup()
{
// running with high speed clock (set prescale to 16)
bitClear(ADCSRA,ADPS0) ;
bitClear(ADCSRA,ADPS1) ;
bitSet(ADCSRA,ADPS2) ;
Serial.begin(115200);
}
void loop()
{
if(Serial.available()>0)
{
inByte = Serial.read()-'0'; //convert to char data type
if (inByte>=0 && inByte<=9)
{
timeStart = micros();
for(int j=0; j<300; j++)
{
delayMicroseconds(100);
time[j] = (int)(micros()-timeStart) ;
sample[j] = analogRead(A0);
}
timeStart = micros();
for(int k=0; k<300; k++)
{
//Serial.print(k);
if (k==0)
{
Serial.print("{");
}
Serial.print("{");
Serial.print(time[k]);
Serial.print(",");
Serial.print(sample[k]);
Serial.print("}");
//Serial.print("\n");
if (k==299)
{
Serial.print("}");
}
else
{
Serial.print(",");
}
}
Serial.print(micros()-timeStart);
Serial.print("E");
Serial.print("\n");
}
}
}