nRF5 SDK v12.1.0
Data Structures | Macros | Typedefs | Enumerations | Functions

nRF52 only: Hardware access layer for managing the Pulse Width Modulation (PWM) peripheral. More...

Data Structures

struct  nrf_pwm_values_grouped_t
 Structure for defining duty cycle values for a sequence loaded in NRF_PWM_LOAD_GROUPED mode. More...
 
struct  nrf_pwm_values_individual_t
 Structure for defining duty cycle values for a sequence loaded in NRF_PWM_LOAD_INDIVIDUAL mode. More...
 
struct  nrf_pwm_values_wave_form_t
 Structure for defining duty cycle values for a sequence loaded in NRF_PWM_LOAD_WAVE_FORM mode. More...
 
union  nrf_pwm_values_t
 Union grouping pointers to arrays of duty cycle values applicable to various loading modes. More...
 
struct  nrf_pwm_sequence_t
 Structure for defining a sequence of PWM duty cycles. More...
 

Macros

#define NRF_PWM_PIN_NOT_CONNECTED   0xFFFFFFFF
 This value can be provided as a parameter for the nrf_pwm_pins_set function call to specify that a given output channel shall not be connected to a physical pin.
 
#define NRF_PWM_CHANNEL_COUNT   4
 Number of channels in each Pointer to the peripheral registers structure.
 
#define NRF_PWM_VALUES_LENGTH(array)   (sizeof(array) / sizeof(uint16_t))
 Helper macro for calculating the number of 16-bit values in specified array of duty cycle values.
 

Typedefs

typedef uint16_t nrf_pwm_values_common_t
 Type used for defining duty cycle values for a sequence loaded in NRF_PWM_LOAD_COMMON mode.
 

Enumerations

enum  nrf_pwm_task_t {
  NRF_PWM_TASK_STOP = offsetof(NRF_PWM_Type, TASKS_STOP),
  NRF_PWM_TASK_SEQSTART0 = offsetof(NRF_PWM_Type, TASKS_SEQSTART[0]),
  NRF_PWM_TASK_SEQSTART1 = offsetof(NRF_PWM_Type, TASKS_SEQSTART[1]),
  NRF_PWM_TASK_NEXTSTEP = offsetof(NRF_PWM_Type, TASKS_NEXTSTEP)
}
 PWM tasks. More...
 
enum  nrf_pwm_event_t {
  NRF_PWM_EVENT_STOPPED = offsetof(NRF_PWM_Type, EVENTS_STOPPED),
  NRF_PWM_EVENT_SEQSTARTED0 = offsetof(NRF_PWM_Type, EVENTS_SEQSTARTED[0]),
  NRF_PWM_EVENT_SEQSTARTED1 = offsetof(NRF_PWM_Type, EVENTS_SEQSTARTED[1]),
  NRF_PWM_EVENT_SEQEND0 = offsetof(NRF_PWM_Type, EVENTS_SEQEND[0]),
  NRF_PWM_EVENT_SEQEND1 = offsetof(NRF_PWM_Type, EVENTS_SEQEND[1]),
  NRF_PWM_EVENT_PWMPERIODEND = offsetof(NRF_PWM_Type, EVENTS_PWMPERIODEND),
  NRF_PWM_EVENT_LOOPSDONE = offsetof(NRF_PWM_Type, EVENTS_LOOPSDONE)
}
 PWM events. More...
 
enum  nrf_pwm_int_mask_t {
  NRF_PWM_INT_STOPPED_MASK = PWM_INTENSET_STOPPED_Msk,
  NRF_PWM_INT_SEQSTARTED0_MASK = PWM_INTENSET_SEQSTARTED0_Msk,
  NRF_PWM_INT_SEQSTARTED1_MASK = PWM_INTENSET_SEQSTARTED1_Msk,
  NRF_PWM_INT_SEQEND0_MASK = PWM_INTENSET_SEQEND0_Msk,
  NRF_PWM_INT_SEQEND1_MASK = PWM_INTENSET_SEQEND1_Msk,
  NRF_PWM_INT_PWMPERIODEND_MASK = PWM_INTENSET_PWMPERIODEND_Msk,
  NRF_PWM_INT_LOOPSDONE_MASK = PWM_INTENSET_LOOPSDONE_Msk
}
 PWM interrupts. More...
 
