COMP HAL

nRF5 SDK v17.0.2

Hardware access layer (HAL) for managing the Comparator (COMP) peripheral. More...

Data Structures

struct nrf_comp_th_t
COMP THDOWN and THUP values that are used to calculate the threshold voltages VDOWN and VUP. More...
struct nrf_comp_ref_conf_t
COMP reference configuration. More...

Enumerations

enum nrf_comp_input_t {
NRF_COMP_INPUT_0 = COMP_PSEL_PSEL_AnalogInput0,
NRF_COMP_INPUT_1 = COMP_PSEL_PSEL_AnalogInput1,
NRF_COMP_INPUT_2 = COMP_PSEL_PSEL_AnalogInput2,
NRF_COMP_INPUT_3 = COMP_PSEL_PSEL_AnalogInput3,
NRF_COMP_INPUT_4 = COMP_PSEL_PSEL_AnalogInput4,
NRF_COMP_INPUT_5 = COMP_PSEL_PSEL_AnalogInput5,
NRF_COMP_INPUT_6 = COMP_PSEL_PSEL_AnalogInput6,
NRF_COMP_INPUT_7 = COMP_PSEL_PSEL_AnalogInput7,
NRF_COMP_VDD_DIV2 = COMP_PSEL_PSEL_VddDiv2,
NRF_COMP_VDDH_DIV5 = COMP_PSEL_PSEL_VddhDiv5
}
COMP analog pin selection. More...
enum nrf_comp_ref_t {
NRF_COMP_REF_Int1V2 = COMP_REFSEL_REFSEL_Int1V2,
NRF_COMP_REF_Int1V8 = COMP_REFSEL_REFSEL_Int1V8,
NRF_COMP_REF_Int2V4 = COMP_REFSEL_REFSEL_Int2V4,
NRF_COMP_REF_VDD = COMP_REFSEL_REFSEL_VDD,
NRF_COMP_REF_ARef = COMP_REFSEL_REFSEL_ARef
}
COMP reference selection. More...
enum nrf_comp_ext_ref_t {
NRF_COMP_EXT_REF_0 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference0,
NRF_COMP_EXT_REF_1 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference1,
NRF_COMP_EXT_REF_2 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference2,
NRF_COMP_EXT_REF_3 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference3,
NRF_COMP_EXT_REF_4 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference4,
NRF_COMP_EXT_REF_5 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference5,
NRF_COMP_EXT_REF_6 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference6,
NRF_COMP_EXT_REF_7 = COMP_EXTREFSEL_EXTREFSEL_AnalogReference7
}
COMP external analog reference selection. More...
enum nrf_comp_main_mode_t {
NRF_COMP_MAIN_MODE_SE = COMP_MODE_MAIN_SE,
NRF_COMP_MAIN_MODE_Diff = COMP_MODE_MAIN_Diff
}
COMP main operation mode. More...
enum nrf_comp_sp_mode_t {
NRF_COMP_SP_MODE_Low = COMP_MODE_SP_Low,
NRF_COMP_SP_MODE_Normal = COMP_MODE_SP_Normal,
NRF_COMP_SP_MODE_High = COMP_MODE_SP_High
}
COMP speed and power mode. More...
enum nrf_comp_hyst_t {
NRF_COMP_HYST_NoHyst = COMP_HYST_HYST_NoHyst,
NRF_COMP_HYST_50mV = COMP_HYST_HYST_Hyst50mV
}
COMP comparator hysteresis. More...
enum nrf_isource_t {
NRF_COMP_ISOURCE_Off = COMP_ISOURCE_ISOURCE_Off,
NRF_COMP_ISOURCE_Ien2uA5 = COMP_ISOURCE_ISOURCE_Ien2mA5,
NRF_COMP_ISOURCE_Ien5uA = COMP_ISOURCE_ISOURCE_Ien5mA,
NRF_COMP_ISOURCE_Ien10uA = COMP_ISOURCE_ISOURCE_Ien10mA
}
COMP current source selection on analog input. More...
enum nrf_comp_task_t {
NRF_COMP_TASK_START = offsetof(NRF_COMP_Type, TASKS_START),
NRF_COMP_TASK_STOP = offsetof(NRF_COMP_Type, TASKS_STOP),
NRF_COMP_TASK_SAMPLE = offsetof(NRF_COMP_Type, TASKS_SAMPLE)
}
COMP tasks. More...
enum nrf_comp_event_t {
NRF_COMP_EVENT_READY = offsetof(NRF_COMP_Type, EVENTS_READY),
NRF_COMP_EVENT_DOWN = offsetof(NRF_COMP_Type, EVENTS_DOWN),
NRF_COMP_EVENT_UP = offsetof(NRF_COMP_Type, EVENTS_UP),
NRF_COMP_EVENT_CROSS = offsetof(NRF_COMP_Type, EVENTS_CROSS)
}
COMP events. More...

