Robot Control Library
pwm.h
Go to the documentation of this file.
1/**
2 * <rc/pwm.h>
3 *
4 * @brief C interface for the Sitara PWM driver
5 *
6 * These functions provide a general interface to all 3 PWM subsystems, each of
7 * which have two available channels A and B. PWM subsystems 1 and 2 are used
8 * for controlling the 4 motor drivers on the Robotics Cape, however they may be
9 * controlled by the user directly instead of using the motor API. PWM subsystem
10 * 0 channels A and B can be accessed on the GPS header if set up with the
11 * Pinmux API to do so. The user may have exclusive use of that subsystem.
12 *
13 *
14 * @author James Strawson
15 * @date 1/31/2018
16 *
17 * @addtogroup PWM
18 * @ingroup IO
19 * @{
20 */
21
22#ifndef RC_PWM_H
23#define RC_PWM_H
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29
30/**
31 * @brief Configures subsystem 0, 1, or 2 to operate at a particular
32 * frequency.
33 *
34 * This may be called at runtime to change the pwm frequency without stopping
35 * the motors or pwm signal.
36 *
37 * @param[in] ss Subsystem 0 1 or 2
38 * @param[in] frequency The frequency in HZ
39 *
40 * @return Returns 0 on success or -1 on failure.
41 */
42int rc_pwm_init(int ss, int frequency);
43
44/**
45 * @brief Stops a subsystem and puts it into a low-power state.
46 *
47 * Recommended to call before userspace program exits to ensure the PWM hardware
48 * stops.
49 *
50 * @param[in] ss subsystem 0,1,2
51 *
52 * @return Returns 0 on success or -1 on failure.
53 */
54int rc_pwm_cleanup(int ss);
55
56/**
57 * @brief Sets the duty cycle of a specific pwm channel.
58 *
59 * @param[in] ss subsystem 0,1,2
60 * @param[in] ch channel 'A' or 'B'
61 * @param[in] duty between 0.0 (off) and 1.0(full on)
62 *
63 * @return Returns 0 on success or -1 on failure.
64 */
65int rc_pwm_set_duty(int ss, char ch, double duty);
66
67/**
68 * @brief Like rc_pwm_set_duty() but takes a pulse width in nanoseconds.
69 *
70 * duty_ns which must range from 0 (off) to the number of nanoseconds in a
71 * single cycle as determined by the freqency specified when calling
72 * rc_pwm_init(). For example, a pwm frequency of 25kz corresponds to a maximum
73 * pulse width of 40,000ns.
74 *
75 * @param[in] ss subsystem 0,1,2
76 * @param[in] ch channel 'A' or 'B'
77 * @param[in] duty_ns The duty cycle (pulse width) in nanoseconds
78 *
79 * @return Returns 0 on success or -1 on failure.
80 */
81int rc_pwm_set_duty_ns(int ss, char ch, unsigned int duty_ns);
82
83
84#ifdef __cplusplus
85}
86#endif
87
88#endif // RC_PWM_H
89
90/** @} end group PWM*/
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.
int rc_pwm_cleanup(int ss)
Stops a subsystem and puts it into a low-power state.
int rc_pwm_set_duty(int ss, char ch, double duty)
Sets the duty cycle of a specific pwm channel.
int rc_pwm_init(int ss, int frequency)
Configures subsystem 0, 1, or 2 to operate at a particular frequency.