gpt4 book ai didi

c++ - 在 Teensy 3.6 上使用 ADC

转载 作者:行者123 更新时间:2023-11-28 04:06:34 25 4
gpt4 key购买 nike

我正在尝试将我在 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
^

最佳答案

Arduino Mega 的 MCU 是 ATmega2560,而 Teensy 3.6 的是 Arm Cortex M4。

ADCSRA 和 ATmega2560 的类似缩写地址寄存器在 Arm Cortex M4 上什至不存在。这是一个完全不同的架构。

关于c++ - 在 Teensy 3.6 上使用 ADC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58618133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com