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:
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)
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. 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.
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.
You can read it http://www.analog.com/library/analogdialogue/archives/34-07/comparators/