Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM Operational Amplifier Controller (OPAMP) Driver

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's Operational Amplifier Controller functionality.

The following peripheral is used by this module:

The following devices can use this module:

The outline of this documentation is as follows:

Prerequisites

There are no prerequisites for this module.

Module Overview

The OPAMP is an individually configurable low power, general purpose operational amplifier offering a high degree of flexibility and rail-to-rail inputs.

Each operational amplifier can be configured in standalone operational amplifier and operational amplifier with built-in feedback. All OPAMPs can be cascaded to support circuits such as differential amplifiers.

Note
For more detail configuration reference, refer to the "Built-in Modes" section in the device datasheet.

Each OPAMP has one positive and one negative input which can be flexible chosen from analog input pins including the output of another OPAMP, internal inputs such as the DAC or the resistor ladder, and the ground.

Each OPAMP output can be selected as input for AC or ADC, also available on I/O pins.

Four modes are available to select the trade-off between speed and power consumption to best fit the application requirements and optimize the power consumption.

Special Considerations

There are no special considerations for this module.

Extra Information

For extra information, see Extra Information for OPAMP Driver. This includes:

Examples

For a list of examples related to this driver, see Examples for OPAMP Driver.

API Overview

Data Structures

struct  opamp0_config
 OPAMP 0 configuration structure. More...
 
struct  opamp1_config
 OPAMP 1 configuration structure. More...
 
struct  opamp2_config
 OPAMP 2 configuration structure. More...
 
struct  opamp_config_common
 OPAMP 0 to 2 common configuration structure. More...
 

Enumerations

enum  opamp0_neg_mux {
  OPAMP0_NEG_MUX_PIN0 = OPAMP_OPAMPCTRL_MUXNEG(0),
  OPAMP0_NEG_MUX_TAP0 = OPAMP_OPAMPCTRL_MUXNEG(1),
  OPAMP0_NEG_MUX_OUT0 = OPAMP_OPAMPCTRL_MUXNEG(2),
  OPAMP0_NEG_MUX_DAC = OPAMP_OPAMPCTRL_MUXNEG(3)
}
 Negative input MUX selection configuration enum. More...
 
enum  opamp0_pos_mux {
  OPAMP0_POS_MUX_PIN0 = OPAMP_OPAMPCTRL_MUXPOS(0),
  OPAMP0_POS_MUX_TAP0 = OPAMP_OPAMPCTRL_MUXPOS(1),
  OPAMP0_POS_MUX_DAC = OPAMP_OPAMPCTRL_MUXPOS(2),
  OPAMP0_POS_MUX_GND = OPAMP_OPAMPCTRL_MUXPOS(3)
}
 Positive input MUX selection configuration enum. More...
 
enum  opamp0_res1_mux {
  OPAMP0_RES1_MUX_POS_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(0),
  OPAMP0_RES1_MUX_NEG_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(1),
  OPAMP0_RES1_MUX_DAC = OPAMP_OPAMPCTRL_RES1MUX(2),
  OPAMP0_RES1_MUX_GND = OPAMP_OPAMPCTRL_RES1MUX(3)
}
 Resistor 1 MUX selection configuration enum. More...
 
enum  opamp1_neg_mux {
  OPAMP1_NEG_MUX_PIN1 = OPAMP_OPAMPCTRL_MUXNEG(0),
  OPAMP1_NEG_MUX_TAP1 = OPAMP_OPAMPCTRL_MUXNEG(1),
  OPAMP1_NEG_MUX_OUT1 = OPAMP_OPAMPCTRL_MUXNEG(2),
  OPAMP1_NEG_MUX_DAC = OPAMP_OPAMPCTRL_MUXNEG(3)
}
 Negative input MUX selection configuration enum. More...
 
enum  opamp1_pos_mux {
  OPAMP1_POS_MUX_PIN1 = OPAMP_OPAMPCTRL_MUXPOS(0),
  OPAMP1_POS_MUX_TAP1 = OPAMP_OPAMPCTRL_MUXPOS(1),
  OPAMP1_POS_MUX_OUT0 = OPAMP_OPAMPCTRL_MUXPOS(2),
  OPAMP1_POS_MUX_GND = OPAMP_OPAMPCTRL_MUXPOS(3)
}
 Positive input MUX selection configuration enum. More...
 
