Trigger ADC with PWM interrupt

Hi Guys!
What I am trying to do is basically the same as this topic here: http://forum.arduino.cc/index.php?topic=146634.0 . My signal (I attached a picture) is a square wave produced by a pwm output. The information I try to measure is the height of these pulses. Because the widgth of the pulses is variing I want to trigger the measurement after a certain delay of the raising edge of the pwm.

I browsed the forum, but I could not get the right information. I figured out that on the DUE there is this PWMC with the pwmc.h library. But I still don’t know how I could attach the interrupt caused by the pwm_eventline to trigger the ADC.
I also have the datasheet of the Microcontroller (>1400 pages!!!http://www.atmel.com/devices/SAM3X8E.aspx)
Can anybody show me a good method to do this measurement? How would you solve this problem?
Seaching the .h Lib files for keywords, searching the datasheet?

signal.pdf (8.9 KB)

I believe you should be able to use a pin-change interrupt on the PWM pin. The interrupt hander can then do whatever measurement is required, or just set a flag telling the loop() function to do it.

Regards, Ray L.

What is the freq of those pulses? If it's not important how you generate pulses, via PWM or Timer, like in linked post, than have a look at this example: http://forum.arduino.cc/index.php?topic=225204.0 Timer flipping digital 2 pin and trigger ADC ( you need to call void pio_TIOA0 () in setup() instead of pinMode (2, ...). Than you have flexibility: freq. of pulses Fp up to 1 MHz; duration of pulses changing RA; take measurements by connecting 1-16 ADC inputs, and activating lines in ADC_setup() - all data points spaced 1 usecond apart. 1-16 data points for each pulse. Of course, you may change space timing later on

Thank you for your fast reply!

The pulses at the moment, are generated by the analogWrite() function at 1kHz

RayLivingston: I believe you should be able to use a pin-change interrupt on the PWM pin. The interrupt hander can then do whatever measurement is required, or just set a flag telling the loop() function to do it.

Regards, Ray L.

Warning, I am not sure this can work on the Due - you cannot trigger interrupts from an output pin, if I recall correctly... At least read the relevant sections of the datasheet.

MarkT: Warning, I am not sure this can work on the Due - you cannot trigger interrupts from an output pin, if I recall correctly... At least read the relevant sections of the datasheet.

If you can't do that, then you can simply tie two pins together, one an output, the other an input, and do a pin interrupt on the input pin.

Regards, Ray L.

This looks like the wrong way to do things. The PWM system has a mode where the output pulse is symmetric about the timer. I forget what it's called - balanced mode or something like that?

The reason for this mode existing is the PWM pulse is started before the timer gets to zero and ends the same time after that. Therefore when the timer is at zero is the perfect time to sample the output. No delays required