Functions

__STATIC_INLINE void nrf_comp_enable (void)
Function for enabling the COMP peripheral.
__STATIC_INLINE void nrf_comp_disable (void)
Function for disabling the COMP peripheral.
__STATIC_INLINE bool nrf_comp_enable_check (void)
Function for checking if the COMP peripheral is enabled. More...
__STATIC_INLINE void nrf_comp_ref_set ( nrf_comp_ref_t reference)
Function for setting the reference source. More...
__STATIC_INLINE void nrf_comp_ext_ref_set ( nrf_comp_ext_ref_t ext_ref)
Function for setting the external analog reference source. More...
__STATIC_INLINE void nrf_comp_th_set ( nrf_comp_th_t threshold)
Function for setting threshold voltages. More...
__STATIC_INLINE void nrf_comp_main_mode_set ( nrf_comp_main_mode_t main_mode)
Function for setting the main mode. More...
__STATIC_INLINE void nrf_comp_speed_mode_set ( nrf_comp_sp_mode_t speed_mode)
Function for setting the speed mode. More...
__STATIC_INLINE void nrf_comp_hysteresis_set ( nrf_comp_hyst_t hyst)
Function for setting the hysteresis. More...
__STATIC_INLINE void nrf_comp_isource_set ( nrf_isource_t isource)
Function for setting the current source on the analog input. More...
__STATIC_INLINE void nrf_comp_input_select ( nrf_comp_input_t input)
Function for selecting the active input of the COMP. More...
__STATIC_INLINE uint32_t nrf_comp_result_get (void)
Function for getting the last COMP compare result. More...
__STATIC_INLINE void nrf_comp_int_enable (uint32_t mask)
Function for enabling interrupts from COMP. More...
__STATIC_INLINE void nrf_comp_int_disable (uint32_t mask)
Function for disabling interrupts from COMP. More...
__STATIC_INLINE bool nrf_comp_int_enable_check (uint32_t mask)
Function for getting the enabled interrupts of COMP. More...
__STATIC_INLINE uint32_t * nrf_comp_task_address_get ( nrf_comp_task_t task)
Function for getting the address of the specified COMP task register. More...
__STATIC_INLINE uint32_t * nrf_comp_event_address_get ( nrf_comp_event_t event)
Function for getting the address of the specified COMP event register. More...
__STATIC_INLINE void nrf_comp_shorts_enable (uint32_t mask)
Function for setting COMP shortcuts. More...
__STATIC_INLINE void nrf_comp_shorts_disable (uint32_t mask)
Function for clearing COMP shortcuts by mask. More...
__STATIC_INLINE void nrf_comp_task_trigger ( nrf_comp_task_t task)
Function for setting the specified COMP task. More...
__STATIC_INLINE void nrf_comp_event_clear ( nrf_comp_event_t event)
Function for clearing the specified COMP event. More...
__STATIC_INLINE bool nrf_comp_event_check ( nrf_comp_event_t event)
Function for retrieving the state of the UARTE event. More...

Detailed Description

Hardware access layer (HAL) for managing the Comparator (COMP) peripheral.

