我正在尝试将我在 Arduino Mega 上创建的程序移植到 Teensy 3.6 上。我使用我找到的一段代码对音频信号进行采样,然后对其进行快速傅立叶变换,但现在我正在移植它,Teensy 不接受他们在 Arduino 上收集音频样本的方式。我可以使用 AnalogRead 来获得相同的效果吗?我怎样才能移植这段代码以同样的方式工作?当它说它是“//清除 ADIF 位以便 ADC 可以执行下一个操作 (0xf5)”时,这段代码在做什么,我是否也需要将它移植过来?谢谢
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
}
此代码在 Arduino Mega 上完美运行,但 Teensy 给了我错误:
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
^