Reputation: 27
I'm currently writing a Library for the ADC of the SAMD21G18. Everything works so far. But when I enable the Freerunning mode of the ADC with 1024 Samples the results differ from what I expect. Here is the code:
#include "ADC_MC.h"
#define Serial SerialUSB
ADC_MC adc;
void setup() {
Serial.begin(9600);
adc.init();
adc.set_SETTINGS(0x05, INT1V, SAMPLENUM_1024, GAIN_2x);
adc.set_FREERUN(true);
adc.enable();
}
void loop() {
int t1 = 0;
int value;
t1 = micros();
value = adc.get_result();
Serial.print("FREE T:" + String(micros() - t1) + " ");
Serial.print(value);
Serial.print("\t");
//Serial.println(adc.get_ADC_SAMPLENUM());
t1 = micros();
value = adc.readPin_once(0x05, INT1V, SAMPLENUM_1024, GAIN_2x);
Serial.print("1024S T:" + String(micros() - t1) + " ");
Serial.print(value);
Serial.print("\t");
t1 = micros();
value = adc.readPin_once(0x05, INT1V, SAMPLENUM_4, GAIN_2x);
Serial.print("4S T:" + String(micros() - t1) + " ");
Serial.print(value);
Serial.print("\n");
t1 = micros();
adc.set_SETTINGS(0x05, INT1V, SAMPLENUM_1024, GAIN_2x);
adc.set_FREERUN(true);
adc.enable();
delay(500);
}
The output is like this:
FREE T:12 3803 1024S T:19755 3806 4S T:105 3803
FREE T:12 3803 1024S T:19758 3805 4S T:105 3801
FREE T:12 3803 1024S T:19753 3805 4S T:105 3802
FREE T:11 3803 1024S T:19756 3805 4S T:105 3805
FREE T:12 3803 1024S T:19761 3805 4S T:105 3801
It appears that the result of the freerun is like the 4 Samples and not the 1024. Is there a max samplerate in the freerunning mode? If I check the current samplerate in freerunning it returns 1024 and looking at the amount of time it takes for one measurement in freerunning mode (~19733) it appears like its 1024. So why the discrepancy?
Upvotes: 0
Views: 22