Walkthrough PIC18F56Q71 MPLAB® Code Configurator Melody Operational Amplifier (Op Amp) Driver

Last modified by Microchip on 2025/05/13 12:09

Objective

This lesson will cover various aspects of the PIC18F56Q71 MPLAB® Code Configurator (MCC) Melody driver for the operational amplifier (op amp) peripheral, including how to:

  • Create an MPLAB X Integrated Development Environment (IDE) project for a PIC18F56Q71 microcontroller (MCU) from scratch
  • Use MCC Melody to add the op amp peripheral driver to the project
  • Review various op amp peripheral settings
  • Demonstrate how to access the peripheral Application Programming Interface (API) and guide

Overview

The PIC18F56Q71 MCU, equipped with integrated op amps, offers a versatile and efficient solution for analog signal processing tasks. These op amps provide high performance with low power consumption, making them ideal for applications requiring precise amplification and filtering. The MCU's advanced features, such as programmable gain and flexible routing options, enhance design flexibility and reduce the need for external components, thereby simplifying circuit design and reducing overall system cost. Additionally, configuring the op amp peripheral is streamlined through MCC Melody, Microchip Technology's intuitive graphical configuration tool. MCC Melody allows developers to easily set up and customize the op amp settings through a user-friendly interface, significantly reducing development time and minimizing the risk of configuration errors. This combination of robust hardware and efficient software tools ensures that engineers can quickly and effectively implement sophisticated analog solutions in their projects.

Note: This project has been verified to work with the following versions of software tools:

Because we regularly update our tools, occasionally you may discover an issue while using the newer versions. If you suspect that to be the case, we recommend that you double-check and use the same versions that the project was tested with.

Walkthrough

Let’s build a new MPLAB X IDE project for the PIC18F56Q71 and highlight various options for the MCC Melody op amp driver.

To begin, open MPLAB X IDE.  Click the New Project Button in the top left corner of the menu.

New project icon

Back to Top


 Select Application Project and click Next.

Application Project > Next

Back to Top


Select your device. This demonstration is using a PIC18F56Q71 device and the corresponding simulator tool.

Device selection

Back to Top


 Next, select a compiler.

Select compiler

Back to Top


Name your project and assign its location. Then, click Finish.

Project name and location > Finish

Back to Top


 After the project is created click the blue MCC shield at the top.

MCC logo

Back to Top


The MCC interface contains several areas, including:

  • Application Builder: Top center window
  • Pin Grid View: Bottom center
  • Resource Management: Tab near the top right-hand side, which shows the following panes:
    • Project Resources: Pane directly under Resource Management that shows the resources in your project
    • Device Resources: Bottom pane of Resource Management that contains the resources that can be added to a project

Note: When a peripheral or driver is added to a project, it moves from Device Resources to Project Resources. 

MCC interface

Back to Top


Since the PIC18F56Q71 Curiosity Nano’s internal oscillator is being used, open Configuration Bits under Project Resources. Make the following selections:

  • External Oscillator Selection: Oscillator not enabled
  • Reset Oscillator Selection:  The oscillator for your project (This demonstration uses the 64 MHz HFINTOSC.)

 External Oscillator Selection and Reset Oscillator Selection

Back to Top


Under Device Resources, scroll down to OPAMP and add OPA1.

Device Resources > OPAMP > OPA1

Back to Top


A window will open on the right for the op amp peripheral. At the top of the window is the Toolbar dropdown.  Under the Toolbar dropdown are the following tabs:

  • Easy View: Peripheral configuration
  • Register Initializations: See the specific values being written to the peripheral registers

OPA1 window

Back to Top


On the left side of every selection under Easy View, there blue circle with a white question inside. Clicking on the question mark will bring up the datasheet entry for each setting.

blue question mark

arrow

Datasheet entry example

Back to Top


 Below is a brief explanation of each dropdown section and its respective settings within the Easy View tab:

Software Settings:  the custom name for the selected op amp peripheral

 Hardware Settings:

  • Enable Op amp:  Enables the peripheral
  • Enable Charge Pump: Uses more power to improve op amp performance for lower operating voltages
  • Enable Internal Output: Switches the op amp output from connecting to an external pin or an internal peripheral
  • Op Amp Configuration: Select between different configurations, including:
    • Direct Connect to Pins
    • Unity Gain Buffer
    • Non-Inverting Programmable Gain Amplifier
    • Inverting Programmable Gain Amplifier
    • Custom Configuration

Op Amp configurations

Channel Selection:

  • Positive Channel and Negative Channel: Sets the signal running into the op amp
  • Positive Source Selection and Negative Source Selection: Controls the source of the op amp input signal pins

After one of the programmable gain configurations or customer configurations is selected from Op Amp Configuration, then under Programmable Gain and Feedback Selection, there will be:

  • Resistor Ladder: Enables the resistors used for the programmable gain
  • Internal Resistor Ladder Selection: Set a programmable gain based on these values

Programmable Gain and Feedback Selection

  • Gain: Calculates the resulting gain from the resistor ladder for the user
  • Feedback Mode Selection: Changes what signal is fed back into the negative op amp input

 

 The Hardware Override Selection includes:

  • Hardware Override: Enables or disables the Hardware Override feature that uses a signal input to change the op amp configuration
  • Hardware Override Source Selection: Determines which signal can trigger the Hardware override

Hardware Override Source Selection

  • Override Control High Configuration and Override Control Low Configuration: Determine which configuration the op amp will be in when the signal is high or low, respectively

This is also where peak, trough, tri-state, and rail drive configurations are located.

Override Control High Configuration and Override Control Low Configuration

  • Override Source Polarity: Selects whether the Override signal will be active high when noninverted or active low when inverted

Override Source Polarity

Back to Top


Once the op amp and other peripheral configurations are all complete, click the Generate button next to Project Resources. 

Back to Top


Once generated, switch the Resource Manager tab on the left to Projects.  Navigate to your project's Source Files and open main.c to write any application code.

Projects tab

Back to Top

Accessing MCC Melody API

When writing application code, the user may need to reconfigure or call certain functions for the op amp peripheral. These functions can be found under the project’s header files.

project’s header file

Back to Top


For these header files open opa.h in the directory under your {project name}>Header Files>MCC Generated Files>opa. The available functions with comments explaining what each function does will appear on your main window.

Back to Top


More information on the MCC/Melody API for this peripheral is available by visiting the "3.19.4 5.5 MHz Gain Bandwidth OPAMP with Hardware Peak Detect" page. It can also be found in MCC Melody by clicking the blue question mark by the peripheral name in the Device Resources or Project Resources if the peripheral has already been added to a project.

Device Resources

Project Resources

Back to Top

Conclusions

In this lab, you created a PIC18F56Q71 MPLAB X IDE project and used MCC Melody to add an op amp driver and review its various settings. You also accessed the API and the guide to further configure the op amp peripheral. As a next step, you can create your own configurations suitable to your needs or explore integrated op amp configurations for another microcontroller.

Back to Top

Learn More

Back to Top