enum  nrf_pwm_short_mask_t {
  NRF_PWM_SHORT_SEQEND0_STOP_MASK = PWM_SHORTS_SEQEND0_STOP_Msk,
  NRF_PWM_SHORT_SEQEND1_STOP_MASK = PWM_SHORTS_SEQEND1_STOP_Msk,
  NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK = PWM_SHORTS_LOOPSDONE_SEQSTART0_Msk,
  NRF_PWM_SHORT_LOOPSDONE_SEQSTART1_MASK = PWM_SHORTS_LOOPSDONE_SEQSTART1_Msk,
  NRF_PWM_SHORT_LOOPSDONE_STOP_MASK = PWM_SHORTS_LOOPSDONE_STOP_Msk
}
 PWM shortcuts. More...
 
enum  nrf_pwm_mode_t {
  NRF_PWM_MODE_UP = PWM_MODE_UPDOWN_Up,
  NRF_PWM_MODE_UP_AND_DOWN = PWM_MODE_UPDOWN_UpAndDown
}
 PWM modes of operation. More...
 
enum  nrf_pwm_clk_t {
  NRF_PWM_CLK_16MHz = PWM_PRESCALER_PRESCALER_DIV_1,
  NRF_PWM_CLK_8MHz = PWM_PRESCALER_PRESCALER_DIV_2,
  NRF_PWM_CLK_4MHz = PWM_PRESCALER_PRESCALER_DIV_4,
  NRF_PWM_CLK_2MHz = PWM_PRESCALER_PRESCALER_DIV_8,
  NRF_PWM_CLK_1MHz = PWM_PRESCALER_PRESCALER_DIV_16,
  NRF_PWM_CLK_500kHz = PWM_PRESCALER_PRESCALER_DIV_32,
  NRF_PWM_CLK_250kHz = PWM_PRESCALER_PRESCALER_DIV_64,
  NRF_PWM_CLK_125kHz = PWM_PRESCALER_PRESCALER_DIV_128
}
 PWM base clock frequencies. More...
 
enum  nrf_pwm_dec_load_t {
  NRF_PWM_LOAD_COMMON = PWM_DECODER_LOAD_Common,
  NRF_PWM_LOAD_GROUPED = PWM_DECODER_LOAD_Grouped,
  NRF_PWM_LOAD_INDIVIDUAL = PWM_DECODER_LOAD_Individual,
  NRF_PWM_LOAD_WAVE_FORM = PWM_DECODER_LOAD_WaveForm
}
 PWM decoder load modes. More...
 
enum  nrf_pwm_dec_step_t {
  NRF_PWM_STEP_AUTO = PWM_DECODER_MODE_RefreshCount,
  NRF_PWM_STEP_TRIGGERED = PWM_DECODER_MODE_NextStep
}
 PWM decoder next step modes. More...
 

Functions

__STATIC_INLINE void nrf_pwm_task_trigger (NRF_PWM_Type *p_reg, nrf_pwm_task_t task)
 Function for activating a specific PWM task. More...
 
__STATIC_INLINE uint32_t nrf_pwm_task_address_get (NRF_PWM_Type const *p_reg, nrf_pwm_task_t task)
 Function for getting the address of a specific PWM task register. More...
 
__STATIC_INLINE void nrf_pwm_event_clear (NRF_PWM_Type *p_reg, nrf_pwm_event_t event)
 Function for clearing a specific PWM event. More...
 
__STATIC_INLINE bool nrf_pwm_event_check (NRF_PWM_Type const *p_reg, nrf_pwm_event_t event)
 Function for checking the state of a specific PWM event. More...
 
