Writes PWM frequency to a GPIO pin
The PWM uses a software implementation allowing all GPIO pins on theRaspberry Pi™ hardware board to output a PWM signal. Each PWM pin outputs a square
waveform with variable frequency, duty cycle, or average voltage. A duty cycle of
0 means the waveform is always low and a duty cycle of
1 means the waveform is always high.
To use a PWM pin, reconfigure one of the multiple-use GPIO pins as a PWM pin.
frequency — Frequency of output waveform, in Hz
Frequency to assign to output pin, in Hz. The value is constrained to the minimum and maximum values that the PWM hardware can support.
Enable PWM and Set Properties
Enable PWM pin
12 and set the frequency and
mypi = raspi(); configurePin(mypi, 12, 'PWM'); writePWMDutyCycle(mypi, 12, 0.5); writePWMFrequency(mypi, 12, 2000);
The result is a square wave with a 50.0% duty cycle, frequency of 2000 hertz,
and average voltage of
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
You can also deploy
writePWMFrequencyon the Raspberry Pi hardware in MATLAB® Online™.
Introduced in R2016b