[英]Getting interrupt from IR sensor
I am having a problem with getting a correct interrupt from IR sensor. 我从红外线传感器获取正确的中断时遇到问题。 Actually there are 2 problems:
实际上有两个问题:
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: 其背后的想法应该如下:
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.