我是Arduino编程的新手,正在尝试将arduino uno用作高分辨率计时器。我希望能够在两个上升沿中断之间以完整的16MHz速率计数时钟周期。我有一些代码可以使用具有4微秒分辨率的micros()函数来工作,而我需要的更好。这是我尝试使用micros()进行计时的示例代码:
volatile int k = 0;
volatile float t1 = 0;
volatile float t2 = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(2), ISR1, RISING);
attachInterrupt(digitalPinToInterrupt(3), ISR2, RISING);
}
void ISR2()
{
k = 1;
t1 = micros();
Serial.println(1);
}
void ISR1()
{
k = 2;
t2 = micros();
Serial.println(2);
}
void loop()
{
if (t1 != 0 && t2 != 0) {
if (t2 - t1 < 0) {
t1 = …Run Code Online (Sandbox Code Playgroud) arduino ×1