libpynq (release 5EWC0-2023 version 0.2.0 of 2023-08-28 20:33)
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)

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 4 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)

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 8 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 7 of file pwm.c.

Here is the call graph for this function:

◆ pwm_get_steps()

uint32_t pwm_get_steps ( const int  pwm)

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 10 of file pwm.c.

Here is the call graph for this function:

◆ pwm_init()

void pwm_init ( const int  pwm,
const uint32_t  period 
)

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 3 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)

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 2 of file pwm.c.

◆ pwm_set_duty_cycle()

void pwm_set_duty_cycle ( const int  pwm,
const uint32_t  duty 
)

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 5 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 
)

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 6 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 
)

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 9 of file pwm.c.

Here is the call graph for this function: