| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
Low-power PWM
SDK common libraries

Module for generating a low-power pulse-width modulated output signal. More...

## Modules
| low_power_pwm module configuration

## Data Structures
struct | low_power_pwm_config_t
| Structure holding the initialization parameters. More...

## Macros
#define | LOW_POWER_PWM_DEFAULT_CONFIG(mask)
| Low-power PWM default configuration. More...

## Typedefs
typedef void(* | low_power_pwm_timeout_user )(void *p_context, low_power_pwm_evt_type_t evt_type)
| Application time-out handler type.
typedef struct low_power_pwm_s | low_power_pwm_t
| Internal structure holding parameters of a low-power PWM instance.

## Enumerations
enum | low_power_pwm_evt_type_t { LOW_POWER_PWM_EVENT_PERIOD = 0, LOW_POWER_PWM_EVENT_DUTY_CYCLE }
| Event types.

## Functions
ret_code_t | low_power_pwm_init (low_power_pwm_t *p_pwm_instance, low_power_pwm_config_t const *p_pwm_config, app_timer_timeout_handler_t handler)
| Function for initializing a low-power PWM instance. More...
ret_code_t | low_power_pwm_start (low_power_pwm_t *p_pwm_instance, uint32_t leds_pin_bit_mask)
| Function for starting a low-power PWM instance. More...
ret_code_t | low_power_pwm_stop (low_power_pwm_t *p_pwm_instance)
| Function for stopping a low-power PWM instance. More...
ret_code_t | low_power_pwm_duty_set (low_power_pwm_t *p_pwm_instance, uint8_t duty_cycle)
| Function for setting a new high pulse width for a given instance. More...

## Default settings
Default parameters for the low_power_pwm_config_t structure.
#define | LOW_POWER_PWM_CONFIG_ACTIVE_HIGH false
#define | LOW_POWER_PWM_CONFIG_PERIOD UINT8_MAX
#define | LOW_POWER_PWM_CONFIG_BIT_MASK(mask) (mask)

## Detailed Description

Module for generating a low-power pulse-width modulated output signal.

This module provides a low-power PWM implementation using app_timers and GPIO.

Each low-power PWM instance utilizes one app_timer. This means it runs on RTC and does not require HFCLK to be running. There can be any number of output channels per instance.

## Macro Definition Documentation

#define LOW_POWER_PWM_DEFAULT_CONFIG | ( |  | mask | ) |

Value:
{ \
.active_high = LOW_POWER_PWM_CONFIG_ACTIVE_HIGH , \
.period = LOW_POWER_PWM_CONFIG_PERIOD , \
.bit_mask = LOW_POWER_PWM_CONFIG_BIT_MASK(mask) \
}

Low-power PWM default configuration.

## Function Documentation

ret_code_t low_power_pwm_duty_set | ( | low_power_pwm_t * | p_pwm_instance,
|  | uint8_t | duty_cycle
| ) |  |

Function for setting a new high pulse width for a given instance.

This function can be called from the timer handler.

Parameters

  [in] | p_pwm_instance | Pointer to the instance to be changed.
  [in] | duty_cycle | New high pulse width. 0 means that the LED is always off. 255 means that it is always on.

Return values

  NRF_SUCCESS | If the function completed successfully.
  NRF_ERROR_INVALID_PARAM | If the function returned an error because of invalid parameters.

ret_code_t low_power_pwm_init | ( | low_power_pwm_t * | p_pwm_instance,
|  | low_power_pwm_config_t const * | p_pwm_config,
|  | app_timer_timeout_handler_t | handler
| ) |  |

Function for initializing a low-power PWM instance.

Parameters

  [in] | p_pwm_instance | Pointer to the instance to be started.
  [in] | p_pwm_config | Pointer to the configuration structure.
  [in] | handler | User function to be called in case of time-out.

Returns
  Values returned by app_timer_create.

ret_code_t low_power_pwm_start | ( | low_power_pwm_t * | p_pwm_instance,
|  | uint32_t | leds_pin_bit_mask
| ) |  |

Function for starting a low-power PWM instance.

Parameters

  [in] | p_pwm_instance | Pointer to the instance to be started.
  [in] | leds_pin_bit_mask | Bit mask of pins to be started.

Returns
  Values returned by app_timer_start.

ret_code_t low_power_pwm_stop | ( | low_power_pwm_t * | p_pwm_instance | ) |

Function for stopping a low-power PWM instance.

Parameters

  [in] | p_pwm_instance | Pointer to the instance to be stopped.

Returns
  Values returned by app_timer_stop.