heyspencerb
Member
ADC in free running on Teensy 3.6
Hello, I am trying to port a program I had on an Arduino Mega which takes samples of live music and runs FFT over them. I am hoping to replicate this functionality on the teensy exactly as it was on the Arduino, just much faster, and with more samples. Here is the program as it was on the Arduino:
Can I use analogRead() to get the same effect? How can I port this code over to work the same way? I want to make sure it will still have ADC in free running mode, but the tutorial on this site for that didn't seem to compile for a Teensy 3.6 using Teensyduino. Thank you for any help you can give me!
Hello, I am trying to port a program I had on an Arduino Mega which takes samples of live music and runs FFT over them. I am hoping to replicate this functionality on the teensy exactly as it was on the Arduino, just much faster, and with more samples. Here is the program as it was on the Arduino:
Code:
void setup() {
ADCSRA = 0b11100110; // set ADC to free running mode and set pre-scalar to 32 (0xe5)
ADMUX = 0b00000000; // use pin A0 and external voltage reference
}
void loop() {
// ++ Sampling
for(int i=0; i<SAMPLES; i++)
{
while(!(ADCSRA & 0x10)); // wait for ADC to complete current conversion ie ADIF bit set
ADCSRA = 0b11110101 ; // clear ADIF bit so that ADC can do next operation (0xf5)
int value = ADC - 512 ; // Read from ADC and subtract DC offset caused value
vReal[i]= value/4; // Copy to bins after compressing
vImag[i] = 0;
}
// -- Sampling
}
Can I use analogRead() to get the same effect? How can I port this code over to work the same way? I want to make sure it will still have ADC in free running mode, but the tutorial on this site for that didn't seem to compile for a Teensy 3.6 using Teensyduino. Thank you for any help you can give me!