enum  opamp1_res1_mux {
  OPAMP1_RES1_MUX_POS_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(0),
  OPAMP1_RES1_MUX_NEG_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(1),
  OPAMP1_RES1_MUX_OUT0 = OPAMP_OPAMPCTRL_RES1MUX(2),
  OPAMP1_RES1_MUX_GND = OPAMP_OPAMPCTRL_RES1MUX(3)
}
 Resistor 1 MUX selection configuration enum. More...
 
enum  opamp2_neg_mux {
  OPAMP2_NEG_MUX_PIN2 = OPAMP_OPAMPCTRL_MUXNEG(0),
  OPAMP2_NEG_MUX_TAP2 = OPAMP_OPAMPCTRL_MUXNEG(1),
  OPAMP2_NEG_MUX_OUT2 = OPAMP_OPAMPCTRL_MUXNEG(2),
  OPAMP2_NEG_MUX_PIN0 = OPAMP_OPAMPCTRL_MUXNEG(3),
  OPAMP2_NEG_MUX_PIN1 = OPAMP_OPAMPCTRL_MUXNEG(4),
  OPAMP2_NEG_MUX_DAC = OPAMP_OPAMPCTRL_MUXNEG(5)
}
 Negative input MUX selection configuration enum. More...
 
enum  opamp2_pos_mux {
  OPAMP2_POS_MUX_PIN2 = OPAMP_OPAMPCTRL_MUXPOS(0),
  OPAMP2_POS_MUX_TAP2 = OPAMP_OPAMPCTRL_MUXPOS(1),
  OPAMP2_POS_MUX_OUT1 = OPAMP_OPAMPCTRL_MUXPOS(2),
  OPAMP2_POS_MUX_GND = OPAMP_OPAMPCTRL_MUXPOS(3),
  OPAMP2_POS_MUX_PIN0 = OPAMP_OPAMPCTRL_MUXPOS(4),
  OPAMP2_POS_MUX_PIN1 = OPAMP_OPAMPCTRL_MUXPOS(5),
  OPAMP2_POS_MUX_TAP0 = OPAMP_OPAMPCTRL_MUXPOS(6)
}
 Positive input MUX selection configuration enum. More...
 
enum  opamp2_res1_mux {
  OPAMP2_RES1_MUX_POS_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(0),
  OPAMP2_RES1_MUX_NEG_PIN0 = OPAMP_OPAMPCTRL_RES1MUX(1),
  OPAMP2_RES1_MUX_OUT1 = OPAMP_OPAMPCTRL_RES1MUX(2),
  OPAMP2_RES1_MUX_GND = OPAMP_OPAMPCTRL_RES1MUX(3)
}
 Resistor 1 MUX selection configuration enum. More...
 
enum  opamp_bias_selection {
  OPAMP_BIAS_MODE_0 = OPAMP_OPAMPCTRL_BIAS(0),
  OPAMP_BIAS_MODE_1 = OPAMP_OPAMPCTRL_BIAS(1),
  OPAMP_BIAS_MODE_2 = OPAMP_OPAMPCTRL_BIAS(2),
  OPAMP_BIAS_MODE_3 = OPAMP_OPAMPCTRL_BIAS(3)
}
 Bias mode selection MUX configuration enum. More...
 
enum  opamp_id {
  OPAMP_0 = 0,
  OPAMP_1 = 1,
  OPAMP_2 = 2,
  OPAMP_NUM
}
 OPAMP ID number enum. More...
 
enum  opamp_pot_mux {
  OPAMP_POT_MUX_14R_2R = OPAMP_OPAMPCTRL_POTMUX(0),
  OPAMP_POT_MUX_12R_4R = OPAMP_OPAMPCTRL_POTMUX(1),
  OPAMP_POT_MUX_8R_8R = OPAMP_OPAMPCTRL_POTMUX(2),
  OPAMP_POT_MUX_6R_10R = OPAMP_OPAMPCTRL_POTMUX(3),
  OPAMP_POT_MUX_4R_12R = OPAMP_OPAMPCTRL_POTMUX(4),
  OPAMP_POT_MUX_3R_13R = OPAMP_OPAMPCTRL_POTMUX(5),
  OPAMP_POT_MUX_2R_14R = OPAMP_OPAMPCTRL_POTMUX(6),
  OPAMP_POT_MUX_R_15R = OPAMP_OPAMPCTRL_POTMUX(7)
}
 Potentiometer selection MUX configuration enum. More...
 

