Bioscara
DALSA's DIY SCARA Robot Arm.
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
RPI_PWM Class Reference

Class to create a Pulse Width Modulated (PWM) signal on the Raspberry PI 4 and 5. More...

#include <uPWM.h>

Public Member Functions

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.
 

Private Member Functions

void setPeriod (int ns) const
 
int setDutyCycleNS (int ns) const
 
void enable () const
 
void disable () const
 
int writeSYS (std::string filename, int value) const
 

Private Attributes

int per = 0
 
std::string chippath
 
std::string pwmpath
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~RPI_PWM()

RPI_PWM::~RPI_PWM ( )
inline

Destroy the RPI_PWM object.

Invokes disable()

Member Function Documentation

◆ 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
vThe 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
channelThe GPIO channel
frequencyThe PWM frequency
duty_cycleThe initial duty cycle of the PWM (default 0)
chipThe chip number
Returns
>0 on success and -1 if an error has happened.

◆ stop()

void RPI_PWM::stop ( )
inline

Stops the PWM.

◆ writeSYS()

int RPI_PWM::writeSYS ( std::string  filename,
int  value 
) const
inlineprivate

Member Data Documentation

◆ chippath

std::string RPI_PWM::chippath
private

◆ per

int RPI_PWM::per = 0
private

◆ pwmpath

std::string RPI_PWM::pwmpath
private

The documentation for this class was generated from the following file: