Hello all,
If the Arduino is sequential processing, how do i calculate the true sampling speed of the ADC?
The arduino that i am using is the Arduino MEGA 2650 and have attached my code below
Do i calculate the length of time between each conversion and incorporate this into the speed?
The number of lines that will be executed is 6 between each ADC conversion. This I believe amounts to 6 instruction samples. 1 instruction sample is about 62.5ns. To run 6 instruction cycles would take 375ns. (and i am stuck here)
#include <SPI.h>
#include <string.h>
int val,k=0;
float sample=0;
int x=4000, i=0;
float temp,Vx,Vin,Vout,Vactual;
String c;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
}
float squared_voltage,sum_squared_voltage, mean, rms, rms1, Zmag;
int n;
void loop() {
// put your main code here, to run repeatedly:
for(n=0; n<500; n++)
{
temp = analogRead(A0);
Vactual = measure(temp); // this line converts the temp into the real actual value. You should test this piece with your circuit.
sample = Vactual;
squared_voltage = sample * sample;
sum_squared_voltage += squared_voltage;
}
mean = sum_squared_voltage/500.0;
rms = sqrt(mean);
sum_squared_voltage=0;
// Serial.println(rms);
for(n=0; n<500; n++)
{
temp = analogRead(A1);
Vactual = measure(temp); // this line converts the temp into the real actual value. You should test this piece with your circuit.
sample = Vactual;
squared_voltage = sample * sample;
sum_squared_voltage += squared_voltage;
}
mean = sum_squared_voltage/500.0;
rms1 = sqrt(mean);
sum_squared_voltage=0;
Zmag = (rms/rms1)*9902;
String to_string(Zmag);
Serial.write(int(Zmag));
}
float measure(int adc_value){
Vx = (adc_value/1023.0)*5;
// Serial.println(Vx,5);
Vin = (Vx - 2.111)*(118.0/18.0);
// Serial.println(Vin,8);
return Vin;
}