Functions

void opamp0_get_config_defaults (struct opamp0_config *const config)
 Initializes all members of OPAMP0 configuration structure to safe defaults. More...
 
void opamp0_set_config (struct opamp0_config *const config)
 Writes OPAMP0 configuration to the hardware module. More...
 
void opamp1_get_config_defaults (struct opamp1_config *const config)
 Initializes all members of OPAMP1 configuration structure to safe defaults. More...
 
void opamp1_set_config (struct opamp1_config *const config)
 Writes OPAMP1 configuration to the hardware module. More...
 
void opamp2_get_config_defaults (struct opamp2_config *const config)
 Initializes all members of OPAMP2 configuration structure to safe defaults. More...
 
void opamp2_set_config (struct opamp2_config *const config)
 Writes OPAMP2 configuration to the hardware module. More...
 
void opamp_disable (const enum opamp_id number)
 Disables an OPAMP that was previously enabled. More...
 
void opamp_enable (const enum opamp_id number)
 Enables an OPAMP that was previously configured. More...
 
bool opamp_is_ready (const enum opamp_id number)
 Checks an OPAMP output ready status. More...
 
static void opamp_module_disable (void)
 Disables OPAMP module. More...
 
static void opamp_module_enable (void)
 Enables OPAMP module. More...
 
void opamp_module_init (void)
 Initializes OPAMP module. More...
 
static void opamp_module_reset (void)
 Resets OPAMP module. More...
 
static void opamp_voltage_doubler_disable (void)
 Disables OPAMP voltage doubler. More...
 
static void opamp_voltage_doubler_enable (void)
 Enables OPAMP voltage doubler. More...
 

Negative input MUX selection configuration enum.

Enum for the negative input of OPAMP0.

Enumerator
OPAMP0_NEG_MUX_PIN0 

Negative I/O pin 0.

OPAMP0_NEG_MUX_TAP0 

Resistor ladder 0 taps.

OPAMP0_NEG_MUX_OUT0 

OPAMP output.

OPAMP0_NEG_MUX_DAC 

DAC output.

Positive input MUX selection configuration enum.

Enum for the positive input of OPAMP0.

Enumerator
OPAMP0_POS_MUX_PIN0 

Positive I/O pin 0.

OPAMP0_POS_MUX_TAP0 

Resistor ladder 0 taps.

OPAMP0_POS_MUX_DAC 

DAC output.

OPAMP0_POS_MUX_GND 

Ground.

Resistor 1 MUX selection configuration enum.

Enum for the Resistor 1 of OPAMP0.

Enumerator
OPAMP0_RES1_MUX_POS_PIN0 

Positive input of OPAMP0.

OPAMP0_RES1_MUX_NEG_PIN0 

Negative input of OPAMP0.

OPAMP0_RES1_MUX_DAC 

DAC output.

OPAMP0_RES1_MUX_GND 

Ground.

Negative input MUX selection configuration enum.

Enum for the negative input of OPAMP1.

Enumerator
OPAMP1_NEG_MUX_PIN1 

Negative I/O pin 1.

OPAMP1_NEG_MUX_TAP1 

Resistor ladder 1 taps.

OPAMP1_NEG_MUX_OUT1 

OPAMP output.

OPAMP1_NEG_MUX_DAC 

DAC output.

Positive input MUX selection configuration enum.

Enum for the positive input of OPAMP1.

Enumerator
OPAMP1_POS_MUX_PIN1 

Positive I/O pin 1.

OPAMP1_POS_MUX_TAP1 

Resistor ladder 1 taps.

OPAMP1_POS_MUX_OUT0 

OPAMP0 output.

OPAMP1_POS_MUX_GND 

Ground.

Resistor 1 MUX selection configuration enum.

Enum for the Resistor 1 of OPAMP1.

Enumerator
OPAMP1_RES1_MUX_POS_PIN0 

Positive input of OPAMP1.

OPAMP1_RES1_MUX_NEG_PIN0 