Enumeration Type Documentation

COMP events.

Enumerator
NRF_COMP_EVENT_READY

COMP is ready and output is valid.

NRF_COMP_EVENT_DOWN

Input voltage crossed the threshold going down.

NRF_COMP_EVENT_UP

Input voltage crossed the threshold going up.

NRF_COMP_EVENT_CROSS

Input voltage crossed the threshold in any direction.

COMP external analog reference selection.

Enumerator
NRF_COMP_EXT_REF_0

Use AIN0 as external analog reference.

NRF_COMP_EXT_REF_1

Use AIN1 as external analog reference.

NRF_COMP_EXT_REF_2

Use AIN2 as external analog reference.

NRF_COMP_EXT_REF_3

Use AIN3 as external analog reference.

NRF_COMP_EXT_REF_4

Use AIN4 as external analog reference.

NRF_COMP_EXT_REF_5

Use AIN5 as external analog reference.

NRF_COMP_EXT_REF_6

Use AIN6 as external analog reference.

NRF_COMP_EXT_REF_7

Use AIN7 as external analog reference.

COMP comparator hysteresis.

Enumerator
NRF_COMP_HYST_NoHyst

Comparator hysteresis disabled.

NRF_COMP_HYST_50mV

Comparator hysteresis enabled.

COMP analog pin selection.

Enumerator
NRF_COMP_INPUT_0

AIN0 selected as analog input.

NRF_COMP_INPUT_1

AIN1 selected as analog input.

NRF_COMP_INPUT_2

AIN2 selected as analog input.

NRF_COMP_INPUT_3

AIN3 selected as analog input.

NRF_COMP_INPUT_4

AIN4 selected as analog input.

NRF_COMP_INPUT_5

AIN5 selected as analog input.

NRF_COMP_INPUT_6

AIN6 selected as analog input.

NRF_COMP_INPUT_7

AIN7 selected as analog input.

NRF_COMP_VDD_DIV2

VDD/2 selected as analog input.

NRF_COMP_VDDH_DIV5

VDDH/5 selected as analog input.

COMP main operation mode.

Enumerator
NRF_COMP_MAIN_MODE_SE

Single-ended mode.

NRF_COMP_MAIN_MODE_Diff

Differential mode.

COMP reference selection.

Enumerator
NRF_COMP_REF_Int1V2

VREF = internal 1.2 V reference (VDD >= 1.7 V).

NRF_COMP_REF_Int1V8

VREF = internal 1.8 V reference (VDD >= VREF + 0.2 V).

NRF_COMP_REF_Int2V4

VREF = internal 2.4 V reference (VDD >= VREF + 0.2 V).

NRF_COMP_REF_VDD

VREF = VDD.

NRF_COMP_REF_ARef

VREF = AREF (VDD >= VREF >= AREFMIN).

COMP speed and power mode.

Enumerator
NRF_COMP_SP_MODE_Low

Low power mode.

NRF_COMP_SP_MODE_Normal

Normal mode.

NRF_COMP_SP_MODE_High

High-speed mode.

COMP tasks.

Enumerator
NRF_COMP_TASK_START

COMP start sampling task.

NRF_COMP_TASK_STOP

COMP stop sampling task.

NRF_COMP_TASK_SAMPLE

Sample comparator value.

COMP current source selection on analog input.

Enumerator
NRF_COMP_ISOURCE_Off

Current source disabled.

NRF_COMP_ISOURCE_Ien2uA5

Current source enabled (+/- 2.5 uA).

NRF_COMP_ISOURCE_Ien5uA

Current source enabled (+/- 5 uA).

NRF_COMP_ISOURCE_Ien10uA

Current source enabled (+/- 10 uA).

Function Documentation

__STATIC_INLINE bool nrf_comp_enable_check ( void )

Function for checking if the COMP peripheral is enabled.

Return values
true The COMP peripheral is enabled.
false The COMP peripheral is not enabled.
__STATIC_INLINE uint32_t* nrf_comp_event_address_get ( nrf_comp_event_t event )

