Synergy Software Package User's Manual

Driver for the Operational Amplifier (OPAMP). More...

Data Structures

struct  opamp_on_opamp_cfg_t
 
struct  opamp_instance_ctrl_t
 

Macros

#define OPAMP_CODE_VERSION_MAJOR   (2U)
 
#define OPAMP_ERROR_RETURN(a, err)   SSP_ERROR_RETURN((a), (err), &g_module_name[0], &g_opamp_version)
 

Enumerations

enum  opamp_trigger_t { OPAMP_TRIGGER_SOFTWARE_START_SOFTWARE_STOP = 0, OPAMP_TRIGGER_AGT_START_SOFTWARE_STOP = 1, OPAMP_TRIGGER_AGT_START_ADC_STOP = 3 }
 
enum  opamp_agt_link_t { OPAMP_AGT_LINK_AGT1_OPAMP_0_2_AGT0_OPAMP_1_3 = 0, OPAMP_AGT_LINK_AGT1_OPAMP_0_1_AGT0_OPAMP_2_3 = 1, OPAMP_AGT_LINK_AGT1_OPAMP_0_1_2_3 = 3 }
 
enum  opamp_mode_t { OPAMP_MODE_LOW_POWER = 0, OPAMP_MODE_MIDDLE_SPEED = 1, OPAMP_MODE_HIGH_SPEED = 3 }
 
enum  opamp_priv_trim_state_t {
  OPAMP_PRIV_TRIM_STATE_INVALID = -1, OPAMP_PRIV_TRIM_STATE_END = 0, OPAMP_PRIV_TRIM_STATE_BIT_0 = 0, OPAMP_PRIV_TRIM_STATE_BIT_1 = 1,
  OPAMP_PRIV_TRIM_STATE_BIT_2 = 2, OPAMP_PRIV_TRIM_STATE_BIT_3 = 3, OPAMP_PRIV_TRIM_STATE_BIT_4 = 4, OPAMP_PRIV_TRIM_STATE_BEGIN = 5
}
 

Functions

ssp_err_t R_OPAMP_Open (opamp_ctrl_t *const p_api_ctrl, opamp_cfg_t const *const p_cfg)
 Applies power to the OPAMP and initializes the hardware based on the user configuration. Implements opamp_api_t::open(). More...
 
ssp_err_t R_OPAMP_InfoGet (opamp_ctrl_t *const p_api_ctrl, opamp_info_t *const p_info)
 Provides the minimum stabilization wait time in microseconds. Implements opamp_api_t::infoGet(). More...
 
ssp_err_t R_OPAMP_Start (opamp_ctrl_t *const p_api_ctrl, uint32_t const channel_mask)
 If the OPAMP is configured for hardware triggers, enables hardware triggers. Otherwise, starts the op-amp. Implements opamp_api_t::start(). More...
 
ssp_err_t R_OPAMP_Stop (opamp_ctrl_t *const p_api_ctrl, uint32_t const channel_mask)
 Stops the op-amp. If the OPAMP is configured for hardware triggers, disables hardware triggers. Implements opamp_api_t::stop(). More...
 
ssp_err_t R_OPAMP_StatusGet (opamp_ctrl_t *const p_api_ctrl, opamp_status_t *const p_status)
 Provides the operating status for each op-amp in a bitmask. This bit is set when operation begins, before the stabilization wait time has elapsed. Implements opamp_api_t::statusGet(). More...
 
ssp_err_t R_OPAMP_Trim (opamp_ctrl_t *const p_api_ctrl, opamp_trim_cmd_t const cmd, opamp_trim_args_t const *const p_args)
 On MCUs that support trimming, the op-amp trim register is set to the factory default after open(). This function allows the application to trim the operational amplifier to a user setting, which overwrites the factory default factory trim values. More...
 
ssp_err_t R_OPAMP_Close (opamp_ctrl_t *const p_api_ctrl)
 Stops the op-amps. Implements opamp_api_t::close(). More...
 
ssp_err_t R_OPAMP_VersionGet (ssp_version_t *const p_version)
 

Variables

const opamp_api_t g_opamp_on_opamp
 

Detailed Description

Driver for the Operational Amplifier (OPAMP).

This module supports the OPAMP peripheral. It implements the following interfaces:

Macro Definition Documentation

◆ OPAMP_CODE_VERSION_MAJOR

#define OPAMP_CODE_VERSION_MAJOR   (2U)

Version of code that implements the API defined in this file

◆ OPAMP_ERROR_RETURN

#define OPAMP_ERROR_RETURN (   a,
  err 
)    SSP_ERROR_RETURN((a), (err), &g_module_name[0], &g_opamp_version)

Macro for error logger.

Enumeration Type Documentation

◆ opamp_agt_link_t

Which AGT timer starts the op-amp. Only applies to channels if OPAMP_TRIGGER_AGT_START_SOFTWARE_STOP or OPAMP_TRIGGER_AGT_START_ADC_STOP is selected for the channel. If OPAMP_TRIGGER_SOFTWARE_START_SOFTWARE_STOP is selected for a channel, then no AGT compare match event will start that op-amp channel.

