Hardware Abstraction Layer (HAL)
All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
Opamp (Operational Amplifier)

General Description

High level interface for interacting with the Operational Amplifier (Opamp).

Features

Each opamp can operate in one of two modes:

In both modes, the output is driven off chip via another pin.

Quickstart

Call cyhal_opamp_init to initialize an opamp instance by providing the opamp object (obj), non-inverting input pin (vin_p), inverting input pin (vin_m), and output pin (vout). If follower mode is desired, pass NC for vin_m.

Use cyhal_opamp_set_power to configure the opamp power.

Code Snippets

Note
Error checking is omitted for clarity

Snippet 1: Bare opamp initialization

The following snippet initializes a bare opamp. Note that any passive components (e.g. resistive feedback) must be implemented off-chip.

cy_rslt_t rslt;
cyhal_opamp_t opamp_obj;
/* Initialize opamp, using pin P9_0 for the non-inverting input, pin P9_1 for the inverting
* input, and P9_2 for the output
*/
rslt = cyhal_opamp_init(&opamp_obj, P9_0, P9_1, P9_2);
/* Power on the opamp */
/* Release opamp object after use */
cyhal_opamp_free(&opamp_obj);

Snippet 2: Opamp follower initialization

The following snippet initializes an opamp as a follower.

cy_rslt_t rslt;
cyhal_opamp_t opamp_obj;
/* Initialize opamp as follower, using pin P9_0 for the input and P9_2 for the output */
rslt = cyhal_opamp_init(&opamp_obj, P9_0, NC, P9_2);
/* Power on the opamp */
/* Release opamp object after use */
cyhal_opamp_free(&opamp_obj);

Snippet 3: Opamp powering-off and on

The following snippet demonstrates temporarily powering-off the opamp without freeing it.

/* This assumes that the opamp has already been initialized as shown in snippet 1 or 2 */
/* Power on the opamp */
/* When the opamp is needed again, power it back on */

API Reference

 Opamp HAL Results
 Opamp specific return codes.
 

Functions

cy_rslt_t cyhal_opamp_init (cyhal_opamp_t *obj, cyhal_gpio_t vin_p, cyhal_gpio_t vin_m, cyhal_gpio_t vout)
 Initialize the opamp peripheral. More...
 
void cyhal_opamp_free (cyhal_opamp_t *obj)
 Deinitialize the opamp peripheral and free associated resources. More...
 
cy_rslt_t cyhal_opamp_set_power (cyhal_opamp_t *obj, cyhal_power_level_t power)
 Changes the current operating power level of the opamp. More...
 

Function Documentation

◆ cyhal_opamp_init()

cy_rslt_t cyhal_opamp_init ( cyhal_opamp_t obj,
cyhal_gpio_t  vin_p,
cyhal_gpio_t  vin_m,
cyhal_gpio_t  vout 
)

Initialize the opamp peripheral.

If vin_m is NC, the opamp will be initialized in follower mode (unity gain).

The opamp will be initialized but not powered-on until cyhal_opamp_set_power is called.

Parameters
[out]objPointer to an opamp object. The caller must allocate the memory for this object but the init function will initialize its contents.
[in]vin_pNon-inverting input
[in]vin_mInverting input
[in]voutopamp output
Returns
The status of the init request

◆ cyhal_opamp_free()

void cyhal_opamp_free ( cyhal_opamp_t obj)

Deinitialize the opamp peripheral and free associated resources.

This will disconnect all inputs and outputs, including internal feedback.

Parameters
[in]objThe opamp object

◆ cyhal_opamp_set_power()

cy_rslt_t cyhal_opamp_set_power ( cyhal_opamp_t obj,
cyhal_power_level_t  power 
)

Changes the current operating power level of the opamp.

If the power level is set to CYHAL_POWER_LEVEL_OFF, the opamp will be powered-off but it will retain its configuration, so it is not necessary to reconfigure it when changing the power level from CYHAL_POWER_LEVEL_OFF to any other value.

Parameters
[in]objOpamp object
[in]powerThe power level to set
Returns
The status of the set power request