简体   繁体   English

从红外传感器获取中断

[英]Getting interrupt from IR sensor

I am having a problem with getting a correct interrupt from IR sensor. 我从红外线传感器获取正确的中断时遇到问题。 Actually there are 2 problems: 实际上有两个问题:

  • I am getting more than one interrupt at a time (meaning if I break the beam, the interrupts gets fired more than once) 我一次收到一个以上的中断(这意味着如果我中断光束,中断会被触发多次)
  • I am getting an interrupt everytime I place something infront of IR beam (which is correct) and everytime, I remove that abostacle (which should not happen). 每次在IR光束前面放置东西(这是正确的)并且每次移除该障碍物(这都不应该发生)时,都会遇到中断。

The schematic looks as follows (just the receiver): 原理图如下(只是接收器): 在此处输入图片说明

The code is written in C and compiled in GCC, I am using AVR Atmega644: 该代码用C编写并在GCC中编译,我使用的是AVR Atmega644:

sei();
/* Enable interrupts. */
EIMSK &= ~((1 << INT1) | (1 << INT0));
EICRA |= ((1 << ISC11) | (1 << ISC10) | (1 << ISC01) | (1 << ISC00)); /* Trigger on rising edge */
EIFR |= ((1 << INTF1) | (1 << INTF0));
EIMSK |= ((1 << INT1) | (1 << INT0));
DDRD &= ~((1 << PD2) | (1 << PD3));
PORTD |= ((1 << PD2) | (1 << PD3));

For the ISR's I use: ISR(INT0_vect) and ISR(INT1_vect) 对于ISR,我使用: ISR(INT0_vect)ISR(INT1_vect)

The idea behind this should be as follows: 其背后的想法应该如下:

  • This IR sensors output is HIGH when the IR beam is closed, and goes to LOW whem the beam gets broken. 当红外光束关闭时,该红外传感器的输出为高;而当光束破裂时,该红外传感器的输出为低。
  • When the beam is closed, the capacitor should get discharged through R2. 当电子束关闭时,电容器应通过R2放电。
  • When the beam gets broken the capacitor starts charging through R1 (R1 for setting charging time), R6 and R2. 当光束断开时,电容器开始通过R1(用于设置充电时间的R1),R6和R2充电。
  • When the voltage on capacitor passes ~3.4V, the output of the comparator goes HIGH, thus generating interrupt on AVR. 当电容器上的电压超过〜3.4V时,比较器的输出变为高电平,从而在AVR上产生中断。
  • Similary when the voltage on capacitor goes below ~3.4V the output of the comparator goes LOW. 类似地,当电容器上的电压降至约3.4V以下时,比较器的输出将变为低电平。

Based on my calculations the time to charge a capacitor from 0V to 3.41V is from 1-10ms (depends on R1), so this is the time the beam should be broken to generate an interrupt. 根据我的计算,电容器从0V充电到3.41V的时间为1-10ms(取决于R1),因此这是应该中断光束以产生中断的时间。 And the time to discarge a capacitor from 4.9V to 3.41 is ~ 1ms (the comparator output goes LOW), and to 0.2V ~7ms. 电容器从4.9V放电至3.41的时间约为1ms(比较器输出变为LOW),而至0.2V约为7ms。

Thank you for your help! 谢谢您的帮助!

I think that you need to substitute your "comparator" with a "comparator with hysteresis". 我认为您需要用“具有迟滞的比较器”代替“比较器”。 When your capacitor is at 3.4 V the comparator will oscillate between LOW and HIGH because you have 3.4 V and noises and the voltage can be 3.36 and after 3.45 and 3.38. 当您的电容器处于3.4 V时,比较器将在LOW和HIGH之间振荡,因为您具有3.4 V和噪声,并且电压可以为3.36,且在3.45和3.38之后。

You can read it http://www.analog.com/library/analogdialogue/archives/34-07/comparators/ 您可以阅读它http://www.analog.com/library/analogdialogue/archives/34-07/comparators/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM