Software PWM on the Omega’s GPIOs
Omega Tip of the Week:
PWM on an Omega GPIO
You read that correctly! Generating a Pulse Width Modulated (PWM) signal on an Omega GPIO is definitely possible, however, it is software-based PWM and there are no guarantees on accuracy.
Software PWM vs Hardware PWM
Software PWM is implemented by a program that usually waits for a defined amount of time before toggling the GPIO output. This has the potential to be inaccurate since the CPU might be interrupted with other processes and tasks. Software PWM is generally good enough for dimming an LED but not for something requiring more accuracy, such as driving a servo.
Hardware PWM is done by programming dedicated hardware that will output cycle-accurate PWM signals. The Servo Expansion has a chip that can be programmed to provide cycle-accurate PWM.
PWM with just an Omega and a Dock
If you want to generate a PWM signal using just an Omega and a Dock, and you don’t need it to be 100% accurate, you can use our fast-gpio utility:
fast-gpio pwm [gpio] [freq in Hz] [duty (out of 100)]
fast-gpio pwm 1 200 25
The command above will launch a background process that will issue commands to have GPIO1 produce a PWM signal with a 25% duty cycle at 200 Hz. The resulting signal will have a 5ms period (P = 1/f) and will be HIGH 25% of the time, and LOW the remaining 75% of the time.
As long as the background process is running, the PWM signal will continue to be generated. To stop the signal, we can run the following:
fast-gpio set 1 0
See our documentation on fast-gpio for more!