Main Content


Writes average PWM voltage to PWM pin

Add-On Required: This feature requires the MATLAB Support Package for BeagleBone Black Hardware add-on.



writePWMVoltage(bbb, pin_name, voltage) writes the average voltage of the output square wave to the output pin. This implicitly writes the duty cycle of the output square wave. The output square wave voltage is 3.3 V maximum and 0 V minimum.

The BeagleBone Black board has eight PWM output pins. Each PWM pin outputs a square waveform with variable frequency and duty cycle.


collapse all

Enable PWM pin P9_14 (PWM1A) and set the frequency and average voltage.

bbb = beaglebone();
enable(bbb, 'P9_14');
writePWMFrequency(bbb, 'P9_14', 2000);
writePWMVoltage(bbb, 'P9_14', 1.65);

The result is a square wave with a 50.0% duty cycle, frequency of 2000 hertz, and average voltage of 1.65 V.

Input Arguments

collapse all

BeagleBone Black connection created using beaglebone, specified as an object.

Name of output pin.

PWMs PWM0A and PWM0B share pins with SPI 0 and serial port 2.

Alternative PWM fanouts PWM0A, PWM0B, PWM1A, PWM1B, PWM2A, and PWM2B share pins with HDMI, which is enabled by default. Use showPins to view the current pin usage. If HDMI is enabled, you cannot enable these pins using enablePWM. For information on how to disable HDMI, see the BeagleBone Black hardware documentation.

Example: 'P9_14'

Data Types: char

Mean voltage of the square wave at the output pin, in volts. The value is constrained between 0 V and 3.3 V. A value of 0 V produces no output. A value of 1.65 V produces a square wave with a 50% duty cycle at the output pin.

Example: 1.5

Version History

Introduced in R2015a