__STATIC_INLINE uint32_t nrf_pwm_event_address_get (NRF_PWM_Type const *p_reg, nrf_pwm_event_t event)
 Function for getting the address of a specific PWM event register. More...
 
__STATIC_INLINE void nrf_pwm_shorts_enable (NRF_PWM_Type *p_reg, uint32_t pwm_shorts_mask)
 Function for enabling specified shortcuts. More...
 
__STATIC_INLINE void nrf_pwm_shorts_disable (NRF_PWM_Type *p_reg, uint32_t pwm_shorts_mask)
 Function for disabling specified shortcuts. More...
 
__STATIC_INLINE void nrf_pwm_shorts_set (NRF_PWM_Type *p_reg, uint32_t pwm_shorts_mask)
 Function for setting the configuration of PWM shortcuts. More...
 
__STATIC_INLINE void nrf_pwm_int_enable (NRF_PWM_Type *p_reg, uint32_t pwm_int_mask)
 Function for enabling specified interrupts. More...
 
__STATIC_INLINE void nrf_pwm_int_disable (NRF_PWM_Type *p_reg, uint32_t pwm_int_mask)
 Function for disabling specified interrupts. More...
 
__STATIC_INLINE void nrf_pwm_int_set (NRF_PWM_Type *p_reg, uint32_t pwm_int_mask)
 Function for setting the configuration of PWM interrupts. More...
 
__STATIC_INLINE bool nrf_pwm_int_enable_check (NRF_PWM_Type const *p_reg, nrf_pwm_int_mask_t pwm_int)
 Function for retrieving the state of a given interrupt. More...
 
__STATIC_INLINE void nrf_pwm_enable (NRF_PWM_Type *p_reg)
 Function for enabling the PWM peripheral. More...
 
__STATIC_INLINE void nrf_pwm_disable (NRF_PWM_Type *p_reg)
 Function for disabling the PWM peripheral. More...
 
__STATIC_INLINE void nrf_pwm_pins_set (NRF_PWM_Type *p_reg, uint32_t out_pins[4])
 Function for assigning pins to PWM output channels. More...
 
__STATIC_INLINE void nrf_pwm_configure (NRF_PWM_Type *p_reg, nrf_pwm_clk_t base_clock, nrf_pwm_mode_t mode, uint16_t top_value)
 Function for configuring the PWM peripheral. More...
 
__STATIC_INLINE void nrf_pwm_sequence_set (NRF_PWM_Type *p_reg, uint8_t seq_id, nrf_pwm_sequence_t const *p_seq)
 Function for defining a sequence of PWM duty cycles. More...
 
__STATIC_INLINE void nrf_pwm_seq_ptr_set (NRF_PWM_Type *p_reg, uint8_t seq_id, uint16_t const *p_values)
 Function for modifying the pointer to the duty cycle values in the specified sequence. More...
 
__STATIC_INLINE void nrf_pwm_seq_cnt_set (NRF_PWM_Type *p_reg, uint8_t seq_id, uint16_t length)
 Function for modifying the total number of duty cycle values in the specified sequence. More...
 
__STATIC_INLINE void nrf_pwm_seq_refresh_set (NRF_PWM_Type *p_reg, uint8_t seq_id, uint32_t refresh)
 Function for modifying the additional number of PWM periods spent on each duty cycle value in the specified sequence. More...
 
__STATIC_INLINE void nrf_pwm_seq_end_delay_set (NRF_PWM_Type *p_reg, uint8_t seq_id, uint32_t end_delay)
 Function for modifying the additional time added after the sequence is played. More...
 
__STATIC_INLINE void nrf_pwm_decoder_set (NRF_PWM_Type *p_reg, nrf_pwm_dec_load_t dec_load, nrf_pwm_dec_step_t dec_step)
 Function for setting the mode of loading sequence data from RAM and advancing the sequence. More...
 
__STATIC_INLINE void nrf_pwm_loop_set (NRF_PWM_Type *p_reg, uint16_t loop_count)
 Function for setting the number of times the sequence playback should be performed. More...
 

Detailed Description

