1

I am working with a simple hardware design that requires the generation of 3 different square waves on different GPIO pins of the Raspberry Pi 3.

I have reviewed posts such as this one:

RPi GPIO as a high-speed square wave generator

and have had great success in generating a single square wave on a GPIO of my choice, at a frequency I specify. So far so good. I've tested with pigpio and RPi.GPIO, and am getting the best results in pigpio so far - however I am open minded about which library I use. I am writing in Python but again if there is a better way to achieve this I have no issues writing a C program or similar.

Where I have come unstuck is generation of two or more square waves at the same time. Let's say that I want:

  1. 100Hz 50% duty cycle generated on GPIO17.
  2. 16Hz 50% duty cycle generated on GPIO18.

I haven't found a way to do this. For example the pigpio documentation for the wave_send_repeat function (http://abyz.me.uk/rpi/pigpio/python.html#wave_send_repeat) says:

Transmits the waveform with id wave_id. The waveform repeats until wave_tx_stop is called or another call to wave_send_* is made.

This is my experience. I've tried the wave_chain function with similar results - I can't get the two square waves to transmit simultaneously, even though I can define them and transmit one at a time.

This post: How to create multiple GPIO pwm waveforms that are in sync using pigpio for trapezoidal motor control?

Suggests a method closer to that which I want, but I don't need the phase syncing - that isn't important for my application - I just need to send two independent waves regardless of phase angle.

I feel like I'm missing something, or perhaps I've struggling with the hardware capabilities of the BCM chip and asking for something it wasn't designed for. Can anyone please point me in the right direction?

Thanks in advance!

1

It should be straightforward to generate a pigpio waveform by hand. To do it programmatically will require a bit more ingenuity.

Your example

  1. 100Hz 50% duty cycle generated on GPIO17.

  2. 16Hz 50% duty cycle generated on GPIO18.

Generate a seconds worth of 100Hz pulses and add with wave add generic. Do the same with a seconds worth of 16Hz pulses and add with wave add generic. Then use wave create. The resulting wave will be the merger of both.

You don't need to use a seconds worth, just enough so that the waves come back into alignment, e.g. 0.25 seconds would be enough.

  • Thank you so much for that - I had not correctly grasped the use of wave_add_generic and wave_create. I do also see the need for ingenuity - I am getting some glitches at the moment which I think it a lack of alignment of the two waves. Hopefully I can find some clever programmatic way of making this tidy and producing a nice clean pulse train. – James Freeman Nov 21 '17 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.