Negative input of OPAMP1.

OPAMP1_RES1_MUX_OUT0 

OPAMP0 output.

OPAMP1_RES1_MUX_GND 

Ground.

Negative input MUX selection configuration enum.

Enum for the negative input of OPAMP2.

Enumerator
OPAMP2_NEG_MUX_PIN2 

Negative I/O pin 2.

OPAMP2_NEG_MUX_TAP2 

Resistor ladder 2 taps.

OPAMP2_NEG_MUX_OUT2 

OPAMP output.

OPAMP2_NEG_MUX_PIN0 

Negative I/O pin 0.

OPAMP2_NEG_MUX_PIN1 

Negative I/O pin 1.

OPAMP2_NEG_MUX_DAC 

DAC output.

Positive input MUX selection configuration enum.

Enum for the positive input of OPAMP2.

Enumerator
OPAMP2_POS_MUX_PIN2 

Positive I/O pin 2.

OPAMP2_POS_MUX_TAP2 

Resistor ladder 2 taps.

OPAMP2_POS_MUX_OUT1 

OPAMP1 output.

OPAMP2_POS_MUX_GND 

Ground.

OPAMP2_POS_MUX_PIN0 

Positive I/O pin 0.

OPAMP2_POS_MUX_PIN1 

Positive I/O pin 1.

OPAMP2_POS_MUX_TAP0 

Resistor ladder 0 taps.

Resistor 1 MUX selection configuration enum.

Enum for the Resistor 1 of OPAMP2.

Enumerator
OPAMP2_RES1_MUX_POS_PIN0 

Positive input of OPAMP2.

OPAMP2_RES1_MUX_NEG_PIN0 

Negative input of OPAMP2.

OPAMP2_RES1_MUX_OUT1 

OPAMP1 output.

OPAMP2_RES1_MUX_GND 

Ground.

Bias mode selection MUX configuration enum.

Enum for the Bias mode selection of OPAMP 0 to 2.

Enumerator
OPAMP_BIAS_MODE_0 

Minimum current consumption but the slowest mode.

OPAMP_BIAS_MODE_1 

Low current consumption, slow speed.

OPAMP_BIAS_MODE_2 

High current consumption, fast speed.

OPAMP_BIAS_MODE_3 

Maximum current consumption but the fastest mode.

enum opamp_id

OPAMP ID number enum.

Enumerator
OPAMP_0 

OPAMP 0.

OPAMP_1 

OPAMP 1.

OPAMP_2 

OPAMP 2.

OPAMP_NUM 

OPAMP number.

Potentiometer selection MUX configuration enum.

Enum for the potentiometer selection of OPAMP 0 to 2.

Enumerator
OPAMP_POT_MUX_14R_2R 

Gain = R2/R1 = 1/7.

OPAMP_POT_MUX_12R_4R 

Gain = R2/R1 = 1/3.

OPAMP_POT_MUX_8R_8R 

Gain = R2/R1 = 1.

OPAMP_POT_MUX_6R_10R 

Gain = R2/R1 = 1 + 2/3.

OPAMP_POT_MUX_4R_12R 

Gain = R2/R1 = 3.

OPAMP_POT_MUX_3R_13R 

Gain = R2/R1 = 4 + 1/3.

OPAMP_POT_MUX_2R_14R 

Gain = R2/R1 = 7.

OPAMP_POT_MUX_R_15R 

Gain = R2/R1 = 15.

void opamp0_get_config_defaults ( struct opamp0_config *const  config)

Initializes all members of OPAMP0 configuration structure to safe defaults.

Initializes all members of OPAMP0 configuration structure to safe defaults. This function should be called on all new instances of these configuration structures before being modified by the user application.

The default configuration is setting OPAMP0 as "Voltage Follower", refer to the first mode of "Built-in Modes" in the device datasheet.

Parameters
[out]configOPAMP0 configuration structure to initialize to default values

References _opamp_get_config_common_defaults(), Assert, opamp0_config::config_common, opamp0_config::negative_input, OPAMP0_NEG_MUX_OUT0, OPAMP0_POS_MUX_PIN0, OPAMP0_RES1_MUX_GND, opamp0_config::positive_input, and opamp0_config::r1_connection.

