Analog Read Serial Write Using the ADCC Peripheral

 Objective

In this project, the voltage across the potentiometer on an MPLAB® Xpress Development board is converted to a 10-bit value using the Analog-to-Digital Converter with Computation peripheral. The value is then sent to the EUSART peripheral on the PIC16F18855 to be transmitted to the other PIC® MCU on the Xpress Board to convert and then transmitted over the USB connection to a computer to display in a terminal emulator program.

analogReadSerialWrite_mainDiagram.jpg

 Materials

Hardware Tools (Optional)

Tool About Purchase
Xpress-50px.png
MPLAB® Xpress
Development Board

Software Tools

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® Xpress
Cloud Integrated Development Environment
swtool-28px.png
CoolTerm FREE serial port terminal
http://freeware.the-meiers.org/

 Procedure

To follow along with these steps, open MPLAB® Xpress log in so that the MPLAB Code Configurator plug-in can be used.

1

Task 1

Create a new project in MPLAB Xpress for a PIC16F1855 using the MPLAB Xpress Development Board called analogReadSerialWrite.

Instructions are below if this is your first project.

2

Task 2

Open the MPLAB Code Configurator (MCC).

Instructions are below if this is your first project.

3

Task 3

Inside of the MCC, expand the ADCC heading in the Device Resources and double-click on the ADCC peripheral to add to the Project Resources.

ADCC_DeviceResources.jpg

4

Task 4

Select the ADCC peripheral under Project Resources>Peripherals to open the configuration window and configure as follows:

  • Ensure that Basic_Mode is selected in the Operating drop-down menu.
  • Select Right from the Result Alignment drop-down menu.
  • Set Acquisition Time to 1. This will delay for 1 x TAD = 1 x 2.0 µs before initiating the conversion process when the ADCC receives a trigger. This is a newer feature of the ADCC replacing traditional delays that tied-up the processor.

The ADCC Easy Setup Hardware Settings should now resemble the following image.

ADCCEasySetup.jpg

5

Task 5

In the Pin Manager pane, tie the RA4 pin that is connected to the potentiometer on the MPLAB Xpress Development Board to the ADCC input channel by clicking on the appropriate cell in the ANx row.

ADCCpinManager.jpg

6

Task 6

Highlight the Pin Module in Project Resources to open the Easy Setup pane. Edit the Custom Name field to rename the ADCC input channel to something more intuitive like "POT".

pinModule.jpg

7

Task 7

In the Device Resources pane, scroll down to locate the EUSART heading, expand and double-click to add the EUSART peripheral to the Project Resources>Peripherals section.

EUSART_DeviceResources.jpg

8

Task 8

Select the EUSART peripheral in the Project Resources to open the Easy Setup Hardware Settings and configure as follows:

  • Enable Transmit
  • Redirect STDIO to USART

The Easy Setup Hardware Settings should now resemble the following image.

EUSARTeasySetup.jpg

9

Task 9

In the Pin Manager, connect the EUSART signals as follows:

  • TX: RC0
  • RX: RC1
EUSARTpinManager.jpg

10

Task 10

Click the Generate button in MCC to create the appropriate header and source files for this configuration. A main.c file will also be generated for the project.

figure8.png

Upon successful code generation the “Generation Completed” notification should appear. Select OK to close the window.

figure9.png

11

Task 11

Return to the MPLAB Xpress IDE and open the adcc.h header file under the Project>analogReadSerialWrite>Header Files>MCC Generated Files folder tree.

generatedFiles.jpg

12

Task 12

Scroll down through the adcc.h header file to locate ADCC_GetSingleConversion(). This function will trigger a single ADCC conversion and is the same as the legacy ADC function call ADC_GetConversion() readers who’ve used the ADC peripheral on other devices may recognize.

Highlight and copy the function.

adccHeader.jpg

13

Task 13

In the Project pane, highlight the main.c source file to open.

mainScroll.jpg

14

Task 14

Scroll down through main.c to locate the while(1) loop inside of main(). Add the following printf statement pasting copied function from the previous step inside the statement as shown, changing the argument inside the brackets to the custom name POT:

printf(“\n\rThe ADC Value is: %i   “,ADCC_GetSingleConversion(POT));
  • \n: Creates a new line.
  • \r: Returns the cursor.
  • %i: Indicates that an integer value will be inserted at this point in the output.
  • POT: The custom name given to the pin RA4 connected to the potentiometer on the Xpress Board.
addPrintF.jpg

15

Task 15

The MPLAB Xpress Development should be connected to an available USB port on the host computer through a USB cable to the Micro-B connector on the board. Drivers should install successfully the first time the board is connected and may take a minute or so. The connection is shown in the picture. No other components are required.

figure3.png

16

Task 16

Compile and download the project HEX file by clicking on the Make and Program Device button at the top of the MPLAB Xpress IDE.

figure13.png

17

Task 17

Program the MPLAB Xpress board by dragging the project HEX file from the downloads section of the browser and dropping the file on to the XPRESS drive.

figure14.png

The Programmer LED on the Xpress board should quickly flash from green to red and then back to green indicating that the HEX file was successfully programmed to the PIC16F18855.

18

Task 18

Open a terminal program on the host computer select Connect. In this example the free program called CoolTerm is used.

connectToSerialPort.jpg

 Results

Once communication is established with the MPLAB Xpress Board, the Terminal screen should display a value between 0 and 1023 depending on the rotation of the potentiometer.

SerialOutput.jpg

 Analysis

The ADCC value output can be used to calculate the voltage across the potentiometer as per the following:

(1)
\begin{align} Voltage = {\frac{V_{REF}}{ADC Resolution}}\times\text{ADCC Value} \end{align}

Example:
If the ADC Value is 368, this equates to:

(2)
\begin{align} Voltage = {\frac{3.3V}{2^{10}-1}}\times\text{ADCC Value}={\frac{3.3V}{1023}}\times368= 1.19V \end{align}

Where: VREF is the Positive Reference selected when the ADCC was configured. This was left at the default of VDD (PIC16F18855 supply voltage) or 3.3 V.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.