在Teensy 3.6上使用ADC

问题描述 投票:0回答:1

我正在尝试将我在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
               ^
c++ arduino sampling adc teensy
1个回答
1
投票

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

ADCSRA和ATmega2560的类似缩写地址寄存器,甚至在Arm Cortex M4上也不存在。那是完全不同的架构。

© www.soinside.com 2019 - 2024. All rights reserved.