nRF52 only: Hardware access layer for managing the Pulse Width Modulation (PWM) peripheral.

Enumeration Type Documentation

PWM base clock frequencies.

Enumerator
NRF_PWM_CLK_16MHz 

16 MHz / 1 = 16 MHz.

NRF_PWM_CLK_8MHz 

16 MHz / 2 = 8 MHz.

NRF_PWM_CLK_4MHz 

16 MHz / 4 = 4 MHz.

NRF_PWM_CLK_2MHz 

16 MHz / 8 = 2 MHz.

NRF_PWM_CLK_1MHz 

16 MHz / 16 = 1 MHz.

NRF_PWM_CLK_500kHz 

16 MHz / 32 = 500 kHz.

NRF_PWM_CLK_250kHz 

16 MHz / 64 = 250 kHz.

NRF_PWM_CLK_125kHz 

16 MHz / 128 = 125 kHz.

PWM decoder load modes.

The selected mode determines how the sequence data is read from RAM and spread to the compare registers.

Enumerator
NRF_PWM_LOAD_COMMON 

1st half word (16-bit) used in all PWM channels (0-3).

NRF_PWM_LOAD_GROUPED 

1st half word (16-bit) used in channels 0 and 1; 2nd word in channels 2 and 3.

NRF_PWM_LOAD_INDIVIDUAL 

1st half word (16-bit) used in channel 0; 2nd in channel 1; 3rd in channel 2; 4th in channel 3.

NRF_PWM_LOAD_WAVE_FORM 

1st half word (16-bit) used in channel 0; 2nd in channel 1; ... ; 4th as the top value for the pulse generator counter.

PWM decoder next step modes.

The selected mode determines when the next value from the active sequence is loaded.

Enumerator
NRF_PWM_STEP_AUTO 

Automatically after the current value is played and repeated the requested number of times.

NRF_PWM_STEP_TRIGGERED 

When the NRF_PWM_TASK_NEXTSTEP task is triggered.

PWM events.

Enumerator
NRF_PWM_EVENT_STOPPED 

Response to STOP task, emitted when PWM pulses are no longer generated.

NRF_PWM_EVENT_SEQSTARTED0 

First PWM period started on sequence 0.

NRF_PWM_EVENT_SEQSTARTED1 

First PWM period started on sequence 1.

NRF_PWM_EVENT_SEQEND0 

Emitted at the end of every sequence 0 when its last value has been read from RAM.

NRF_PWM_EVENT_SEQEND1 

Emitted at the end of every sequence 1 when its last value has been read from RAM.

NRF_PWM_EVENT_PWMPERIODEND 

Emitted at the end of each PWM period.

NRF_PWM_EVENT_LOOPSDONE 

Concatenated sequences have been played the requested number of times.

PWM interrupts.

Enumerator
NRF_PWM_INT_STOPPED_MASK 

Interrupt on STOPPED event.

NRF_PWM_INT_SEQSTARTED0_MASK 

Interrupt on SEQSTARTED[0] event.

NRF_PWM_INT_SEQSTARTED1_MASK 

Interrupt on SEQSTARTED[1] event.

NRF_PWM_INT_SEQEND0_MASK 

Interrupt on SEQEND[0] event.

NRF_PWM_INT_SEQEND1_MASK 

Interrupt on SEQEND[1] event.

NRF_PWM_INT_PWMPERIODEND_MASK 

Interrupt on PWMPERIODEND event.

NRF_PWM_INT_LOOPSDONE_MASK 

Interrupt on LOOPSDONE event.

PWM modes of operation.

Enumerator
NRF_PWM_MODE_UP 

Up counter (edge-aligned PWM duty cycle).

NRF_PWM_MODE_UP_AND_DOWN 

Up and down counter (center-aligned PWM duty cycle).

PWM shortcuts.

Enumerator
NRF_PWM_SHORT_SEQEND0_STOP_MASK 

Shortcut between SEQEND[0] event and STOP task.

NRF_PWM_SHORT_SEQEND1_STOP_MASK 

