11 years, 1 month ago.

Help with Interrupts

Hello Mbed Team,

I'm tryin to implement a break beam circuit(consisting of ir led and phototransistor) for calculating the number of persons entering the room .

I rigged up the circuit and the same circuit worked well for arduino,but here on mbed i'm not getting the exact output .For a single beam cut the count is incrementing by 30 or 40 not sure why .

I have attached the code and the hyperterminal o/p for the same .

main.cpp

 #include "mbed.h"

char counter=0;

InterruptIn button(p18);

void inc()
{
  counter++;
}

int main() {

button.rise(&inc);

    while(1) {
    
    
    
    printf("The number of persons Entered = %d \n",counter);
    wait(0.2); 
    
    
       
    }
}

Before 1st cut

/media/uploads/sanpai/before_cutting.jpg

After 1st cut

/media/uploads/sanpai/after_1st_cut.jpg

The count has increased by 36 instead of 1 ,not sure why .Please help .

4 Answers

11 years, 1 month ago.

Are you possibly now using a button to simulate your circuit? Then this could simply be bouncing. Even if not I guess something similar could happen. You can have a look at the PinDetect library: http://mbed.org/users/AjK/code/PinDetect/docs/tip/

11 years, 1 month ago.

Hello Mr Erik,

I'm using an IR break beam circuit to count the number of ppl entering , i tried with the circuit given in the below link and could even implement an tachometer too on arduino . Not sure why its not working with the mbed board .

Below is the link where i got the circuit .

http://arduinoprojects101.com/arduino-rpm-counter-tachometer/

11 years, 1 month ago.

Hi!

char counter=0;

I think this should be

int counter = 0;

Debounce could be an issue too.

Charly

Should not make a difference. Compiler should convert it to int before passing to printf

posted by Ad van der Weiden 04 Apr 2013
11 years, 1 month ago.

Most likely cause is bouncing. Original arduino code used falling edge for count. The ir diode may have better response that way. Try button.fall(&inc). You may also try some small capacitor parallel to the ir diode to reduce bouncing.