I am using the MEGA2560 to measure a 4V pk-pk sine wave (2.5V DC offset) and a smaller DC sine wave from a shunt. I use the analogRead function for both and then post process the array to determine the frequency. My problem is time. I timed the analog read by adding a digitalWrite toggle at the beginning and ending of the reads and found the readings took between .07-.1ms. The variation kills my accuracy as my sample rate is significant compared to that number. I am an amateur programmer. Is this a problem I can solve using the timer or do I need to strap on my big boy pants and figure out how to use interrupts?
//Record Data
for(i = 0; i < arraysize; i++)
{
VoltageArray[i] = analogRead(9);
CurrentArray[i] = analogRead(10);
TimeArray[i] = time;
time = time + 0.00024; // This is amount of time for the delay and approximate time of both analog reads
delay(.1);
}