The Operational Amplifier (OPA) peripheral on the PIC18F16Q41 family of devices comes with an internal resistor ladder that can be used to set different gains internally. This code example demonstrates how to use the internal resistor ladder to generate various DC levels without the use of a Digital-to-Analog Converter (DAC).
Code Example: AVR128DB48 Using the Internal Opamp as Regulated Power Supply for MVIO
Note: Versions 3.0.0 (and newer) of this project were switched to the Curiosity Nano. Previous versions used the Curiosity Development Board (DM164137).
Pin | Function |
---|---|
RC2 | Output of the OPA module |
RC7 | LED0 |
The internal resistor ladder of the OPA module is normally used to provide feedback for the operational amplifier. In this code example, the internal resistor ladder is used to generate a voltage level based on the internal resistor ladder. The output of the operational amplifier is proportional to the resistor divider network created between VDD and VSS, as shown below. GSEL (gain select) is the internal name for the resistor ladder. A simple diagram of this circuit is shown below.
The table below (reproduced from the PIC18F16Q41 data sheet) contains the ratios of the internal resistors available in PIC18F16Q41 and their expected outputs as a percentage of VDD and as an absolute value at VDD = 3.3V.
Resistor Ratio | Output % | Ideal Output at VDD = 3.3V |
---|---|---|
1/15 | 6.25% | 206.25 mV |
1/7 | 12.5% | 412.5 mV |
1/3 | 25% | 825 mV |
1 | 50% | 1.65V |
5/3 | 62.5% | 2.0625V |
3 | 75% | 2.475V |
7 | 87.5% | 2.8875V |
15 | 93.75% | 3.09375V |
To demonstrate the full range of outputs, the code example generates a free-running sawtooth waveform (shown below) that contains all of the output steps listed above. The LED toggles on each ladder step.
This code example demonstrates how the internal resistor ladder can be used to generate various DC output levels.