PWM (Pulse Width Modulation) - Counting PWM Pulses

Hello GHI and forum members,

I am hoping one of you good folks can help me out with a Fez Domino PWM question.
I am using my Fez Domino to drive my CNC table with 3 stepper motors.
I need to generate higher frequencies than can be accomplished by toggling a pin between 1 and 0.
Therefore I am using the built in PWM pins… which work very well.

My question is:
I would like to count the number of PWM pulses.
For example, I would like to generate 2000 pulses to move my X axis 1 inch.
After 2000 pulses have been sent, I turn off the PWM pin/function.

Is there a way to count the PWM pulses rather than setting a timer ?
(currently, I set a timer to fire after approx 2000 pulses have been sent).

Thanks much,
Larry Scott
Walnut Creek, CA

Have you tried also sending your PWM signal to an InputPort? I’m not sure if C# event handler can keep up but that’s where I’d start.

I would implement this in RLP using an interrupt on timer overflow (same timer that generates the PWM signal). The interrupt handler would count down and disable the timer if the counter reaches 0.

Is OutputCompare an option?