Enumerator
OPAMP_AGT_LINK_AGT1_OPAMP_0_2_AGT0_OPAMP_1_3 

OPAMP channel 0 and 2 are started by AGT1 compare match. OPAMP channel 1 and 3 are started by AGT0 compare match.

OPAMP_AGT_LINK_AGT1_OPAMP_0_1_AGT0_OPAMP_2_3 

OPAMP channel 0 and 1 are started by AGT1 compare match. OPAMP channel 2 and 3 are started by AGT0 compare match.

OPAMP_AGT_LINK_AGT1_OPAMP_0_1_2_3 

All OPAMP channels are started by AGT1 compare match.

◆ opamp_mode_t

Op-amp mode.

Enumerator
OPAMP_MODE_LOW_POWER 

Low power mode.

OPAMP_MODE_MIDDLE_SPEED 

Middle speed mode (not supported on all MCUs)

OPAMP_MODE_HIGH_SPEED 

High speed mode.

◆ opamp_priv_trim_state_t

Op-amp trim state.

Enumerator
OPAMP_PRIV_TRIM_STATE_INVALID 

Trim state invalid.

OPAMP_PRIV_TRIM_STATE_END 

Trim state end.

OPAMP_PRIV_TRIM_STATE_BIT_0 

Trim state bit 0.

OPAMP_PRIV_TRIM_STATE_BIT_1 

Trim state bit 1.

OPAMP_PRIV_TRIM_STATE_BIT_2 

Trim state bit 2.

OPAMP_PRIV_TRIM_STATE_BIT_3 

Trim state bit 3.

OPAMP_PRIV_TRIM_STATE_BIT_4 

Trim state bit 4.

OPAMP_PRIV_TRIM_STATE_BEGIN 

Trim state begin.

◆ opamp_trigger_t

Start and stop trigger for the op-amp.

Enumerator
OPAMP_TRIGGER_SOFTWARE_START_SOFTWARE_STOP 

Start and stop with APIs.

OPAMP_TRIGGER_AGT_START_SOFTWARE_STOP 

Start by AGT compare match and stop with API.

OPAMP_TRIGGER_AGT_START_ADC_STOP 

Start by AGT compare match and stop after ADC conversion.

Function Documentation

◆ R_OPAMP_Close()

ssp_err_t R_OPAMP_Close ( opamp_ctrl_t *const  p_api_ctrl)

Stops the op-amps. Implements opamp_api_t::close().

Return values
SSP_SUCCESSInstance control block closed successfully.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.

Perform parameter checking

Set all OPAMP units and the reference current generator to be stopped.

Mark driver as closed

Enter the module-stop state.

Release the hardware lock

Return the error code

◆ R_OPAMP_InfoGet()

ssp_err_t R_OPAMP_InfoGet ( opamp_ctrl_t *const  p_api_ctrl,
opamp_info_t *const  p_info 
)

Provides the minimum stabilization wait time in microseconds. Implements opamp_api_t::infoGet().

Return values
SSP_SUCCESSInformation stored in p_info.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.

Perform parameter checking

◆ R_OPAMP_Open()

ssp_err_t R_OPAMP_Open ( opamp_ctrl_t *const  p_api_ctrl,
opamp_cfg_t const *const  p_cfg 
)

Applies power to the OPAMP and initializes the hardware based on the user configuration. Implements opamp_api_t::open().

The op-amp is not operational until the opamp_api_t::start() is called. If the op-amp is configured to start after AGT compare match, the op-amp is not operational until opamp_api_t::start() and the associated AGT compare match event occurs.

Some MCUs have switches that must be set before starting the op-amp. These switches must be set in the application code after opamp_api_t::open() and before opamp_api_t::start().

Return values
SSP_SUCCESSConfiguration successful.
SSP_ERR_ASSERTIONAn input pointer is NULL.
SSP_ERR_INVALID_ARGUMENTAn input argument is invalid.
SSP_ERR_IN_USEControl block is already opened.
Returns
See Common Error Codes or functions called by this function for other possible return codes. This function calls:

Verify the control block has not already been initialized.

Confirm the OPAMP exists on this MCU.

Lock the OPAMP

Initialize the hardware based on the configuration.

Stop operation of all op-amps.

Initialize trim registers to factory trim values.

◆ R_OPAMP_Start()

ssp_err_t R_OPAMP_Start ( opamp_ctrl_t *const  p_api_ctrl,
uint32_t const  channel_mask 
)

If the OPAMP is configured for hardware triggers, enables hardware triggers. Otherwise, starts the op-amp. Implements opamp_api_t::start().

Some MCUs have switches that must be set before starting the op-amp. These switches must be set in the application code after opamp_api_t::open() and before opamp_api_t::start().

Return values
SSP_SUCCESSOp-amp started or hardware triggers enabled successfully.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.
SSP_ERR_INVALID_ARGUMENTchannel_mask includes a channel that does not exist on this MCU.

