COMP driver

group nrfx_comp

Comparator (COMP) peripheral driver.

Defines

NRFX_COMP_VOLTAGE_THRESHOLD_TO_INT(vol, ref)

Macro for converting the threshold voltage to an integer value (needed by the COMP_TH register).

Parameters:
  • vol[in] Voltage to be changed to COMP_TH register value. This value must not be smaller than reference voltage divided by 64.

  • ref[in] Reference voltage.

NRFX_COMP_CONFIG_TH

COMP threshold default configuration.

NRFX_COMP_DEFAULT_CONFIG(_input)

COMP driver default configuration.

This configuration sets up COMP with the following options:

  • single-ended mode

  • reference voltage: internal 1.8 V

  • lower threshold: 0.5 V

  • upper threshold: 1.5 V

  • high speed mode

  • hysteresis disabled

  • current source disabled

Parameters:
  • _input[in] Analog input.

Typedefs

typedef void (*nrfx_comp_event_handler_t)(nrf_comp_event_t event)

COMP event handler function type.

Param event:

[in] COMP event.

Enums

enum nrfx_comp_short_mask_t

COMP shortcut masks.

Values:

enumerator NRFX_COMP_SHORT_STOP_AFTER_CROSS_EVT

Shortcut between the CROSS event and the STOP task.

enumerator NRFX_COMP_SHORT_STOP_AFTER_UP_EVT

Shortcut between the UP event and the STOP task.

enumerator NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT

Shortcut between the DOWN event and the STOP task.

enum nrfx_comp_evt_en_mask_t

COMP events masks.

Values:

enumerator NRFX_COMP_EVT_EN_CROSS_MASK

CROSS event (generated after VIN+ == VIN-).

enumerator NRFX_COMP_EVT_EN_UP_MASK

UP event (generated when VIN+ crosses VIN- while increasing).

enumerator NRFX_COMP_EVT_EN_DOWN_MASK

DOWN event (generated when VIN+ crosses VIN- while decreasing).

enumerator NRFX_COMP_EVT_EN_READY_MASK

READY event (generated when the module is ready).

Functions

nrfx_err_t nrfx_comp_init(nrfx_comp_config_t const *p_config, nrfx_comp_event_handler_t event_handler)

Function for initializing the COMP driver.

This function initializes the COMP driver, but does not enable the peripheral or any interrupts. To start the driver, call the function nrfx_comp_start() after initialization.

Parameters:
  • p_config[in] Pointer to the structure with the initial configuration.

  • event_handler[in] Event handler provided by the user. Must not be NULL.

Return values:
  • NRFX_SUCCESS – Initialization was successful.

  • NRFX_ERROR_ALREADY – The driver is already initialized.

  • NRFX_ERROR_INVALID_STATE – The driver is already initialized. Deprecated - use NRFX_ERROR_ALREADY instead.

  • NRFX_ERROR_BUSY – The LPCOMP peripheral is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled.

nrfx_err_t nrfx_comp_reconfigure(nrfx_comp_config_t const *p_config)

Function for reconfiguring the COMP driver.

Parameters:
  • p_config[in] Pointer to the structure with the configuration.

Return values:
  • NRFX_SUCCESS – Reconfiguration was successful.

  • NRFX_ERROR_BUSY – The driver is running and cannot be reconfigured.

  • NRFX_ERROR_INVALID_STATE – The driver is uninitialized.

void nrfx_comp_uninit(void)

Function for uninitializing the COMP driver.

This function uninitializes the COMP driver. The COMP peripheral and its interrupts are disabled, and local variables are cleaned. After this call, you must initialize the driver again by calling nrfx_comp_init() if you want to use it.

See also

nrfx_comp_stop

bool nrfx_comp_init_check(void)

Function for checking if the COMP driver is initialized.

Return values:
  • true – Driver is already initialized.

  • false – Driver is not initialized.

void nrfx_comp_pin_select(nrf_comp_input_t psel)

Function for setting the analog input.

Parameters:
  • psel[in] COMP analog pin selection.

void nrfx_comp_start(uint32_t comp_evt_en_mask, uint32_t comp_shorts_mask)

Function for starting the COMP peripheral and interrupts.

Before calling this function, the driver must be initialized. This function enables the COMP peripheral and its interrupts.

See also

nrfx_comp_init

Parameters:
  • comp_evt_en_mask[in] Mask of events to be enabled. This parameter is to be built as an OR of elements from nrfx_comp_evt_en_mask_t.

  • comp_shorts_mask[in] Mask of shortcuts to be enabled. This parameter is to be built as an OR of elements from nrfx_comp_short_mask_t.

void nrfx_comp_stop(void)

Function for stopping the COMP peripheral.

Before calling this function, the driver must be enabled. This function disables the COMP peripheral and its interrupts.

See also

nrfx_comp_uninit

uint32_t nrfx_comp_sample(void)

Function for copying the current state of the comparator result to the RESULT register.

Return values:
  • 0 – The input voltage is below the threshold (VIN+ < VIN-).

  • 1 – The input voltage is above the threshold (VIN+ > VIN-).

NRFX_STATIC_INLINE uint32_t nrfx_comp_task_address_get(nrf_comp_task_t task)

Function for getting the address of a COMP task.

Parameters:
  • task[in] COMP task.

Returns:

Address of the given COMP task.

NRFX_STATIC_INLINE uint32_t nrfx_comp_event_address_get(nrf_comp_event_t event)

Function for getting the address of a COMP event.

Parameters:
  • event[in] COMP event.

Returns:

Address of the given COMP event.

struct nrfx_comp_config_t
#include <nrfx_comp.h>

COMP configuration.

Public Members

nrf_comp_ref_t reference

Reference selection.

nrf_comp_ext_ref_t ext_ref

External analog reference selection.

nrf_comp_main_mode_t main_mode

Main operation mode.

nrf_comp_th_t threshold

Structure holding THDOWN and THUP values needed by the COMP_TH register.

nrf_comp_sp_mode_t speed_mode

Speed and power mode.

nrf_comp_hyst_t hyst

Comparator hysteresis.

nrf_comp_input_t input

Input to be monitored.

uint8_t interrupt_priority

Interrupt priority.