Microchip® Advanced Software Framework

Quick Start Guide for OPAMP - Basic

In this use case, the OPAMP0 is configured as "Non-Inverting PGA" mode, refer to the second mode of "Built-in Modes" in the device datasheet.

You can give a signal on OA0POS and watch the output on OA0OUT through an oscilloscope.

Setup

Prerequisites

There are no special setup requirements for this use case.

Code

Copy-paste the following setup code to your user application:

void configure_non_inverting_pga_opamp0(void)
{
struct opamp0_config conf;
/* Set the the OPAMP0 as "Non-Inverting PGA" mode. */
conf.negative_input = OPAMP0_NEG_MUX_TAP0;
conf.positive_input = OPAMP0_POS_MUX_PIN0;
conf.r1_connection = OPAMP0_RES1_MUX_GND;
conf.config_common.r1_enable = true;
conf.config_common.r2_out = true;
/* Set up OA0POS pin and OA0OUT pin. */
struct system_pinmux_config opamp0_pos_pin_conf;
system_pinmux_get_config_defaults(&opamp0_pos_pin_conf);
opamp0_pos_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
opamp0_pos_pin_conf.mux_position = MUX_PA06B_OPAMP_OAPOS0;
system_pinmux_pin_set_config(PIN_PA06B_OPAMP_OAPOS0, &opamp0_pos_pin_conf);
struct system_pinmux_config opamp0_out_pin_conf;
system_pinmux_get_config_defaults(&opamp0_out_pin_conf);
opamp0_out_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
opamp0_out_pin_conf.mux_position = MUX_PA07B_OPAMP_OAOUT0;
system_pinmux_pin_set_config(PIN_PA07B_OPAMP_OAOUT0, &opamp0_out_pin_conf);
/* Wait for the output ready. */
}

Add to user application initialization (typically the start of main()):

configure_non_inverting_pga_opamp0();

Workflow

  1. Create an OPAMP0 configuration struct, which can be filled out to adjust the configuration of OPAMP0.
    struct opamp0_config conf;
  2. Initialize the OPAMP module.
  3. Initialize the OPAMP0 configuration struct with the module's default values.
    Note
    This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  4. Adjust the configuration struct to set the OPAMP0 as "Non-Inverting PGA" mode.
    conf.negative_input = OPAMP0_NEG_MUX_TAP0;
    conf.positive_input = OPAMP0_POS_MUX_PIN0;
    conf.r1_connection = OPAMP0_RES1_MUX_GND;
    conf.config_common.r1_enable = true;
    conf.config_common.r2_out = true;
    Note
    The existing configuration struct may be re-used, as long as any values that have been altered from the default settings are taken into account by the user application.
  5. Set up OA0POS pin and OA0OUT pin.
    struct system_pinmux_config opamp0_pos_pin_conf;
    system_pinmux_get_config_defaults(&opamp0_pos_pin_conf);
    opamp0_pos_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
    opamp0_pos_pin_conf.mux_position = MUX_PA06B_OPAMP_OAPOS0;
    system_pinmux_pin_set_config(PIN_PA06B_OPAMP_OAPOS0, &opamp0_pos_pin_conf);
    struct system_pinmux_config opamp0_out_pin_conf;
    system_pinmux_get_config_defaults(&opamp0_out_pin_conf);
    opamp0_out_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
    opamp0_out_pin_conf.mux_position = MUX_PA07B_OPAMP_OAOUT0;
    system_pinmux_pin_set_config(PIN_PA07B_OPAMP_OAOUT0, &opamp0_out_pin_conf);
  6. Write OPAMP0 configuration to the hardware module.
  7. Enable OPAMP0.
  8. Wait for the output ready.

Use Case

Code

Copy-paste the following code to your user application:

while (true) {
/* Do nothing */
}