Try something like the following for your interrupt handlers. Depending on the micro you select, how to install these will be different. I would stay away from PIC parts, I personally don't like them. The Atmega family of MPU should be better to work with in my opinion, although my personal favorite these days is the Freescale Kinetis family of MPU's. You can get demo boards in the form of expandable towers from Freescale. [EDIT] You may also want to handle rollover for the counter variable if you expect to have counts high enough for this to happen.
#define S1 (1 << 0)
#define S2 (1 << 1)
unsigned char sensorFlags = 0;
int counter = 0;
/* interrupt handler for S1 */
void s1_isr(void)
{
if(sensorFlags & S2)
{
/* Exiting, decrement counter */
--counter;
/* clear S2 flag */
sensorFlags &= ~S2;
/* Get timestamp, store it, transmit to remote host
this will depend a lot on your hardware */
}
else if(sensorFlags & S1)
{
/* ERROR same sensor tripped twice, handle as necessary */
}
else
{
/* Entering, set S1 flag */
sensorFlags |= S1;
}
/* clear interrupt flag if necessary */
}
/*interrupt handler for S2 */
void s2_isr(void)
{
if(sensorFlags & S1)
{
/* Entering, increment counter */
++counter;
/* clear S1 flag */
sensorFlags &= ~S1;
/* Get timestamp, store it, transmit to remote host
this will depend a lot on your hardware */
}
else if(sensorFlags & S2)
{
/* ERROR same sensor tripped twice, handle as necessary */
}
else
{
/* Exiting, set S2 flag */
sensorFlags |= S2;
}
/* clear interrupt flag if necessary */
}