configure_opamp2()
in an
empty Atmel Studio ASF Board Project for SAM L21 or within an existing SAM L21
project. Configure the OPAMP2 as a Non-Inverting PGA:
/* Configure OPAMP2 and I/O PORT */
void configure_opamp2(void)
{
/* Creates a new configuration structure for the OPAMP2. */
struct opamp2_config conf;
/* Initializes OPAMP module. */
opamp_module_init();
/* Settings and fill with the default settings. */
opamp2_get_config_defaults(&conf);
/* Set the the OPAMP2 in "Non-Inverted PGA" mode. */
conf.negative_input = OPAMP2_NEG_MUX_TAP2;
conf.positive_input = OPAMP2_POS_MUX_PIN2;
conf.r1_connection = OPAMP2_RES1_MUX_GND;
conf.config_common.potentiometer_selection = OPAMP_POT_MUX_12R_4R;
conf.config_common.r1_enable = true;
conf.config_common.r2_out = true;
conf.config_common.analog_out = true;
/* Set up OA2POS pin as input. */
struct system_pinmux_config opamp2_input_pin_conf;
system_pinmux_get_config_defaults(&opamp2_input_pin_conf);
opamp2_input_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
opamp2_input_pin_conf.mux_position = OPAMP_INPUT_MUX;
system_pinmux_pin_set_config(OPAMP_INPUT_PIN, &opamp2_input_pin_conf);
OPAMP_INPUT_MUX
and OPAMP_INPUT_PIN
is
defined in conf_example.h which must be included./* Initialize and enable the OPAMP2 with the user settings. */
opamp2_set_config(&conf);
opamp_enable(OPAMP_2);
/* Wait for the output ready. */
while(!opamp_is_ready(OPAMP_2));
configure_opamp2()
function should be like the
following:
/* Configure OPAMP2 and I/O PORT */
void configure_opamp2(void)
{
/* Creates a new configuration structure for the OPAMP2. */
struct opamp2_config conf;
/* Initializes OPAMP module. */
opamp_module_init();
/* Settings and fill with the default settings. */
opamp2_get_config_defaults(&conf);
/* Set the the OPAMP2 in "Non-Inverted PGA" mode. */
conf.negative_input = OPAMP2_NEG_MUX_TAP2;
conf.positive_input = OPAMP2_POS_MUX_PIN2;
conf.r1_connection = OPAMP2_RES1_MUX_GND;
conf.config_common.potentiometer_selection = OPAMP_POT_MUX_12R_4R;
conf.config_common.r1_enable = true;
conf.config_common.r2_out = true;
conf.config_common.analog_out = true;
/* Set up OA2POS pin as input. */
struct system_pinmux_config opamp2_input_pin_conf;
system_pinmux_get_config_defaults(&opamp2_input_pin_conf);
opamp2_input_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
opamp2_input_pin_conf.mux_position = OPAMP_INPUT_MUX;
system_pinmux_pin_set_config(OPAMP_INPUT_PIN, &opamp2_input_pin_conf);
/* Initialize and enable the OPAMP2 with the user settings. */
opamp2_set_config(&conf);
opamp_enable(OPAMP_2);
/* Wait for the output ready. */
while(!opamp_is_ready(OPAMP_2));
}