Function for getting the address of the specified COMP event register.

Parameters
[in] event COMP event.
Returns
Address of the specified COMP event.
__STATIC_INLINE bool nrf_comp_event_check ( nrf_comp_event_t event )

Function for retrieving the state of the UARTE event.

Parameters
[in] event Event to be checked.
Return values
true The event has been generated.
false The event has not been generated.
__STATIC_INLINE void nrf_comp_event_clear ( nrf_comp_event_t event )

Function for clearing the specified COMP event.

Parameters
[in] event COMP event to be cleared.
__STATIC_INLINE void nrf_comp_ext_ref_set ( nrf_comp_ext_ref_t ext_ref )

Function for setting the external analog reference source.

Parameters
[in] ext_ref COMP external analog reference selection.
__STATIC_INLINE void nrf_comp_hysteresis_set ( nrf_comp_hyst_t hyst )

Function for setting the hysteresis.

Parameters
[in] hyst COMP comparator hysteresis.
__STATIC_INLINE void nrf_comp_input_select ( nrf_comp_input_t input )

Function for selecting the active input of the COMP.

Parameters
[in] input Input to be selected.
__STATIC_INLINE void nrf_comp_int_disable ( uint32_t mask )

Function for disabling interrupts from COMP.

Parameters
[in] mask Mask of interrupts to be disabled.
See Also
nrf_comp_int_enable_check
__STATIC_INLINE void nrf_comp_int_enable ( uint32_t mask )

Function for enabling interrupts from COMP.

Parameters
[in] mask Mask of interrupts to be enabled.
See Also
nrf_comp_int_enable_check
__STATIC_INLINE bool nrf_comp_int_enable_check ( uint32_t mask )

Function for getting the enabled interrupts of COMP.

Parameters
[in] mask Mask of interrupts to be checked.
Return values
true At least one interrupt from the specified mask is enabled.
false No interrupt provided by the specified mask are enabled.
__STATIC_INLINE void nrf_comp_isource_set ( nrf_isource_t isource )

Function for setting the current source on the analog input.

Parameters
[in] isource COMP current source selection on analog input.
__STATIC_INLINE void nrf_comp_main_mode_set ( nrf_comp_main_mode_t main_mode )

Function for setting the main mode.

Parameters
[in] main_mode COMP main operation mode.
__STATIC_INLINE void nrf_comp_ref_set ( nrf_comp_ref_t reference )

Function for setting the reference source.

Parameters
[in] reference COMP reference selection.
__STATIC_INLINE uint32_t nrf_comp_result_get ( void )

Function for getting the last COMP compare result.

Note
If VIN+ == VIN-, the return value depends on the previous result.
Returns
The last compare result. If 0, then VIN+ < VIN-. If 1, then VIN+ > VIN-.
__STATIC_INLINE void nrf_comp_shorts_disable ( uint32_t mask )

Function for clearing COMP shortcuts by mask.

Parameters
[in] mask Mask of shortcuts.
__STATIC_INLINE void nrf_comp_shorts_enable ( uint32_t mask )

Function for setting COMP shortcuts.

Parameters
[in] mask Mask of shortcuts.
__STATIC_INLINE void nrf_comp_speed_mode_set ( nrf_comp_sp_mode_t speed_mode )

Function for setting the speed mode.

Parameters
[in] speed_mode COMP speed and power mode.
__STATIC_INLINE uint32_t* nrf_comp_task_address_get ( nrf_comp_task_t task )

Function for getting the address of the specified COMP task register.

Parameters
[in] task COMP task.
Returns
Address of the specified COMP task.
__STATIC_INLINE void nrf_comp_task_trigger ( nrf_comp_task_t task )

Function for setting the specified COMP task.

Parameters
[in] task Task to be activated.
__STATIC_INLINE void nrf_comp_th_set ( nrf_comp_th_t threshold )

Function for setting threshold voltages.

Parameters
[in] threshold COMP VDOWN and VUP thresholds.