pwm.h

Low-level PWM peripheral driver interface definitions.

PWM_DEV( x)

Default PWM access macro.

1
(x)
PWM_UNDEF

Default PWM undefined value.

1
(UINT_MAX)
enum pwm_mode_t
PWM_CENTER_INV = PWM_MODE(1, 0)
not supported
PWM_LEFT = PWM_MODE(0, 1)
left aligned PWM
PWM_RIGHT = PWM_MODE(0, 0)
right aligned PWM
PWM_CENTER = PWM_MODE(1, 1)
not supported
unsigned int pwm_t

Default PWM type definition.

uint32_t pwm_init(pwm.h::pwm_t dev, nrf52/include/periph_cpu.h::pwm_mode_t mode, uint32_t freq, uint16_t res)

Initialize a PWM device.

The PWM module is based on virtual PWM devices, which can have one or more channels. The PWM devices can be configured to run with a given frequency and resolution, which are always identical for the complete device, hence for every channel on a device.

The desired frequency and resolution may not be possible on a given device when chosen too large. In this case the PWM driver will always keep the resolution and decrease the frequency if needed. To verify the correct settings compare the returned value which is the actually set frequency.

Parameters

dev:PWM device to initialize
mode:PWM mode, left, right or center aligned
freq:PWM frequency in Hz
res:PWM resolution

Return values

  • actual PWM frequency on success
  • 0 on error
uint8_t pwm_channels(pwm.h::pwm_t dev)

Get the number of available channels.

Parameters

dev:PWM device

Return values

  • Number of channels available for the given device
void pwm_set(pwm.h::pwm_t dev, uint8_t channel, uint16_t value)

Set the duty-cycle for a given channel of the given PWM device.

The duty-cycle is set in relation to the chosen resolution of the given device. If value > resolution, value is set to resolution.

Parameters

dev:the PWM device to set
channel:the channel of the given device to set
value:the desired duty-cycle to set

void pwm_poweron(pwm.h::pwm_t dev)

Resume PWM generation on the given device.

When this function is called, the given PWM device is powered on and continues its previously configured operation. The duty cycle of each channel will be the value that was last set.

This function must not be called before the PWM device was initialized.

Parameters

dev:device to start

void pwm_poweroff(pwm.h::pwm_t dev)

Stop PWM generation on the given device.

This function stops the PWM generation on all configured channels for the given device and powers down the given PWM peripheral.

Parameters

dev:device to stop