Module for generating a pulse-width modulated output signal.
More...
|
typedef uint16_t | app_pwm_duty_t |
|
typedef void(* | app_pwm_callback_t )(uint32_t) |
| PWM callback that is executed when a PWM duty change has been completed. More...
|
|
|
enum | app_pwm_polarity_t {
APP_PWM_POLARITY_ACTIVE_LOW = 0,
APP_PWM_POLARITY_ACTIVE_HIGH = 1
} |
| Channel polarity.
|
|
Module for generating a pulse-width modulated output signal.
This module provides a PWM implementation using timers, GPIOTE, and PPI.
Each PWM instance utilizes 1 timer, 2 PPI channels, and 1 PPI channel group plus 2 PPI and 1 GPIOTE channels per PWM channel. The maximum number of PWM channels per instance is 2.
#define APP_PWM_DEFAULT_CONFIG_1CH |
( |
|
period_in_us, |
|
|
|
pin |
|
) |
| |
Value:{ \
.pins = {pin, APP_PWM_NOPIN}, \
.pin_polarity = {APP_PWM_POLARITY_ACTIVE_LOW, APP_PWM_POLARITY_ACTIVE_LOW}, \
.num_of_channels = 1, \
.period_us = period_in_us \
}
PWM instance default configuration (1 channel).
#define APP_PWM_DEFAULT_CONFIG_2CH |
( |
|
period_in_us, |
|
|
|
pin0, |
|
|
|
pin1 |
|
) |
| |
Value:{ \
.pins = {pin0, pin1}, \
.pin_polarity = {APP_PWM_POLARITY_ACTIVE_LOW, APP_PWM_POLARITY_ACTIVE_LOW}, \
.num_of_channels = 2, \
.period_us = period_in_us \
}
PWM instance default configuration (2 channels).
#define APP_PWM_INSTANCE |
( |
|
name, |
|
|
|
num |
|
) |
| |
Value:const nrf_drv_timer_t m_pwm_##name##_timer = NRF_DRV_TIMER_INSTANCE(num); \
\
.p_cb = &m_pwm_##name##_cb, \
.p_timer = &m_pwm_##name##_timer, \
}
Macro for creating a PWM instance.
typedef void(* app_pwm_callback_t)(uint32_t) |
PWM callback that is executed when a PWM duty change has been completed.
- Parameters
-
[in] | pwm_id | PWM instance ID. |
app_pwm_duty_t app_pwm_channel_duty_get |
( |
app_pwm_t const *const |
p_instance, |
|
|
uint8_t |
channel |
|
) |
| |
Function for retrieving the PWM channel duty cycle in percents.
- Parameters
-
[in] | p_instance | PWM instance. |
[in] | channel | Channel number. |
- Returns
- Duty cycle value.
uint32_t app_pwm_channel_duty_set |
( |
app_pwm_t const *const |
p_instance, |
|
|
uint8_t |
channel, |
|
|
app_pwm_duty_t |
duty |
|
) |
| |
Function for setting the PWM channel duty cycle in percents.
A duty cycle change requires one full PWM clock period to finish. If another change is attempted for any channel of given instance before the current change is complete, the new attempt will result in the error NRF_ERROR_BUSY.
- Parameters
-
[in] | p_instance | PWM instance. |
[in] | channel | Channel number. |
[in] | duty | Duty cycle (0 - 100). |
- Return values
-
NRF_SUCCESS | If the operation was successful. |
NRF_ERROR_BUSY | If the PWM is not ready yet. |
NRF_ERROR_INVALID_STATE | If the given instance was not initialized. |
void app_pwm_disable |
( |
app_pwm_t const *const |
p_instance | ) |
|
Function for stopping a PWM instance after initialization.
- Parameters
-
[in] | p_instance | PWM instance. |
- Return values
-
NRF_SUCCESS | If the operation was successful. |
NRF_ERROR_INVALID_STATE | If the given instance was not initialized. |
void app_pwm_enable |
( |
app_pwm_t const *const |
p_instance | ) |
|
Function for enabling a PWM instance after initialization.
- Parameters
-
[in] | p_instance | PWM instance. |
- Return values
-
NRF_SUCCESS | If the operation was successful. |
NRF_ERROR_INVALID_STATE | If the given instance was not initialized. |
Function for initializing a PWM instance.
- Parameters
-
[in] | p_instance | PWM instance. |
[in] | p_config | Initial configuration. |
[in] | p_ready_callback | Pointer to ready callback function (or NULL to disable). |
- Return values
-
NRF_SUCCESS | If initialization was successful. |
NRF_ERROR_NO_MEM | If there were not enough free resources. |
NRF_ERROR_INVALID_PARAM | If an invalid configuration structure was passed. |
NRF_ERROR_INVALID_STATE | If the timer/PWM is already in use or if initialization failed. |
uint32_t app_pwm_uninit |
( |
app_pwm_t const *const |
p_instance | ) |
|
Function for uninitializing a PWM instance and releasing the allocated resources.
- Parameters
-
[in] | p_instance | PWM instance. |
- Return values
-
NRF_SUCCESS | If uninitialization was successful. |
NRF_ERROR_INVALID_STATE | If the given instance was not initialized. |