我一直在测量阿迪诺号的高度。它会升高,然后保持高的几毫秒。然后,它被拉低1单位,然后浮回高点。我的代码似乎没有意识到这条线被拉得很低。对于中断来说,1U太快了吗?我怎么才能慢下来呢?
谢谢
编辑我的想法是,使用RC滤波器与二极管一起,以减缓上升时间足以让阿尔杜诺识别变化,但只有当变化发生时,从接收线。这可行吗?或者我可以用同样的方式使用带有二极管的脉冲扩展芯片吗?
#define ESC 2 //the digital pin the esc signal line is attached to
int throttlePos = 0;
volatile unsigned long timer_start;
volatile int last_interrupt_time;
volatile int pulse_time;
void setup() {
// put your setup code here, to run once:
pinMode(ESC, OUTPUT); //originally set the ESC's line to output to keep line high ready for throttle armature
digitalWrite(ESC, HIGH); //keep the pulse high due to inverted throttle pulse
Serial.begin(115200); //opens the serial port for use when testing
timer_start = 0;
attachInterrupt(digitalPinToInterrupt(ESC), calcSignal, CHANGE);
for(throttlePos = 0; throttlePos <= 1000; throttlePos += 1) //these for loops arm the ESC by emulating an inverted PWM pulse, process takes two seconds
{
digitalWrite(ESC, LOW);
delayMicroseconds(1500);
digitalWrite(ESC, HIGH);
delayMicroseconds(100);
}
for(throttlePos = 1000; throttlePos <= 2000; throttlePos += 1)
{
digitalWrite(ESC, LOW);
delayMicroseconds(1000);
digitalWrite(ESC, HIGH);
delayMicroseconds(100);
}
}
void loop() {
digitalWrite(ESC, LOW);
delayMicroseconds(1200);
digitalWrite(ESC, HIGH);
delayMicroseconds(100);
delay(19);
Serial.println(pulse_time);
}
void calcSignal()
{
//record the interrupt time so that we can tell if the receiver has a signal from the transmitter
last_interrupt_time = micros();
//if the pin has gone HIGH, record the microseconds since the Arduino started up
if(digitalRead(ESC) == HIGH)
{
timer_start = micros();
}
//otherwise, the pin has gone LOW
else
{
//only worry about this if the timer has actually started
if(timer_start != 0)
{
//record the pulse time
pulse_time = ((volatile int)micros() - timer_start);
//restart the timer
timer_start = 0;
}
}
}

发布于 2016-02-15 16:08:55
1/1U为1 1MHz。考虑到您的Arduino在16 that执行指令(最好是一些指令需要更长的时间),您的中断处理程序可能很容易丢失一些东西。但是,即使中断条件在中断结束之前被清除,中断仍然应该执行。
您是将Arduino库用于中断,还是直接在寄存器级别配置引脚更改中断?
你证实过进入阿杜伊诺的脉搏是电的声音吗?如果不了解更多关于你的电路,就很难提出解决方案。
https://stackoverflow.com/questions/35410904
复制相似问题