提升arduino采样速度
普通的 Arduino UNO 的采样速度
基准电压可通过函数 analogReference()
或 ADMUX 寄存器中的 REFS[1:0] 位进行设置。
void setup() {
Serial.begin(9600);
analogReference(INTERNAL); //调用板载1.1V基准源
}
void loop() {
int i;
float voltage;
int sensorValue;
unsigned long elsp=millis();
for (i=0;i<10000;i++)
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
}
Serial.println(millis()-elsp);
delay(10000);
}
运行结果是 1057 左右,就是说采样10000次用时1.057s,采样频率大约是 9,460.73Hz (次/秒)。
提高采样速度
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
void setup() {
S