PSOC E8XXGP Device Support Library
Loading...
Searching...
No Matches
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);
Comparator object.
Definition: mtb_hal_hw_types_comp.h:83
uint32_t cy_rslt_t
Provides the result of an operation as a structured bitfield.
Definition: cy_result.h:459

API Reference

 Comparator HAL Results
 Comparator specific return codes.
 

Typedefs

typedef void(* mtb_hal_comp_event_callback_t) (void *callback_arg, mtb_hal_comp_event_t event)
 Handler for Comparator events.
 

Enumerations

enum  mtb_hal_comp_event_t {
  MTB_HAL_COMP_EDGE_NONE = 0 ,
  MTB_HAL_COMP_RISING_EDGE = 1 ,
  MTB_HAL_COMP_FALLING_EDGE = 2 ,
  MTB_HAL_COMP_BOTH_EDGE = 3
}
 Comparator event types. More...
 

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.
 
bool mtb_hal_comp_read (mtb_hal_comp_t *obj)
 Reads the Comparator state.
 
cy_rslt_t mtb_hal_comp_set_ref (mtb_hal_comp_t *obj, uint16_t ref_mv)
 Sets the reference voltage value.
 
cy_rslt_t mtb_hal_comp_enable (mtb_hal_comp_t *obj, bool enable)
 Enable/disable the comparator.
 
cy_rslt_t mtb_hal_comp_slice_enable (mtb_hal_comp_t *obj, bool enable)
 Enable/disable the slope generator slice.
 
bool mtb_hal_comp_slice_read (mtb_hal_comp_t *obj)
 Read the output state of the slope generator slice.
 
cy_rslt_t mtb_hal_comp_slice_set_ref_count (mtb_hal_comp_t *obj, uint32_t count)
 Sets the reference count of the slope generator slice.
 
cy_rslt_t mtb_hal_comp_slice_set_ref_mv (mtb_hal_comp_t *obj, uint32_t ref_mv)
 Sets the reference voltage of the slope generator slice.
 
void mtb_hal_comp_register_callback (mtb_hal_comp_t *obj, mtb_hal_comp_event_callback_t callback, void *callback_arg)
 Register/clear a callback handler for Comp events.
 
void mtb_hal_comp_enable_event (mtb_hal_comp_t *obj, mtb_hal_comp_event_t event, bool enable)
 Enable or Disable the specified Comp event.
 
cy_rslt_t mtb_hal_comp_process_interrupt (mtb_hal_comp_t *obj)
 Process interrupts related related to a Comp instance.
 

Enumeration Type Documentation

◆ mtb_hal_comp_event_t

Comparator event types.

Enumerator
MTB_HAL_COMP_EDGE_NONE 

No trigger on either edge.

MTB_HAL_COMP_RISING_EDGE 

Rising edge on comparator output.

MTB_HAL_COMP_FALLING_EDGE 

Falling edge on comparator output.

MTB_HAL_COMP_BOTH_EDGE 

Falling edge on comparator output.

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

◆ mtb_hal_comp_enable()

cy_rslt_t mtb_hal_comp_enable ( mtb_hal_comp_t obj,
bool  enable 
)

Enable/disable the comparator.

Parameters
[in]objThe Comp object
[in]enableEnable/disable
Returns
The status of the enable request

◆ mtb_hal_comp_slice_enable()

cy_rslt_t mtb_hal_comp_slice_enable ( mtb_hal_comp_t obj,
bool  enable 
)

Enable/disable the slope generator slice.

Parameters
[in]objThe Comp object
[in]enableEnable/disable
Returns
The status of the enable request

◆ mtb_hal_comp_slice_read()

bool mtb_hal_comp_slice_read ( mtb_hal_comp_t obj)

Read the output state of the slope generator slice.

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

◆ mtb_hal_comp_slice_set_ref_count()

cy_rslt_t mtb_hal_comp_slice_set_ref_count ( mtb_hal_comp_t obj,
uint32_t  count 
)

Sets the reference count of the slope generator slice.

Parameters
[in]objThe Comp object
[in]countReference count
Returns
The status of the set reference request

◆ mtb_hal_comp_slice_set_ref_mv()

cy_rslt_t mtb_hal_comp_slice_set_ref_mv ( mtb_hal_comp_t obj,
uint32_t  ref_mv 
)

Sets the reference voltage of the slope generator slice.

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

◆ mtb_hal_comp_register_callback()

void mtb_hal_comp_register_callback ( mtb_hal_comp_t obj,
mtb_hal_comp_event_callback_t  callback,
void *  callback_arg 
)

Register/clear a callback handler for Comp events.

The referenced function will be called when one of the events enabled by by mtb_hal_comp_enable_event occurs.

Parameters
[in]objThe Comp object
[in]callbackThe callback handler which will be invoked when the event occurs
[in]callback_argGeneric argument that will be provided to the callback when called

◆ mtb_hal_comp_enable_event()

void mtb_hal_comp_enable_event ( mtb_hal_comp_t obj,
mtb_hal_comp_event_t  event,
bool  enable 
)

Enable or Disable the specified Comp event.

When an enabled event occurs, the function specified by mtb_hal_comp_register_callback will be called.

Parameters
[in]objThe Comp object
[in]eventThe Comp event
[in]enableTrue to turn on interrupts, False to turn off

◆ mtb_hal_comp_process_interrupt()

cy_rslt_t mtb_hal_comp_process_interrupt ( mtb_hal_comp_t obj)

Process interrupts related related to a Comp instance.

Parameters
objHAL object for which the interrupt should be processed
Returns
CY_RSLT_SUCCESS if the interrupt was processed successfully; otherwise an error