11.8.1.1.3 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.
    opamp_module_init();
    
  3. Initialize the OPAMP0 configuration struct with the module's default values.
    opamp0_get_config_defaults(&conf);
    
    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.
    opamp0_set_config(&conf);
    
  7. Enable OPAMP0.
    opamp_enable(OPAMP_0);
    
  8. Wait for the output ready.
    while(!opamp_is_ready(OPAMP_0));