Shortcut between SEQEND[1] event and STOP task.

NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK 

Shortcut between LOOPSDONE event and SEQSTART[0] task.

NRF_PWM_SHORT_LOOPSDONE_SEQSTART1_MASK 

Shortcut between LOOPSDONE event and SEQSTART[1] task.

NRF_PWM_SHORT_LOOPSDONE_STOP_MASK 

Shortcut between LOOPSDONE event and STOP task.

PWM tasks.

Enumerator
NRF_PWM_TASK_STOP 

Stops PWM pulse generation on all channels at the end of the current PWM period, and stops the sequence playback.

NRF_PWM_TASK_SEQSTART0 

Starts playback of sequence 0.

NRF_PWM_TASK_SEQSTART1 

Starts playback of sequence 1.

NRF_PWM_TASK_NEXTSTEP 

Steps by one value in the current sequence if the decoder is set to NRF_PWM_STEP_TRIGGERED mode.

Function Documentation

__STATIC_INLINE void nrf_pwm_configure ( NRF_PWM_Type *  p_reg,
nrf_pwm_clk_t  base_clock,
nrf_pwm_mode_t  mode,
uint16_t  top_value 
)

Function for configuring the PWM peripheral.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]base_clockBase clock frequency.
[in]modeOperating mode of the pulse generator counter.
[in]top_valueValue up to which the pulse generator counter counts.
__STATIC_INLINE void nrf_pwm_decoder_set ( NRF_PWM_Type *  p_reg,
nrf_pwm_dec_load_t  dec_load,
nrf_pwm_dec_step_t  dec_step 
)

Function for setting the mode of loading sequence data from RAM and advancing the sequence.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]dec_loadMode of loading sequence data from RAM.
[in]dec_stepMode of advancing the active sequence.
__STATIC_INLINE void nrf_pwm_disable ( NRF_PWM_Type *  p_reg)

Function for disabling the PWM peripheral.

Parameters
[in]p_regPointer to the peripheral registers structure.
__STATIC_INLINE void nrf_pwm_enable ( NRF_PWM_Type *  p_reg)

Function for enabling the PWM peripheral.

Parameters
[in]p_regPointer to the peripheral registers structure.
__STATIC_INLINE uint32_t nrf_pwm_event_address_get ( NRF_PWM_Type const *  p_reg,
nrf_pwm_event_t  event 
)

Function for getting the address of a specific PWM event register.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]eventRequested event.
Returns
Address of the specified event register.
__STATIC_INLINE bool nrf_pwm_event_check ( NRF_PWM_Type const *  p_reg,
nrf_pwm_event_t  event 
)

Function for checking the state of a specific PWM event.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]eventEvent to check.
Return values
trueIf the event is set.
falseIf the event is not set.
__STATIC_INLINE void nrf_pwm_event_clear ( NRF_PWM_Type *  p_reg,
nrf_pwm_event_t  event 
)

Function for clearing a specific PWM event.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]eventEvent to clear.
__STATIC_INLINE void nrf_pwm_int_disable ( NRF_PWM_Type *  p_reg,
uint32_t  pwm_int_mask 
)

Function for disabling specified interrupts.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]pwm_int_maskInterrupts to disable.
__STATIC_INLINE void nrf_pwm_int_enable ( NRF_PWM_Type *  p_reg,
uint32_t  pwm_int_mask 
)

Function for enabling specified interrupts.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]pwm_int_maskInterrupts to enable.
__STATIC_INLINE bool nrf_pwm_int_enable_check ( NRF_PWM_Type const *  p_reg,
nrf_pwm_int_mask_t  pwm_int 
)

Function for retrieving the state of a given interrupt.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]pwm_intInterrupt to check.
Return values
trueIf the interrupt is enabled.
falseIf the interrupt is not enabled.
__STATIC_INLINE void nrf_pwm_int_set ( NRF_PWM_Type *  p_reg,
uint32_t  pwm_int_mask 
)

