Analog-to-Digital Converter with Computation (ADCC) and Context Switching — Differential Reading Using PIC18F56Q71 Microcontroller with MCC Melody
This code example demonstrates how to perform a differential coversion using the Analog-to-Digital Converter with Computation (ADCC) and Context Switching and visualize the voltage difference of two input channels using the Data Visualizer tool. The application starts with the initialization of the ADCC with Context Switching and Universal Asynchronous Receiver Transmitter (UART) peripherals, and then a conversion is performed every 10 ms. The conversion result is sent via serial communication using the UART peripheral in the Data Visualizer format, in which a real-time plot is displayed.
More details and code examples for the PIC18F56Q71 can be found at the following links:
- MPLAB® X IDE v6.10 or newer
- MPLAB XC8 v2.41 or newer
- PIC18F-Q Series Device Pack v1.18.389 or newer
- MPLAB Code Configurator v5.3.7 or newer
- MPLAB Code Configurator Melody v2.5.0 or newer
- PIC10/PIC12/PIC16/PIC18 Devices Library v5.17.1 or newer
-
The PIC18F56Q71 Curiosity Nano Development board is used as a test platform:
To program the Curiosity Nano board with this MPLAB X project, follow the steps provided in the How to Program the Curiosity Nano Board chapter.
The following configurations must be made for this project:
- System clock is configured at 64 MHz – ADCRC Oscillator enabled
- ADCC with Content Switching:
- Input Configuration: Differential mode
- Result Format: Right justified, two's complement
- VDD: 3.3V
- Clock Selection: ADCRC
- Enable Context 1:
- Positive Channel Selection: ANA2
- Positive Voltage Reference: VDD
- Negative Channel Selection: ANA1
- Negative Voltage Reference: VSS
- Operating Mode Selection: Basic mode
- Double Sampling
- UART2:
- 115200 baud rate
- 8 data bits
- No parity bit
- 1 Stop bit
- RX and TX pins enabled (RB5 and RB4)
Pin | Configuration |
---|---|
RA1 | Analog input |
RA2 | Analog input |
RB4 (TX) | Digital output |
RB5 (RX) | Digital input |
In this example, the Analog-to-Digital Converter (ADC) reads data from the two potentiometers and displays the result on the serial terminal.
To visualize the ADCC with Content Switching readings in a graphical format use the Data Visualizer time plot.
Follow the procedure below to open the Graph/Time plot in Data Visualizer:
-
Open the Data Visualizer tool, available as a plugin in MPLAB X IDE
-
Click on Connections>Serial Ports
-
Open the COMx Settings window corresponding to the port that your device is connected to. Set the Baud Rate to 115200.
-
Click Play to start streaming
-
Click Variable Streamers>New...
-
Add new variables as shown in the image below and click Save
-
Select the source of the plot as COMx port
This method determines if the result is positive or negative.
Note: The COM port number can differ depending on the port availability.
This chapter demonstrates how to use the MPLAB X IDE to program a PIC® device with an Example_Project.X
. This is applicable to other projects.
-
Connect the board to the PC.
-
Open the
Example_Project.X
project in MPLAB X IDE. -
Set the
Example_Project.X
project as main project.
Right click the project in the Projects tab and click Set as Main Project. -
Clean and build the
Example_Project.X
project.
Right click theExample_Project.X
project and select Clean and Build. -
Select PICxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:
Right click the project and click Properties.
Click the arrow under the Connected Hardware Tool.
Select PICxxxxx Curiosity Nano (click the SN), click Apply and then OK: -
Program the project to the board.
Right click the project and click Make and Program Device.
This code example shows how to configure the ADCC with Context Switching using the MPLAB Code Configurator and demonstrates the use of the peripheral by sending the result via the UART interface and plotting it with Data Visualizer.