void opamp0_set_config ( struct opamp0_config *const  config)
void opamp1_get_config_defaults ( struct opamp1_config *const  config)

Initializes all members of OPAMP1 configuration structure to safe defaults.

Initializes all members of OPAMP1 configuration structure to safe defaults. This function should be called on all new instances of these configuration structures before being modified by the user application.

The default configuration is setting OPAMP1 as "Voltage Follower", refer to the first mode of "Built-in Modes" in the device datasheet.

Parameters
[out]configOPAMP1 configuration structure to initialize to default values

References _opamp_get_config_common_defaults(), Assert, opamp1_config::config_common, opamp1_config::negative_input, OPAMP1_NEG_MUX_OUT1, OPAMP1_POS_MUX_PIN1, OPAMP1_RES1_MUX_GND, opamp1_config::positive_input, and opamp1_config::r1_connection.

void opamp1_set_config ( struct opamp1_config *const  config)
void opamp2_get_config_defaults ( struct opamp2_config *const  config)

Initializes all members of OPAMP2 configuration structure to safe defaults.

Initializes all members of OPAMP2 configuration structure to safe defaults. This function should be called on all new instances of these configuration structures before being modified by the user application.

The default configuration is setting OPAMP2 as "Voltage Follower", refer to the first mode of "Built-in Modes" in the device datasheet.

Parameters
[out]configOPAMP2 configuration structure to initialize to default values

References _opamp_get_config_common_defaults(), Assert, opamp2_config::config_common, opamp2_config::negative_input, OPAMP2_NEG_MUX_OUT2, OPAMP2_POS_MUX_PIN2, OPAMP2_RES1_MUX_GND, opamp2_config::positive_input, and opamp2_config::r1_connection.

void opamp2_set_config ( struct opamp2_config *const  config)
void opamp_disable ( const enum opamp_id  number)

Disables an OPAMP that was previously enabled.

Disables an OPAMP that was previously enabled via a call to opamp_enable().

Parameters
[in]numberOPAMP number to disable

References Assert, OPAMP_0, OPAMP_1, and OPAMP_2.

void opamp_enable ( const enum opamp_id  number)

Enables an OPAMP that was previously configured.

Enables an OPAMP that was previously configured via a call to the set configuration function.

Parameters
[in]numberOPAMP number to enable

References Assert, OPAMP_0, OPAMP_1, and OPAMP_2.

bool opamp_is_ready ( const enum opamp_id  number)

Checks an OPAMP output ready status.

Checks if an OPAMP output is ready.

Parameters
[in]numberOPAMP number to check
Returns
Ready status of the select OPAMP.
Return values
falseIf the select OPAMP output is not ready
tureIf the select OPAMP output is ready

References Assert, OPAMP_0, OPAMP_1, and OPAMP_2.

static void opamp_module_disable ( void  )
inlinestatic

Disables OPAMP module.

Disables the peripheral.

static void opamp_module_enable ( void  )
inlinestatic

Enables OPAMP module.

Enable the peripheral. Each OPAMP must also be enabled individually by the Enable bit in the corresponding OPAMP Control register.

Referenced by opamp_module_init().

void opamp_module_init ( void  )

Initializes OPAMP module.

Resets all registers in the MODULE to their initial state, and then enable the module.

References opamp_module_enable(), opamp_module_reset(), system_apb_clock_set_mask(), SYSTEM_CLOCK_APB_APBD, system_clock_source_osculp32k_get_config_defaults(), and system_clock_source_osculp32k_set_config().

static void opamp_module_reset ( void  )
inlinestatic

Resets OPAMP module.

Resets all registers in the MODULE to their initial state, and the OPAMP will be disabled.

Referenced by opamp_module_init().

static void opamp_voltage_doubler_disable ( void  )
inlinestatic

Disables OPAMP voltage doubler.

The analog input MUXes have high resistance, but consume less power at lower voltages (e.g., the voltage doubler is disabled).

static void opamp_voltage_doubler_enable ( void  )
inlinestatic

Enables OPAMP voltage doubler.

The analog input MUXes have low resistance, but consume more power at lower voltages (e.g., driven by the voltage doubler).

References system_clock_source_osculp32k_get_config_defaults(), and system_clock_source_osculp32k_set_config().