I am working on a project with an arduino mega 2560 and an arduino motor shield rev3 in order to control a dc motor. A wheel is fixed on the motor and we have a sensor which detect an aperture on the wheel. The whole system is turning at 100 Hz and the aim of the project is to generate a pulse each time we detect this aperture.
The sensor output is connected to two different interrupts (int1 and int5). Int5 is declared on rising edge and is useful only when we want to stop the motor (there is 3 different modes which are controlled with push buttons). Int 1 is declared on falling edge and it is our reference to generate the pulse in output.
In theory I should have a pulse in output every 10 ms since the sensor detect the aperture every 10ms. It works but sometimes I also have random pulses in output. I checked the int 1 flag and indeed the interrupt is triggered but when I check the sensor signal there is no noise or unwanted detection. So I am wondering if I did set up my interrupts correctly ? If I did then in which condition the flag could set itself without seeing an interrupts on its pin ?
If someone had the time to look at my program it would be awesome and highly appreciated. Thank you and have a good friday !
I attached the main.c file
main.c (8.22 KB)