class::hal::Pwm

class hal::Pwm
  : public hal::Periph< pwm_info_t, pwm_attr_t, PwmAttributes, PWM_IOC_IDENT_CHAR >

This class implements PWM outputs.

Here is an example of how to use the Pwm class

#include <sapi/hal.hpp>

Pwm pwm(1); //use PWM port 1
PwmPinAssignment pin_assignment;
pin_assignment->channel[0] = mcu_pin(1,20); //Use Pin 1.20
pwm.init(Pwm::SET_TIMER | Pwm::IS_ENABLED, 24000000, 1000, pin_assignment);
pwm.set_channel(2, 500);

Summary

Pwm(

port_t port
)

int disable() const

int enable() const

int get_channel(

u32 loc
)

u32 get_channel()

int set_channel(

u32 loc,
u32 value
) const

int set_channel(

const mcu_channel_t & channel
) const

int set_channels(

const pwm_pin_assignment_t * pin_assignment
)

enum pwm_flags

Members

Pwm(

port_t port
)


int disable() const

Disables the PWM timer.

See also: enable()


int enable() const

Enables the PWM timer.

Returns

Zero on success

This method can be used with disable() to start and stop the PWM timer while preserving the attributes.


int get_channel(

u32 loc
)

Gets the channel value.

Parameters

  • loc Channel location

Returns

The value of the channel or (u32)-1 for an error


u32 get_channel()

int set_channel(

u32 loc,
u32 value
) const

Sets the channel to the specified value.

Parameters

  • loc The channel location (number)

  • value The value to assign to the channel

Returns

Zero on success


int set_channel(

const mcu_channel_t & channel
) const

Sets the channel using the channel reference.

Parameters

  • channel The channel location and value

Returns

Zero on success


int set_channels(

const pwm_pin_assignment_t * pin_assignment
)

Sets the channel configuration.

Parameters

  • pin_assignment A pointer to the pin assignment

Returns

Zero on success

This method is equivalent to set_attr() with o_flags set to PWM::FLAG_SET_CHANNELS.


enum pwm_flags

X

Thanks for Coming!

Subscribe to news and updates