mraa  0.6.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Pages
Functions | Typedefs
pwm.h File Reference

API Description

PWM is the Pulse Width Modulation interface to libmraa. It allows the generation of a signal on a pin. Some boards may have higher or lower levels of resolution so make sure you check the board & pin you are using before hand.

mraa_pwm_context pwm;
pwm = mraa_pwm_init(3);
if (pwm == NULL) {
return 1;
}
mraa_pwm_period_us(pwm, 200);
mraa_pwm_enable(pwm, 1);
float value = 0.0f;
while (1) {
value = value + 0.01f;
mraa_pwm_write(pwm, value);
usleep(50000);
if (value >= 1.0f) {
value = 0.0f;
}
float output = mraa_pwm_read(pwm);
}

Go to the source code of this file.

Functions

mraa_pwm_context mraa_pwm_init (int pin)
 
mraa_pwm_context mraa_pwm_init_raw (int chipid, int pin)
 
mraa_result_t mraa_pwm_write (mraa_pwm_context dev, float percentage)
 
float mraa_pwm_read (mraa_pwm_context dev)
 
mraa_result_t mraa_pwm_period (mraa_pwm_context dev, float seconds)
 
mraa_result_t mraa_pwm_period_ms (mraa_pwm_context dev, int ms)
 
mraa_result_t mraa_pwm_period_us (mraa_pwm_context dev, int us)
 
mraa_result_t mraa_pwm_pulsewidth (mraa_pwm_context dev, float seconds)
 
mraa_result_t mraa_pwm_pulsewidth_ms (mraa_pwm_context dev, int ms)
 
mraa_result_t mraa_pwm_pulsewidth_us (mraa_pwm_context dev, int us)
 
mraa_result_t mraa_pwm_enable (mraa_pwm_context dev, int enable)
 
mraa_result_t mraa_pwm_owner (mraa_pwm_context dev, mraa_boolean_t owner)
 
mraa_result_t mraa_pwm_close (mraa_pwm_context dev)
 
mraa_result_t mraa_pwm_config_ms (mraa_pwm_context dev, int period, float duty)
 
mraa_result_t mraa_pwm_config_percent (mraa_pwm_context dev, int period, float duty)
 

Typedefs

typedef struct _pwm * mraa_pwm_context
 

Function Documentation

mraa_pwm_context mraa_pwm_init ( int  pin)

Initialise pwm_context, uses board mapping

Parameters
pinThe PWM PIN
Returns
pwm context or NULL

Here is the caller graph for this function:

mraa_pwm_context mraa_pwm_init_raw ( int  chipid,
int  pin 
)

Initialise pwm_context, raw mode

Parameters
chipidThe chip inwhich the PWM is under in SYSFS
pinThe PWM PIN.
Returns
pwm context or NULL

Here is the caller graph for this function:

mraa_result_t mraa_pwm_write ( mraa_pwm_context  dev,
float  percentage 
)

Set the ouput duty-cycle percentage, as a float

Parameters
devThe Pwm context to use
percentageA floating-point value representing percentage of output. The value should lie between 0.0f (representing on 0%) and 1.0f Values above or below this range will be set at either 0.0f or 1.0f
Returns
Result of operation

Here is the caller graph for this function:

float mraa_pwm_read ( mraa_pwm_context  dev)

Read the ouput duty-cycle percentage, as a float

Parameters
devThe Pwm context to use
Returns
percentage A floating-point value representing percentage of output. The value should lie between 0.0f (representing on 0%) and 1.0f Values above or below this range will be set at either 0.0f or 1.0f

Here is the caller graph for this function:

mraa_result_t mraa_pwm_period ( mraa_pwm_context  dev,
float  seconds 
)

Set the PWM period as seconds represented in a float

Parameters
devThe Pwm context to use
secondsPeriod represented as a float in seconds
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_pwm_period_ms ( mraa_pwm_context  dev,
int  ms 
)

Set period, milliseconds.

Parameters
devThe Pwm context to use
msMilliseconds for period
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_pwm_period_us ( mraa_pwm_context  dev,
int  us 
)

Set period, microseconds

Parameters
devThe Pwm context to use
usMicroseconds as period
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_pwm_pulsewidth ( mraa_pwm_context  dev,
float  seconds 
)

Set pulsewidth, As represnted by seconds in a (float)

Parameters
devThe Pwm context to use
secondsThe duration of a pulse
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_pwm_pulsewidth_ms ( mraa_pwm_context  dev,
int  ms 
)

Set pulsewidth, milliseconds

Parameters
devThe Pwm context to use
msMilliseconds for pulsewidth
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_pwm_pulsewidth_us ( mraa_pwm_context  dev,
int  us 
)

Set pulsewidth, microseconds

Parameters
devThe Pwm context to use
usMicroseconds for pulsewidth
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_pwm_enable ( mraa_pwm_context  dev,
int  enable 
)

Set the enable status of the PWM pin. None zero will assume on with output being driven. and 0 will disable the output.

Parameters
devThe pwm context to use
enableToggle status of pin
Returns
Result of operation.

Here is the caller graph for this function:

mraa_result_t mraa_pwm_owner ( mraa_pwm_context  dev,
mraa_boolean_t  owner 
)

Change ownership of context

Parameters
devthe context
ownerOwnership boolean
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_pwm_close ( mraa_pwm_context  dev)

Close and unexport the PWM pin

Parameters
devThe pwm context to use
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_pwm_config_ms ( mraa_pwm_context  dev,
int  period,
float  duty 
)

Set Both Period and DutyCycle on a PWM context

Parameters
devThe pwm context to use
periodrepresented in ms.
dutydutycycle of the pwm signal.
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_pwm_config_percent ( mraa_pwm_context  dev,
int  period,
float  duty 
)

Set Both Period and DutyCycle on a PWM context. Duty represented as percentage.

Parameters
devThe pwm context to use
periodrepresented in ms.
dutyduty percantage. i.e. 50% = 0.5f
Returns
Result of operation

Here is the caller graph for this function:

Include dependency graph for pwm.h: