AnalogRead() and timer

I used the analogRead to collect the value of a sinusoid, through this code:

void setup() { Serial.begin(250400); pinMode(A0, INPUT); }

void loop() {

int a = analogRead(A0); Serial.print(a);

float x = (5.0 / 1023.0) * a; Serial.print(x); }

I have collect the values perfectly but my doubt is at the time, I did not set any time, ie the Arduino automatically set when collected values. I have a arduino uno, and i want to kwon what time arduino use? For example: 0 --0.0001s--- 0.0002s-- 0.0003 or 0---0.001--0.002--0.003

thanks

You can use [u]millis()[/u] or micros() to find the time.

I believe your Serial.print statements will slow down your loop by a lot.

Typically, you'd sample the waveform at a known rate. For example, CD audio is sampled at 44.1kHz. (Take a look at the Blink Without Delay example for how to set up a timer.)

I've never done this, and I don't know if the standard procedure is to use micros() or if a timer interrupt is used.

You can't directly read the negative half of a sine wave. In fact, the Arduino can be damaged by negative voltages. Assuming you feed the sinewave directly into the Arduino, and assuming the Ardunio doesn't die, half of the readings (all of the negative voltages) will be zero.

You should probably use millis() or micros() to manage your timing (see several things at a time). If Serial.print() slows the data collection too much you can collect all the data into an array and then only send it to the PC when you have it all.

How many data points do you want to collect ?

...R