writePWMFrequency

Writes PWM frequency to PWM pin

Syntax

writePWMFrequency(bbb, pin_name, frequency)

Description

example

writePWMFrequency(bbb, pin_name, frequency) writes the frequency 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.

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

Frequency to assign to output pin, in Hz. The value is constrained to the minimum and maximum values that the PWM hardware can support.

Example: 2000

Introduced in R2015a