Enable AGT start and ADC conversion end triggers or start the op-amp channel(s).

Return the error code

◆ R_OPAMP_StatusGet()

ssp_err_t R_OPAMP_StatusGet ( opamp_ctrl_t *const  p_api_ctrl,
opamp_status_t *const  p_status 
)

Provides the operating status for each op-amp in a bitmask. This bit is set when operation begins, before the stabilization wait time has elapsed. Implements opamp_api_t::statusGet().

Return values
SSP_SUCCESSOperating status of each op-amp provided in p_status.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.

Read the operating status of the op-amps.

◆ R_OPAMP_Stop()

ssp_err_t R_OPAMP_Stop ( opamp_ctrl_t *const  p_api_ctrl,
uint32_t const  channel_mask 
)

Stops the op-amp. If the OPAMP is configured for hardware triggers, disables hardware triggers. Implements opamp_api_t::stop().

Return values
SSP_SUCCESSOp-amp stopped or hardware triggers disabled successfully.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.
SSP_ERR_INVALID_ARGUMENTchannel_mask includes a channel that does not exist on this MCU.

Disable AGT start and ADC conversion end triggers and stop the op-amp channel(s).

Return the error code

◆ R_OPAMP_Trim()

ssp_err_t R_OPAMP_Trim ( opamp_ctrl_t *const  p_api_ctrl,
opamp_trim_cmd_t const  cmd,
opamp_trim_args_t const *const  p_args 
)

On MCUs that support trimming, the op-amp trim register is set to the factory default after open(). This function allows the application to trim the operational amplifier to a user setting, which overwrites the factory default factory trim values.

Not supported on all MCUs. See hardware manual for details. Not supported if configured for low power mode (OPAMP_MODE_LOW_POWER).

This function is not reentrant. Only one side of one op-amp can be trimmed at a time. Complete the procedure for one side of one channel before calling trim() with command OPAMP_TRIM_CMD_START again.

Implements opamp_api_t::trim().

The trim procedure works as follows:

  1. Call trim() for the Pch (+) side input with command OPAMP_TRIM_CMD_START.
  2. Connect a fixed voltage to the Pch (+) input.
  3. Connect the Nch (-) input to the op-amp output to create a voltage follower.
  4. Ensure the op-amp is operating and stabilized.
  5. Call trim() for the Pch (+) side input with command OPAMP_TRIM_CMD_START.
  6. Measure the fixed voltage connected to the Pch (+) input using the SAR ADC and save the value (referred to as A later in this procedure).
  7. Iterate over the following loop 5 times:
    1. Call trim() for the Pch (+) side input with command OPAMP_TRIM_CMD_NEXT_STEP.
    2. Measure the op-amp output using the SAR ADC (referred to as B in the next step).
    3. If A <= B, call trim() for the Pch (+) side input with command OPAMP_TRIM_CMD_CLEAR_BIT.
  8. Call trim() for the Nch (-) side input with command OPAMP_TRIM_CMD_START.
  9. Measure the fixed voltage connected to the Pch (+) input using the SAR ADC and save the value (referred to as A later in this procedure).
  10. Iterate over the following loop 5 times:
    1. Call trim() for the Nch (-) side input with command OPAMP_TRIM_CMD_NEXT_STEP.
    2. Measure the op-amp output using the SAR ADC (referred to as B in the next step).
    3. If A <= B, call trim() for the Nch (-) side input with command OPAMP_TRIM_CMD_CLEAR_BIT.
Return values
SSP_SUCCESSConversion result in p_data.
SSP_ERR_UNSUPPORTEDTrimming is not supported on this MCU.
SSP_ERR_INVALID_STATEThe command is not valid in the current state of the trim state machine.
SSP_ERR_INVALID_ARGUMENTThe requested channel is not operating or the trim procedure is not in progress for this channel/input combination.
SSP_ERR_INVALID_MODETrim is not allowed in low power mode.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.

Initialize the trim register to 0 during OPAMP_TRIM_CMD_START.

Set the next trim bit during OPAMP_TRIM_CMD_NEXT_STEP.

Clear the current trim bit during OPAMP_TRIM_CMD_CLEAR_BIT.

◆ R_OPAMP_VersionGet()

ssp_err_t R_OPAMP_VersionGet ( ssp_version_t *const  p_version)

Gets the API and code version. Implements opamp_api_t::versionGet().

Return values
SSP_SUCCESSVersion information available in p_version.
SSP_ERR_ASSERTIONThe parameter p_version is NULL.

Return the version number

Variable Documentation

◆ g_opamp_on_opamp

const opamp_api_t g_opamp_on_opamp
Initial value:
=
{
.open = R_OPAMP_Open,
.start = R_OPAMP_Start,
.stop = R_OPAMP_Stop,
.trim = R_OPAMP_Trim,
.infoGet = R_OPAMP_InfoGet,
.statusGet = R_OPAMP_StatusGet,
.close = R_OPAMP_Close,
.versionGet = R_OPAMP_VersionGet
}

Name of module used by error logger macro OPAMP Implementation of OPAMP interface.