Question

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).

The schematic looks as follows (just the receiver):enter image description here

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:

  • 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.
  • When the beam gets broken the capacitor starts charging through R1 (R1 for setting charging time), R6 and R2.
  • When the voltage on capacitor passes ~3.4V, the output of the comparator goes HIGH, thus generating interrupt on AVR.
  • Similary when the voltage on capacitor goes below ~3.4V the output of the comparator goes LOW.

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!

Was it helpful?

Solution

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top