Robot Control Library
PWM

Description

C interface for the Sitara PWM driver.

<rc/pwm.h>

These functions provide a general interface to all 3 PWM subsystems, each of which have two available channels A and B. PWM subsystems 1 and 2 are used for controlling the 4 motor drivers on the Robotics Cape, however they may be controlled by the user directly instead of using the motor API. PWM subsystem 0 channels A and B can be accessed on the GPS header if set up with the Pinmux API to do so. The user may have exclusive use of that subsystem.

Author
James Strawson
Date
1/31/2018

Functions

int rc_pwm_init (int ss, int frequency)
 Configures subsystem 0, 1, or 2 to operate at a particular frequency. More...
 
int rc_pwm_cleanup (int ss)
 Stops a subsystem and puts it into a low-power state. More...
 
int rc_pwm_set_duty (int ss, char ch, double duty)
 Sets the duty cycle of a specific pwm channel. More...
 
int rc_pwm_set_duty_ns (int ss, char ch, unsigned int duty_ns)
 Like rc_pwm_set_duty() but takes a pulse width in nanoseconds. More...
 

Function Documentation

◆ rc_pwm_init()

int rc_pwm_init ( int  ss,
int  frequency 
)

Configures subsystem 0, 1, or 2 to operate at a particular frequency.

This may be called at runtime to change the pwm frequency without stopping the motors or pwm signal.

Parameters
[in]ssSubsystem 0 1 or 2
[in]frequencyThe frequency in HZ
Returns
Returns 0 on success or -1 on failure.

◆ rc_pwm_cleanup()

int rc_pwm_cleanup ( int  ss)

Stops a subsystem and puts it into a low-power state.

Recommended to call before userspace program exits to ensure the PWM hardware stops.

Parameters
[in]sssubsystem 0,1,2
Returns
Returns 0 on success or -1 on failure.

◆ rc_pwm_set_duty()

int rc_pwm_set_duty ( int  ss,
char  ch,
double  duty 
)

Sets the duty cycle of a specific pwm channel.

Parameters
[in]sssubsystem 0,1,2
[in]chchannel 'A' or 'B'
[in]dutybetween 0.0 (off) and 1.0(full on)
Returns
Returns 0 on success or -1 on failure.

◆ rc_pwm_set_duty_ns()

int rc_pwm_set_duty_ns ( int  ss,
char  ch,
unsigned int  duty_ns 
)

Like rc_pwm_set_duty() but takes a pulse width in nanoseconds.

duty_ns which must range from 0 (off) to the number of nanoseconds in a single cycle as determined by the freqency specified when calling rc_pwm_init(). For example, a pwm frequency of 25kz corresponds to a maximum pulse width of 40,000ns.

Parameters
[in]sssubsystem 0,1,2
[in]chchannel 'A' or 'B'
[in]duty_nsThe duty cycle (pulse width) in nanoseconds
Returns
Returns 0 on success or -1 on failure.