heyspencerb
Member
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. When I tried moving over my code I ran into issues with the ADC. Here is the program as it was on the Arduino:
When I tried to compile the Arduino IDE told me
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. What is this code doing when it says it is "// clear ADIF bit so that ADC can do next operation (0xf5)" and do I need to port this over as well? Thank you for any help you can give me!
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
}
When I tried to compile the Arduino IDE told me
Code:
Teensy_Version: In function 'void setup()':
Teensy_Version:57: error: 'ADCSRA' was not declared in this scope
ADCSRA = 0b11100110; // set ADC to free running mode and set pre-scalar to 32 (0xe5)
^
Teensy_Version:59: error: 'ADMUX' was not declared in this scope
ADMUX = 0b00000000; // use pin A0 and external voltage reference
^
Teensy_Version: In function 'void loop()':
Teensy_Version:106: error: 'ADCSRA' was not declared in this scope
while(!(ADCSRA & 0x10)); // wait for ADC to complete current conversion ie ADIF bit set
^
Teensy_Version:107: error: 'ADCSRA' was not declared in this scope
ADCSRA = 0b11110101 ; // clear ADIF bit so that ADC can do next operation (0xf5)
^
Teensy_Version:108: error: 'ADC' was not declared in this scope
int value = ADC - 512 ; // Read from ADC and subtract DC offset caused value
^
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. What is this code doing when it says it is "// clear ADIF bit so that ADC can do next operation (0xf5)" and do I need to port this over as well? Thank you for any help you can give me!