PWM lines are incredibly versatile and it is always worth asking the question "could I use PWM?" when you are considering almost any problem. The LED example shows how you can use PWM as a power controller. You can extend this idea to a computer-controlled switch-mode power supply. All you need is a capacitor to smooth out the voltage and perhaps a transformer to change the voltage. You can also use PWM to control the speed of a DC motor and if you add a simple bridge circuit you can control its direction and speed.
The amount of power delivered to a device by a pulse train is proportional to the duty cycle. A pulse train that has a 50% duty cycle is delivering current to the load only 50% of the time and this is irrespective of the pulse repetition rate. So the duty cycle controls the power, but the period still matters in many situations because you want to avoid any flashing or other effects. A higher frequency smooths out the power flow at any duty cycle.
With a sufficiently fast period you can also use PWM as a digital to analog converter. Simply add a low-pass filter to remove the pulsing and you have a steady voltage proportional to the duty cycle. This can be used to create an audio signal if the clock is fast enough.
Finally, you can use a PWM signal as a modulated carrier for data communications. For example, most infrared controllers make use of a 38kHz carrier, which is roughly a 26µs pulse. This is switched on and off for 1ms and this is well within the range that the PWM can manage. So all you have to do is replace the red LED in the previous circuit with an infrared LED and you have the start of a remote control, or data transmission, link.
Summary
PWM, Pulse Width Modulation, has a fixed repetition rate but a variable duty cycle, i.e. the amount of time the signal is high or low changes.
PWM can be generated by software simply by changing the state of a GPIO line correctly, but it can also be generated in hardware, so relieving the processor of some work.
Hardware PWM can generate high speed pulses, but how quickly you can change the duty cycle is still software-limited.
All versions of the Pi have two hardware PWM channels which can be used and configured using Linux drivers.
The CM5 has two additional channels which cannot be easily used via the driver. The PWM chip has also changed from pwmchip0 to pwmchip2.
The PWM drivers do not provide control over the PWM clock frequency which determines how accurately you can set the duty cycle.
A typical use of PWM is to control a servo and this only requires a PWM frequency of 50Hz. The position of the servo depends on the duty cycle.
You can easily invert the sense of the PWM signal, which is useful when the device is being driven by a single transistor.
As well as being a way of signaling, PWM can also be used to vary the amount of power or voltage transferred. The higher the duty cycle, the more power/voltage.
In the same way, by varying the duty cycle, you can dim an LED. As the brightness of an LED is not linear with applied voltage, you have to modify the output using a cubic law to get linear changes in brightness.
Raspberry Pi Compute Module 5 IoT In C Using Linux Drivers and Gpio5
Deno has faced a setback in its attempt to get Oracle to relinquish the JavaScript Trademark. The US Patents Office Trademark Trial and Appeal Board (TTAB) dismissed Deno's fraud claim which is one th [ ... ]
Apple has announced a range of improvements to its developer tools at this year's WWDC (WorldWide Developers Conference), including a new foundation models framework and updates to Xcode, Apple's [ ... ]