Regarding my last post, can anyone explain to me why the Teensy's ADC is slower than the UNO?
The Atmega328 ADC needs 13 clock cycles for a conversion. Even at the (unsupported) highest possible ADC clock of 4MHz that only means about 300Ksps. The highest clock speed that is still relatively close to spec is 1MHz so that's about 77Ksps.
But the details are complex, as explained on that instructibles page, and in this thread. You can't simply read a complex discussion of technical details and find the largest number on the page and wish for that number to be the actual performance of the ADC.
void ADC_Module::enablePGA(uint8_t gain) {
#if defined(__MK20DX256__)
if (calibrating) wait_for_cal();
uint8_t setting;
if(gain <= 1) {
setting = 0;
} else if(gain<=2){
setting = 1;
} else if(gain<=4){
setting = 2;
} else if(gain<=8){
setting = 3;
} else if(gain<=16){
setting = 4;
} else if(gain<=32){
setting = 5;
} else { // 64
setting = 6;
}
*ADC_PGA = ADC_PGA_PGAEN | ADC_PGA_PGAG(setting);
pga_value=1<<setting;
#endif
}
Pin: 17 = 3.3000000v FFT: - 0.02 - 0.01 0.01 0.02 0.01 0.01 - 0.03 - 0.01 - 0.03 0.02 - - - - 0.01 - 0.03 0.01 - 0.02 0.01 0.02 0.01 0.02 - 0.02 - 0.03 0.02 0.01 0.03 0.01 0.01 0.01 -
Pin: 17 = 3.3000000v FFT: 0.02 - 0.02 0.02 0.02 0.01 0.01 0.02 0.03 0.02 0.01 0.02 0.02 0.02 0.03 - 0.01 0.01 0.03 0.02 0.02 0.02 - - 0.01 0.01 0.02 - - 0.02 0.01 - 0.02 0.02 - 0.02 0.01 - 0.01 -
#include <ADC.h>
ADC *adc = new ADC();
volatile int elapsed;
volatile int count;
void setup()
{
Serial.begin(38400);
adc->setAveraging(10);
adc->setResolution(12);
adc->setConversionSpeed(ADC_HIGH_SPEED);
adc->setSamplingSpeed(ADC_VERY_HIGH_SPEED);
adc->analogReadContinuous(ADC_0);
}
void loop()
{
elapsedMicros elapsed;
while (elapsed <= 10)
{
adc->analogReadContinuous(ADC_0);
count++;
}
Serial.println(count);
count=0;
delay(5000);
}
#include <ADC.h>
ADC *adc = new ADC();
const int readPin = A9;
int elapsed;
int count;
int value;
void setup()
{
Serial.begin(38400);
pinMode(readPin, INPUT);
adc->setAveraging(10);
adc->setResolution(12);
adc->setConversionSpeed(ADC_HIGH_SPEED);
adc->setSamplingSpeed(ADC_VERY_HIGH_SPEED);
adc->startContinuous(readPin, ADC_0);
adc->analogReadContinuous(ADC_0);
}
void loop()
{
elapsedMicros elapsed;
while (elapsed <= 10)
{
value = adc->analogReadContinuous(ADC_0);
count++;
}
Serial.println(count);
count=0;
delay(5000);
}
#include <ADC.h>
ADC *adc = new ADC();
const int readPin = A9;
int elapsed;
int count;
int value;
void setup()
{
Serial.begin(38400);
pinMode(readPin, INPUT);
adc->setAveraging(10);
adc->setResolution(12);
adc->setConversionSpeed(ADC_HIGH_SPEED);
adc->setSamplingSpeed(ADC_VERY_HIGH_SPEED);
adc->startContinuous(readPin, ADC_0);
adc->analogReadContinuous(ADC_0);
}
void loop()
{
elapsedMicros elapsed;
while (elapsed <= 2)
{
value = adc->analogReadContinuous(ADC_0);
count++;
}
Serial.print(value); Serial.print(" -> ");
Serial.println(count);
count=0;
delay(5000);
}
Sorry im just puzzled as to why your trying to run an AC motor with a 100Khz loop? The fastest control loop I have seen at work was around 20Khz loop to spin a generator(they used as a motor on the Buckeye Bullet 3) to 10K rpm.