Output PWM with specific number of pulses?

29 Nov 2017

Hi,

I'm using the LCP4088 - is there a way to use PWMOut by outputting a specific number of PWM pulses (ie. I just want 1 pulse!)

Is this possible?

Thank you, Steve

05 Dec 2017

PWM outputs are generally continuous I don't think the mbed library supplies any easy way to count or limit the number of pulses.

Outside of the library there are a few tricks you could try if you play with the registers directly such as feeding the PWM output into a counter input (either externally or if possible internally) and then using the counter to trigger at the required number of pulses and switch the PWM output off.

Alternatively sticking within the mbed library if you only want a few pulses of defined duration you could use an SPI output and set the data, data width and bus speed to give the required high/low pattern. For short patterns this should work well but it may be tricky to maintain the correct timing once the pattern requires multiple spi write transactions. The BurstSPI library would help in that situation.

05 Dec 2017

Steven,

PWM is meant to be a continuous modulation. If you only want to turn the signal on / off for a couple pulses you can use the DigitalOut() class to do this.

All the best,

-Austin