I've been using the Arduino_AdvancedAnalog (version 1.3) library to create a low-cost digital oscilloscope. I'm having a problem when I try to sample two signals at the same time. First I tried just binding both pins to the same ADC which is shown in examples like ADC_Multi example. This shows great synchronization in time between the two inputs, but it cuts the sample rate in half. When you sample from a pair of pins at sample rate R, each pin is sampled half the time, so the effective rate is R/2.
Next I tried binding each pin to a separate ADC. Like this.
result=adc_input[0].begin(res, sample_rate, num_samples, QUEUE_DEPTH,1,&(probes[0]));
if(num_pins==2)
{
result=adc_input[1].begin(res, sample_rate, num_samples, QUEUE_DEPTH,1,&(probes[1]));
}
The problem now is that the begin routine is so long (checking this, checking that, assigning it to an available ADC module etc.) that there is a 5us lag time between the two sampled signals.
Would it make sense to have a way to set up the ADC without starting it, and then when both ADCs are set up, be able to pull the trigger on both more quickly?
I tried doing this by breaking up the begin routine into a load() and fire(), but could not get the right behavior. Clearly there is something I'm missing about how the DMA and ADC's are being intiailized.
Any thoughts? Ideas on how to synchronize the sampling two analog inputs without sacrificing sample rate?