忽略时间范围内的中断arduino(低通滤波器)

忽略时间范围内的中断arduino(低通滤波器),arduino,interrupt,Arduino,Interrupt,我试图将中断附加到信号(PWM)的上升沿。但是,当信号处于高位时,会有一些噪声,这会导致代码在不应该的情况下记录另一个中断。很明显,我试图在我的电路中解决这个问题,但不太有效,所以我转到了软件部分 问题是如何在给定的频率范围内过滤掉中断?我需要应用一个低通滤波器,以便在信号为高时不会触发中断。我的想法是在给定的时间内分离中断,或者在特定的时间范围内忽略中断 我只是不知道如何做到这一点 这是我的代码: unsigned long tsend = 0; unsigned long techo = 0

我试图将中断附加到信号(PWM)的上升沿。但是,当信号处于
高位时,会有一些噪声,这会导致代码在不应该的情况下记录另一个中断。很明显,我试图在我的电路中解决这个问题,但不太有效,所以我转到了软件部分

问题是如何在给定的频率范围内过滤掉中断?我需要应用一个低通滤波器,以便在信号为
高时不会触发中断。我的想法是在给定的时间内分离中断,或者在特定的时间范围内忽略中断

我只是不知道如何做到这一点

这是我的代码:

unsigned long tsend = 0;
unsigned long techo = 0;
const int SEND = 2;
const int ECHO = 3;
unsigned long telapsed = 0;
unsigned long treal = 0;

void setup() {
  Serial.begin(115200);
  Serial.println("Start");

  pinMode(SEND, INPUT);
  pinMode(ECHO, INPUT);

  attachInterrupt(digitalPinToInterrupt(SEND), time_send, RISING);
  attachInterrupt(digitalPinToInterrupt(ECHO), time_echo, RISING);
}

void loop() {
  telapsed = techo - tsend;
  if (telapsed > 100 && telapsed < 10000000) {
    treal = telapsed;
    Serial.println(treal);
  }
}

void time_send() {
  tsend = micros();
}
void time_echo() {
  techo = micros();

}
unsigned long-tsend=0;
无符号长techo=0;
const int SEND=2;
常数int ECHO=3;
无符号的长终止点=0;
无符号长流程=0;
无效设置(){
序列号开始(115200);
Serial.println(“开始”);
pinMode(发送、输入);
pinMode(回波,输入);
连接中断(数字插针中断(发送)、发送时间、上升);
连接中断(数字插针中断(回波),时间\回波,上升);
}
void循环(){
telapsed=techo-tsend;
如果(终止>100&&终止<10000000){
treal=末端脱垂;
序列号println(treal);
}
}
无效时间_发送(){
tsend=micros();
}
无效时间_echo(){
techo=micros();
}

下面是信号(黄色),它有很多噪音。当信号为
高时,我需要忽略中断。这是一张

的图片,我将尝试以下方法:

#define DEBOUNCE_TIME 100

void time_send() {
  static long last = micros() ;
  if (last-tsend > DEBOUNCE_TIME)
     tsend = last;
}
void time_echo() {
  static long last = micros() ;
  if (last-techo > DEBOUNCE_TIME)
     techo = last;

}
调整去盎司时间,直到得到满意的结果

const byte intrpt_pin = 18; 
volatile unsigned int count = 0; 

#define DEBOUNCE_TIME 5000

void isr()
{
  cli();
  delayMicroseconds(DEBOUNCE_TIME);
  sei();

  count++;
}

void setup()
{
  pinMode(intrpt_pin, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(intrpt_pin), isr, FALLING);
}

void loop()
{
}
cli():
通过清除全局中断掩码禁用所有中断

sei():
通过设置全局中断掩码启用中断

所以,基本上这个程序会忽略这两行之间发生的所有中断,也就是去盎司时间。 检查中断反弹时间,并相应地调整去盎司时间,以获得最佳结果