If the pulses aren't very fast and you don't mind jitter you could do it in software. Untested Python.
def send_PWM(GPIO, pulses, frequency, dutycycle): # dutycycle expected to be in range 0.0 to 1.0 duration = 1.0 / frequency on_period = duration * dutycycle off_period = duration - on_period for i in range(pulses): pi.write(GPIO, 1) time.sleep(on_period) pi.write(GPIO, 0) time.sleep(off_period)
If the pulses are fast (say the 100 kHz or less region) and you don't like jitter you could use a wave chain.
There are various examples of using waves at http://abyz.me.uk/rpi/pigpio/examples.html
Here is an example using waves and wave chains.
#!/usr/bin/env python import time import pigpio def tx_pulses(pi, GPIO, frequency, num, dutycycle=0.5): assert 1 <= frequency <= 500000 assert 1 <= num <= 65535 assert 0.0 <= dutycycle <= 1.0 duration = int(1000000/frequency) on_micros = int(duration * dutycycle) num_low = num % 256 num_high = num // 256 wf = [] # on off time wf.append(pigpio.pulse(1<<GPIO, 0, on_micros)) wf.append(pigpio.pulse( 0, 1<<GPIO, duration - on_micros)) pi.wave_add_generic(wf) wid = pi.wave_create() if wid >= 0: pi.wave_chain([255, 0, wid, 255, 1, num_low, num_high]) while pi.wave_tx_busy(): time.sleep(0.01) pi.wave_delete(wid) pi = pigpio.pi() if not pi.connected: exit() GPIO=19 pi.set_mode(GPIO, pigpio.OUTPUT) tx_pulses(pi, GPIO, 100, 25) # 25 pulses @ 100 Hz 50% duty tx_pulses(pi, GPIO, 1000, 250, 0.1) # 250 pulses @ 1000 Hz 10% duty tx_pulses(pi, GPIO, 5000, 2391, 0.03) # 2391 pulses @ 5000 Hz 3% duty pi.stop()