Function for setting the configuration of PWM interrupts.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]pwm_int_maskInterrupts configuration to set.
__STATIC_INLINE void nrf_pwm_loop_set ( NRF_PWM_Type *  p_reg,
uint16_t  loop_count 
)

Function for setting the number of times the sequence playback should be performed.

This function applies to two-sequence playback (concatenated sequence 0 and 1). A single sequence can be played back only once.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]loop_countNumber of times to perform the sequence playback.
__STATIC_INLINE void nrf_pwm_pins_set ( NRF_PWM_Type *  p_reg,
uint32_t  out_pins[4] 
)

Function for assigning pins to PWM output channels.

Usage of all PWM output channels is optional. If a given channel is not needed, pass the NRF_PWM_PIN_NOT_CONNECTED value instead of its pin number.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]out_pinsArray with pin numbers for individual PWM output channels.
__STATIC_INLINE void nrf_pwm_seq_cnt_set ( NRF_PWM_Type *  p_reg,
uint8_t  seq_id,
uint16_t  length 
)

Function for modifying the total number of duty cycle values in the specified sequence.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]seq_idIdentifier of the sequence (0 or 1).
[in]lengthNumber of duty cycle values.
__STATIC_INLINE void nrf_pwm_seq_end_delay_set ( NRF_PWM_Type *  p_reg,
uint8_t  seq_id,
uint32_t  end_delay 
)

Function for modifying the additional time added after the sequence is played.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]seq_idIdentifier of the sequence (0 or 1).
[in]end_delayNumber of PWM periods added at the end of the sequence.
__STATIC_INLINE void nrf_pwm_seq_ptr_set ( NRF_PWM_Type *  p_reg,
uint8_t  seq_id,
uint16_t const *  p_values 
)

Function for modifying the pointer to the duty cycle values in the specified sequence.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]seq_idIdentifier of the sequence (0 or 1).
[in]p_valuesPointer to an array with duty cycle values.
__STATIC_INLINE void nrf_pwm_seq_refresh_set ( NRF_PWM_Type *  p_reg,
uint8_t  seq_id,
uint32_t  refresh 
)

Function for modifying the additional number of PWM periods spent on each duty cycle value in the specified sequence.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]seq_idIdentifier of the sequence (0 or 1).
[in]refreshNumber of additional PWM periods for each duty cycle value.
__STATIC_INLINE void nrf_pwm_sequence_set ( NRF_PWM_Type *  p_reg,
uint8_t  seq_id,
nrf_pwm_sequence_t const *  p_seq 
)

Function for defining a sequence of PWM duty cycles.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]seq_idIdentifier of the sequence (0 or 1).
[in]p_seqPointer to the sequence definition.
__STATIC_INLINE void nrf_pwm_shorts_disable ( NRF_PWM_Type *  p_reg,
uint32_t  pwm_shorts_mask 
)

Function for disabling specified shortcuts.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]pwm_shorts_maskShortcuts to disable.
__STATIC_INLINE void nrf_pwm_shorts_enable ( NRF_PWM_Type *  p_reg,
uint32_t  pwm_shorts_mask 
)

Function for enabling specified shortcuts.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]pwm_shorts_maskShortcuts to enable.
__STATIC_INLINE void nrf_pwm_shorts_set ( NRF_PWM_Type *  p_reg,
uint32_t  pwm_shorts_mask 
)

Function for setting the configuration of PWM shortcuts.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]pwm_shorts_maskShortcuts configuration to set.
__STATIC_INLINE uint32_t nrf_pwm_task_address_get ( NRF_PWM_Type const *  p_reg,
nrf_pwm_task_t  task 
)

Function for getting the address of a specific PWM task register.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]taskRequested task.
Returns
Address of the specified task register.
__STATIC_INLINE void nrf_pwm_task_trigger ( NRF_PWM_Type *  p_reg,
nrf_pwm_task_t  task 
)

Function for activating a specific PWM task.

Parameters
[in]p_regPointer to the peripheral registers structure.
[in]taskTask to activate.

Documentation feedback | Developer Zone | Subscribe | Updated