libpynq (release 5EWC0-2023 version 0.2.6 of 2023-10-24 17:28)
Loading...
Searching...
No Matches
PWM library

Enumerations

enum  pwm_index_t {
  PWM0 , PWM1 , PWM2 , PWM3 ,
  PWM4 , PWM5 , NUM_PWMS
}
 

Functions

bool pwm_initialized (const int pwm)
 
void pwm_init (const int pwm, const uint32_t period)
 
void pwm_destroy (const int pwm)
 
void pwm_set_duty_cycle (const int pwm, const uint32_t duty)
 
void pwm_set_period (const int pwm, const uint32_t period)
 
uint32_t pwm_get_period (const int pwm)
 
uint32_t pwm_get_duty_cycle (const int pwm)
 
void pwm_set_steps (const int pwm, const uint32_t steps)
 
uint32_t pwm_get_steps (const int pwm)
 

Detailed Description

Functions to use Pulse Width Modulation (PWM).

Each of the 6 PWM channels (numbered 0..NUM_PWMS-1) can be linked to any mappable pin (e.g. green or color LEDs, buttons).

PWM can also be used through GPIO (see gpio.h and pinmap.h). Note that GPIO numbering (SWB_PWM0..SWB_PWM5) is then used instead of 0..NUM_PWMS-1 (PWM0..PWM5).

Enumeration Type Documentation

◆ pwm_index_t

Enum of PWM channels.

All functions use a PWM channel from 0..NUM_PWMS-1. Alternatively, you can use PWMi instead of just i if you find that clearer.

Enumerator
PWM0 
PWM1 
PWM2 
PWM3 
PWM4 
PWM5 
NUM_PWMS 

Definition at line 47 of file pwm.h.

Function Documentation

◆ pwm_destroy()

void pwm_destroy ( const int  pwm)
extern

Removes the instantiated shared memory system of the PWM channel.

Parameters
pwmThe PWM channel to destroy.
Warning
Fails with program exit if pwm is outside valid range.

Definition at line 72 of file pwm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pwm_get_duty_cycle()

uint32_t pwm_get_duty_cycle ( const int  pwm)
extern

Gets the duty cycle of the specified PWM channel.

Parameters
pwmThe PWM channel.
Returns
The duty cycle of the specified PWM channel.
Warning
Fails with program exit if pwm is outside valid range or if pwm has not been initialized.

Definition at line 78 of file pwm.c.

Here is the call graph for this function:

◆ pwm_get_period()

uint32_t pwm_get_period ( const int  pwm)

Returns the period of a certain PWM channel.

Parameters
pwmThe PWM channel.
Returns
The period of the specified PWM channel as an uint32_t.
Warning
Fails with program exit if pwm is outside valid range or if pwm has not been initialized.

Definition at line 83 of file pwm.c.

Here is the call graph for this function:

◆ pwm_get_steps()

uint32_t pwm_get_steps ( const int  pwm)
extern

Get the number of steps a certain channel has taken so far.

Parameters
pwmPWM channel.
Returns
The number of steps that have been taken; 0 is off and -1 is continous.
Warning
Fails with program exit if pwm is outside valid range or if pwm has not been initialized.

Definition at line 98 of file pwm.c.

Here is the call graph for this function:

◆ pwm_init()

void pwm_init ( const int  pwm,
const uint32_t  period 
)
extern

Initializes the PWM channel with the specified period.

Parameters
pwmthe PWM channel to initialize.
periodThe period to set for the PWM channel.
Warning
Fails with program exit if pwm is outside valid range.

Definition at line 61 of file pwm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pwm_initialized()

bool pwm_initialized ( const int  pwm)
extern

Checks if the channel index is initialized.

Parameters
pwmThe PWM channel
Returns
True if initialized, false if not
Warning
Fails with program exit if pwm is outside valid range.

Definition at line 38 of file pwm.c.

◆ pwm_set_duty_cycle()

void pwm_set_duty_cycle ( const int  pwm,
const uint32_t  duty 
)
extern

Sets the duty cycle for the specified PWM channel.

Parameters
pwmThe PWM channel.
dutyThe duty cycle to set for the PWM channel.
Warning
Fails with program exit if pwm is outside valid range or if pwm has not been initialized.

Definition at line 93 of file pwm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pwm_set_period()

void pwm_set_period ( const int  pwm,
const uint32_t  period 
)
extern

Sets the period for the specified PWM channel.

Parameters
pwmThe PWM channel.
periodThe period to set for the PWM channel.
Warning
Fails with program exit if pwm is outside valid range or if pwm has not been initialized.

Definition at line 88 of file pwm.c.

Here is the call graph for this function:

◆ pwm_set_steps()

void pwm_set_steps ( const int  pwm,
const uint32_t  steps 
)
extern

Generates steps steps on the PWM channel.

Parameters
pwmThe PWM channel.
stepsThe number of steps to cycle, 0 to turn off and -1 to run continously.
Warning
Fails with program exit if pwm is outside valid range or if pwm has not been initialized.

Definition at line 103 of file pwm.c.

Here is the call graph for this function: