Hi I am using 328 based arduino, so only have two interrupts to play with.
I have three streams of pulses that I need to read and count the pulses.
With one stream of pulses it is easy, a single ISR attached to a single single interrupt, the ISR simply increments a counter variable.
However with three streams, i.e. more than the interrupts available, link these to an interrupt and an input pin each (as you might with three switches) so the ISR is fired for each received pulse, the ISR determines which stream fired, and increments the relevant counter. I just don't see how this will work! What happens when two streams go high for a period, sure the interrupt will fire (assuming int's are not disabled in the ISR) but how do you know which stream => which counter to increment.
Even with multiple interrupts I cannot see how to make this work!
You could use pin change interrupts in addition to the two external interrupts on the Uno.
Using one interrupt, the method can't discriminate between pulses that arrive closer together than the time it takes to acknowledge the interrupt (the "interrupt latency") and sample the inputs.
Tell us more about the pulse streams: frequency, on time, etc.
That standard approach with pin change interrupts is to read the port in question (each pin change
interrupt listens to selected pins on one port), and compare to the last time it was read - any changed
bits for pins you are interested in are noted and relevant counter(s) updated, then you record the
latest port value for next time.
So something like:
#define PORT_B_MASK 0b00110011 // mask for the pins you are interested in, here 8,9,12,13
void setup ()
{
PCICR = 0b001 ; // enable PCINT0 only
PCMSK0 = PORT_B_MASK ; // for only the pins we are interested in
}
volatile byte last_port_b;
volatile int counter_A = 0;
volatile int counter_B = 0;
// PinChangeINT0 covers port B, 1 and 2 cover ports C and D...
ISR (PCINT0_vect)
{
byte this_port_b = PINB ;
byte diffs = (this_port_b ^ last_port_b) & PORT_B_MASK ;
last_port_b = this_port_b ;
if (diffs & 1)
counter_A ++ ;
if (diffs & 2)
counter_B ++ ;
... etc
Radical alternative: the ESP8266 supports interrupts on all pins (like the external interrupts of AVR chips; the ESP doesn't have these generic "pin change" interrupts).
Up to you to decide whether it makes sense to switch to that processor.