nrfx 4.5.0
Loading...
Searching...
No Matches
COMP driver

Comparator (COMP) peripheral driver. More...

Topics

 COMP peripheral driver configuration
 

Data Structures

struct  nrfx_comp_config_t
 COMP configuration. More...
 

Macros

#define NRFX_COMP_VOLTAGE_THRESHOLD_TO_INT(vol, ref)
 Macro for converting the threshold voltage to an integer value (needed by the COMP_TH register).
 
#define NRFX_COMP_CONFIG_TH
 COMP threshold default configuration.
 
#define NRFX_COMP_DEFAULT_CONFIG(_input)
 COMP driver default configuration.
 

Typedefs

typedef void(* nrfx_comp_event_handler_t) (nrf_comp_event_t event)
 COMP event handler function type.
 

Functions

int nrfx_comp_init (nrfx_comp_config_t const *p_config, nrfx_comp_event_handler_t event_handler)
 Function for initializing the COMP driver.
 
int nrfx_comp_reconfigure (nrfx_comp_config_t const *p_config)
 Function for reconfiguring the COMP driver.
 
void nrfx_comp_uninit (void)
 Function for uninitializing the COMP driver.
 
bool nrfx_comp_init_check (void)
 Function for checking if the COMP driver is initialized.
 
int nrfx_comp_pin_select (nrfx_analog_input_t psel)
 Function for setting the analog input.
 
void nrfx_comp_start (uint32_t comp_evt_en_mask, uint32_t comp_shorts_mask)
 Function for starting the COMP peripheral and interrupts.
 
void nrfx_comp_stop (void)
 Function for stopping the COMP peripheral.
 
uint32_t nrfx_comp_sample (void)
 Function for copying the current state of the comparator result to the RESULT register.
 
NRFX_STATIC_INLINE uint32_t nrfx_comp_task_address_get (nrf_comp_task_t task)
 Function for getting the address of a 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.
 

Detailed Description

Comparator (COMP) peripheral driver.

Macro Definition Documentation

◆ NRFX_COMP_CONFIG_TH

#define NRFX_COMP_CONFIG_TH
Value:
{ \
.th_down = NRFX_COMP_VOLTAGE_THRESHOLD_TO_INT(0.5, 1.2), \
}
#define NRFX_COMP_VOLTAGE_THRESHOLD_TO_INT(vol, ref)
Macro for converting the threshold voltage to an integer value (needed by the COMP_TH register).
Definition nrfx_comp.h:60

COMP threshold default configuration.

◆ NRFX_COMP_DEFAULT_CONFIG

#define NRFX_COMP_DEFAULT_CONFIG ( _input)
Value:
{ \
.reference = NRF_COMP_REF_INT_1V2, \
.main_mode = NRF_COMP_MAIN_MODE_SE, \
.threshold = NRFX_COMP_CONFIG_TH, \
.speed_mode = NRF_COMP_SP_MODE_HIGH, \
NRFX_COND_CODE_1(NRF_COMP_HAS_ISOURCE, (.isource = NRF_COMP_ISOURCE_OFF,), ()) \
.input = (nrfx_analog_input_t)_input, \
.interrupt_priority = NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY \
}
#define NRF_COMP_HAS_ISOURCE
Symbol indicating whether COMP has ISOURCE register.
Definition nrf_comp.h:52
@ NRF_COMP_REF_INT_1V2
Definition nrf_comp.h:175
@ NRF_COMP_ISOURCE_OFF
Definition nrf_comp.h:259
@ NRF_COMP_MAIN_MODE_SE
Definition nrf_comp.h:226
@ NRF_COMP_HYST_NO_HYST
Definition nrf_comp.h:243
@ NRF_COMP_SP_MODE_HIGH
Definition nrf_comp.h:237
nrfx_analog_input_t
Generic analog input types.
Definition nrfx_analog_common.h:64
#define NRFX_COMP_CONFIG_TH
COMP threshold default configuration.
Definition nrfx_comp.h:87

COMP driver default configuration.

This configuration sets up COMP with the following options:

  • single-ended mode
  • reference voltage: internal 1.2 V
  • lower threshold: 0.5 V
  • upper threshold: 1.0 V
  • high speed mode
  • hysteresis disabled
  • current source disabled
Parameters
[in]_inputAnalog input.

◆ NRFX_COMP_VOLTAGE_THRESHOLD_TO_INT

#define NRFX_COMP_VOLTAGE_THRESHOLD_TO_INT ( vol,
ref )
Value:
(uint8_t)(((vol) > ((ref) / 64)) ? (NRFX_ROUNDED_DIV((vol) * 64,(ref)) - 1) : 0)
#define NRFX_ROUNDED_DIV(a, b)
Macro for performing rounded integer division (as opposed to truncating the result).
Definition nrfx_utils.h:483

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

Parameters
[in]volVoltage to be changed to COMP_TH register value. This value must not be smaller than reference voltage divided by 64.
[in]refReference voltage.

Typedef Documentation

◆ nrfx_comp_event_handler_t

typedef void(* nrfx_comp_event_handler_t) (nrf_comp_event_t event)

COMP event handler function type.

Parameters
[in]eventCOMP event.

Function Documentation

◆ nrfx_comp_event_address_get()

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
[in]eventCOMP event.
Returns
Address of the given COMP event.

◆ nrfx_comp_init()

int 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
[in]p_configPointer to the structure with the initial configuration.
[in]event_handlerEvent handler provided by the user. Must not be NULL.
Return values
0Initialization was successful.
-EALREADYThe driver is already initialized.
-EBUSYThe LPCOMP peripheral is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled.
-EINVALThe analog input pin or external reference is invalid.

◆ nrfx_comp_init_check()

bool nrfx_comp_init_check ( void )

Function for checking if the COMP driver is initialized.

Return values
trueDriver is already initialized.
falseDriver is not initialized.

◆ nrfx_comp_pin_select()

int nrfx_comp_pin_select ( nrfx_analog_input_t psel)

Function for setting the analog input.

Parameters
[in]pselGeneric analog pin selection.
Return values
0Setting the pin was successful.
-EINVALThe analog input pin is invalid.

◆ nrfx_comp_reconfigure()

int nrfx_comp_reconfigure ( nrfx_comp_config_t const * p_config)

Function for reconfiguring the COMP driver.

Parameters
[in]p_configPointer to the structure with the configuration.
Return values
0Reconfiguration was successful.
-EBUSYThe driver is running and cannot be reconfigured.
-EINPROGRESSThe driver is uninitialized.
-EINVALThe analog input pin or external reference is invalid.

◆ nrfx_comp_sample()

uint32_t nrfx_comp_sample ( void )

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

Return values
0The input voltage is below the threshold (VIN+ < VIN-).
1The input voltage is above the threshold (VIN+ > VIN-).

◆ nrfx_comp_start()

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.

Parameters
[in]comp_evt_en_maskMask of events to be enabled. This parameter is to be built as an OR of elements from nrf_comp_int_mask_t.
[in]comp_shorts_maskMask of shortcuts to be enabled. This parameter is to be built as an OR of elements from nrf_comp_short_mask_t.
See also
nrfx_comp_init

◆ nrfx_comp_stop()

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

◆ nrfx_comp_task_address_get()

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
[in]taskCOMP task.
Returns
Address of the given COMP task.

◆ nrfx_comp_uninit()

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