Class to create a Pulse Width Modulated (PWM) signal on the Raspberry PI 4 and 5.
More...
#include <uPWM.h>
|
| int | start (int channel, int frequency, float duty_cycle=0, int chip=2) |
| | Starts the PWM.
|
| |
| void | stop () |
| | Stops the PWM.
|
| |
| | ~RPI_PWM () |
| | Destroy the RPI_PWM object.
|
| |
| int | setDutyCycle (float v) const |
| | Sets the duty cycle in percent 0 - 100.
|
| |
Class to create a Pulse Width Modulated (PWM) signal on the Raspberry PI 4 and 5.
Based on https://github.com/berndporr/rpi_pwm/blob/main/rpi_pwm.h and slightly modified.
For servo control it is important to use a hardware generated PWM, since software PWM, like it is created by the lgpio library, is subject to timing jitter which can cause the servo to figet which might lead to overheating and wear.
◆ ~RPI_PWM()
◆ disable()
| void RPI_PWM::disable |
( |
| ) |
const |
|
inlineprivate |
◆ enable()
| void RPI_PWM::enable |
( |
| ) |
const |
|
inlineprivate |
◆ setDutyCycle()
| int RPI_PWM::setDutyCycle |
( |
float |
v | ) |
const |
|
inline |
Sets the duty cycle in percent 0 - 100.
- Parameters
-
| v | The duty cycle in percent. |
- Returns
- >0 on success and -1 after an error.
◆ setDutyCycleNS()
| int RPI_PWM::setDutyCycleNS |
( |
int |
ns | ) |
const |
|
inlineprivate |
◆ setPeriod()
| void RPI_PWM::setPeriod |
( |
int |
ns | ) |
const |
|
inlineprivate |
◆ start()
| int RPI_PWM::start |
( |
int |
channel, |
|
|
int |
frequency, |
|
|
float |
duty_cycle = 0, |
|
|
int |
chip = 2 |
|
) |
| |
|
inline |
Starts the PWM.
- Parameters
-
| channel | The GPIO channel |
| frequency | The PWM frequency |
| duty_cycle | The initial duty cycle of the PWM (default 0) |
| chip | The chip number |
- Returns
- >0 on success and -1 if an error has happened.
◆ stop()
◆ writeSYS()
| int RPI_PWM::writeSYS |
( |
std::string |
filename, |
|
|
int |
value |
|
) |
| const |
|
inlineprivate |
◆ chippath
| std::string RPI_PWM::chippath |
|
private |
◆ per
◆ pwmpath
| std::string RPI_PWM::pwmpath |
|
private |
The documentation for this class was generated from the following file:
- lib/ros2_ws/src/dalsa_bioscara_grippers/bioscara_gripper_hardware_driver/include/bioscara_gripper_hardware_driver/uPWM.h