I am a newbie with Arduino and I would need some help with ADC. In particular, I connected my Arduino Due with a Microphone from Adafruit and I want to read the values with a sampling frequency equal to 32 kHz, then I want to put in a buffer with 128 elements. I read that the function AnalogRead() is not "fast" enough to my purpose and I should use DMA but I am not confident with it. Could someone help me?
Depending on the manufacturing batch your uc comes from, there is a good chance that you'll have to calibrate the ADC peripheral for decent results. Atmel Application Note Analog-to-Digital Converter in the SAM3S4 details everything you need to make this calibration.
In order to get better results from this peripheral, these rules may apply:
*For conversion of periodic signals, add an RC filter with an RC time constant at least 10 times the frequency of the input signal,
*Select an ADC channel dedicated as a purging input. Connect it to ground through a small resistor (say 100 ohms) and sample that channel in between each channel you are interested in. This ensures that the ADC channel of interest is purged of residual charges between readings. The resistor is important to reduce current flow, but you want it small enough that the capacitor discharges in a reasonable time,
*Oversample and average as much as possible in regard to the sampling frequency you need, the number of enabled ADC channels and the maximum sampling frequency allowed,
*Power the board throughout the jack because the power supply from the USB cable might be very unstable,
*In case you have white noise at the ADC input (usually the case), you can improve 12-bit conversions into 16-bit conversions (see above Atmel Application Note).
*Using a PDC DMA gives you more time to apply results of calibration to a previous buffer of conversions while in parallel another buffer of conversions is filled by the DMA.
Thank you for the quick reply. Could you please tell me the meaning for the following:
TC0->TC_CHANNEL[1].TC_RA = 40; //<******************** Any Duty cycle in between 1 and TC_RC ?