writePWMDutyCycle

Writes PWM duty cycle to PWM pin

Syntax

writePWMDutyCycle(bbb, pin_name, duty_cycle)

Description

example

writePWMDutyCycle(bbb, pin_name, duty_cycle) writes the duty cycle of the output square wave to the output pin.

The BeagleBone Black board has eight PWM output pins. 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.

Examples

collapse all

Enable PWM pin P9_14 (PWM1A) and set the frequency and duty cycle.

bbb = beaglebone();
enable(bbb, 'P9_14');
writePWMDutyCycle(bbb, 'P9_14', 0.5);
writePWMFrequency(bbb, 'P9_14', 2000);

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

Duty cycle between 0 and 1 to assign to output pin.

Example: 0.5

Data Types: single | double

Introduced in R2015a