Hardware Abstraction Layer (HAL)
COMP (Analog Comparator)

General Description

High level interface for interacting with an analog Comparator.

Features

The analog comparator measures one input voltage from the non-inverting pin against a second voltage provided on the inverting pin. The result of this comparison can be used in two ways:

These abilities can be used in any combination.

Quickstart

Call mtb_hal_comp_setup to initialize the HAL for a peripheral instance. The peripheral must] have already been initialized and configured using the PDL.

Use mtb_hal_comp_read to read the comparator state from firmware.

Code Snippets:

Note
Error checking is omitted for clarity

Snippet 1: Comparator read value

The following snippet reads the current comparator value into a variable

cy_rslt_t rslt;
mtb_hal_comp_t comp_obj;
// Setup the comparator
rslt = mtb_hal_comp_setup(&comp_obj, &comp_config_struct);
// Read the comparator value
bool comp_value = mtb_hal_comp_read(&comp_obj);
bool mtb_hal_comp_read(mtb_hal_comp_t *obj)
Reads the Comparator state.
cy_rslt_t mtb_hal_comp_setup(mtb_hal_comp_t *obj, const mtb_hal_comp_configurator_t *config)
Sets up a HAL instance to use the specified hardware resource.
Comparator object.
Definition: mtb_hal_hw_types_comp.h:84
uint32_t cy_rslt_t
Provides the result of an operation as a structured bitfield.
Definition: cy_result.h:457

API Reference

 Comparator HAL Results
 Comparator specific return codes.
 

Functions

cy_rslt_t mtb_hal_comp_setup (mtb_hal_comp_t *obj, const mtb_hal_comp_configurator_t *config)
 Sets up a HAL instance to use the specified hardware resource. More...
 
bool mtb_hal_comp_read (mtb_hal_comp_t *obj)
 Reads the Comparator state. More...
 
cy_rslt_t mtb_hal_comp_set_ref (mtb_hal_comp_t *obj, uint16_t ref_mv)
 Sets the reference voltage value. More...
 

Function Documentation

◆ mtb_hal_comp_setup()

cy_rslt_t mtb_hal_comp_setup ( mtb_hal_comp_t obj,
const mtb_hal_comp_configurator_t config 
)

Sets up a HAL instance to use the specified hardware resource.

This hardware resource must have already been configured via the PDL.

Parameters
[out]objThe HAL driver instance object. The caller must allocate the memory for this object, but the HAL will initialize its contents
[in]configThe configurator-generated HAL config structure for this peripheral instance
Returns
the status of the HAL setup

◆ mtb_hal_comp_read()

bool mtb_hal_comp_read ( mtb_hal_comp_t obj)

Reads the Comparator state.

Parameters
[in]objComparator object
Returns
The Comparator state. True if the non-inverting pin voltage is greater than the inverting pin voltage, false otherwise.

◆ mtb_hal_comp_set_ref()

cy_rslt_t mtb_hal_comp_set_ref ( mtb_hal_comp_t obj,
uint16_t  ref_mv 
)

Sets the reference voltage value.

Parameters
[in]objComparator object
[in]ref_mvReference voltage in millivolts
Returns
The status of the set reference request