Walkthrough PIC18F56Q71 MPLAB® Code Configurator Melody Operational Amplifier (Op Amp) Driver
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.
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.
Select Application Project and click Next.
Select your device. This demonstration is using a PIC18F56Q71 device and the corresponding simulator tool.
Next, select a compiler.
Name your project and assign its location. Then, click Finish.
After the project is created click the blue MCC shield at the 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
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.)
Under Device Resources, scroll down to OPAMP and add OPA1.
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
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.
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
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
- 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
- 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
- Override Source Polarity: Selects whether the Override signal will be active high when noninverted or active low when inverted
Once the op amp and other peripheral configurations are all complete, click the Generate button next to Project Resources.
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.
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.
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.
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.
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.
Learn More
- 8-bit PIC® MCU Peripheral Summary
- All 8-bit MCUs with Op Amps
- Operational Amplifier Module
- Introduction to Operational Amplifiers
- PIC18F26-46-56Q71 Microcontroller Data Sheet
- MCC Melody API Reference for PIC16F/18F MCU Families
- Create a Unity Gain Amplifier Using PIC18F56Q71
- Develop a Non-Inverting Amplifier Using PIC18F56Q71
- Multiplex Analog Inputs Into PIC18F56Q71 Op Amp