I have a fairly simple project that does work on my Uno board but when switching to my Mega 2560 the interrupt does not work. What I am trying to do is to take a trigger signal from my external power supply and count how many times that signal is triggered. The trigger signal is a 10us positive pulse, so the Uno could detect the rising edge.
With the Mega board the interrupt will not happen. I have tried to change pin from 2 to 21 to 53 but no difference. Not sure what I am doing wrong.
You should actually do this on an 8 bit MCU (non-atomic 32bit read operation):
noInterrupts() ;
unsigned long new_count = count;
interrupts() ;
but I doubt if that is your problem.
I'd connect a 10k pull down resistor to pin 2 and touch a jumper lead between +5v and pin 2 to see if that generates a message with the value new_count.
OK that worked perfectly (10k pulldown and trigger with wire to 5V). However connecting to the trigger signal on PSU, it does not work. Is the trigger signal too fast to detect? 10us is that on the limit?
Only pin 2 and 3 are safe for external interrupts. Pin 18 to 20 also are used for Wire and Serial1. If you want to change your interrupt pin then use a #define or const int declaration for the selected pin so that the pin is fully initialized in setup().
OK that worked perfectly (10k pulldown and trigger with wire to 5V). However connecting to the trigger signal on PSU, it does not work. Is the trigger signal too fast to detect? 10us
The only thing connected to the arduino is the pulse signal 5V and Gnd. The 5V is connected to pin 2 and Gnd to Gnd. Pin 2 has a pull-down resistor,10k to Gnd.
That is all.
Yes, there is not much to it. I can only guess that the shape/amplitude of the input pulse is not good enough. You could try something like this (R2 should be 10k), You'd then look for a falling edge. I suppose you could also look at using the Mega's built-in comparator to trigger an interrupt.