Measruing PWM widths with interrupts

I need to measure the widths of a PWM type signal that contains 3 pulses repeating every 1 sec.
This is the signal
b40_signal

I am planning to use pinchange interrupts on D6 in my case as its free and in the range.
But the handling gets a bit complicated as i have to track the timings of the gaps as well as pulses to determine which i am reading.

i.e. ----1 sec gap----Pulse1---gap----Pulse2----gap----pulse3--->

Can someone knowledgeable on interrupts help me out?

But the handling gets a bit complicated

Why? Using a pin CHANGE interrupt means you get called when the pin goes HIGH and when it goes LOW. The time between going HIGH once and going HIGH again tells you one thing. The time between going HIGH and going LOW tells you something else.

Yes i suppose its not rocket science, i was just after some guidance ho how best to do it.
My thoughts were:

On Interrupt rising
width counter = 0
if time since last pulse > 900ms || pulsecount >2, then pulse count =0

On interrupt falling
store pulse width n, pulse count n
pulsecount ++

I've seen several (sometimes conflicting) sources on how to use interrupts, including external libs such as PinChangeInterrupt.h which looks a little heavy to use (and understand) to the simple built-in http://playground.arduino.cc/Main/PinChangeInterrupt
So was looking for some guidance on implementation.

I think PaulS was referring to the normal attachInterrupt function where you specify CHANGE parameter.

Look at the attached sketch and you will hopefully get an idea how to read frequency & duty cycle of a PWM signal. The signal connects to pin 2 on the UNO/MEGA and the sketch is currently setup to use tone to generate test signals from pin 9 on the same MCU.

Frequency_Counter.ino (2.74 KB)

I think PaulS was referring to the normal attachInterrupt function where you specify CHANGE parameter.

No, because the pin CHANGE interrupt only supports CHANGE.

Just to close the loop, I have i working nicely. Thanks to Riva for the example and the excellent pages of Nick Gammon.

** setup**

attachInterrupt(digitalPinToInterrupt(OIL_PIN), ISROilPulse, CHANGE);

** ISR **

void ISROilPulse() {
  unsigned long now = micros();
  if (digitalRead(OIL_PIN) == HIGH) { //rising edge
    if (now - lastRiseT < 900000) {
      period = now - lastRiseT; //if the last rise was < 900ms ago, period measuremet is vaild
    } else {
      pulseCount = 0;     // if the last rise was > 900ms ago, reset the counter
    }
    lastRiseT = now;
  } else {                          //falling edge
    lastFallT = now;
    switch (pulseCount) {
      case 0: p1 = now - lastRiseT; break;
      case 1: p2 = now - lastRiseT; break;
      case 2: p3 = now - lastRiseT; break;
    }
    pulseCount++;
  }
}