Step 3: Configure MCU1 Resources with MCC

Step 3.1 - Launch MCC


Open MPLAB® Code Configurator (MCC) by clicking the MCC logo in the MPLAB X Integrated Development Environment (IDE) toolbar.


Note: MCC may take a while to load the first time it is launched.

Step 3.2 - Configure System Module

Now you can start configuring the settings for MCU1.


Click on System Module in the Project Resources window.



For System Module, we will use the HFINTOSC Oscillator for the clock source.


Step 3.3 – Configure Timer0

Now we will add the Core Independent Peripherals (CIPs) needed for the project and configure them. Timer0 will be configured to create a periodic interrupt to trigger the Analog-to-Digital Converter (ADC) conversions.


Add Timer0 by opening the Timer folder under Device Resources window and clicking the + icon for TMR0.



Select the TMR0 CIP in the Project Resources window to configure its settings:



In the TMR0 configuration window, select FOSC/4 for the Clock Source and 1:64 for the Clock prescaler. This will configure Timer0 for a 50 ms rollover.


Step 3.4 – Configure ADC

The ADC is used to read the potentiometer voltage.


Add ADC by opening the ADCC folder in the Device Resources window and clicking the + icon for ADCC.



Now select the ADCC CIP in the Project Resources window.



Update the ADCC configuration window to match the following:


Step 3.5 – Configure UART

The UART for MCU1 is used to transmit the ADC results.


Add UART3 by opening the UART folder in the Device Resources window and clicking the + icon for UART3.



Select UART3 in the Project Resources window.



Update the UART3 configuration window to match the following:


Step 3.6 – Configure GPIO

General Purpose Input/Output (GPIO) is configured to read the analog potentiometer input and output the UART data.


Select Pin Manager: Grid View in the bottom right window. Click each pin with a green lock as either an input or output as shown in the figure below:


Step 3.7 – Configure DMA

The DMA for MCU1 is used to transfer the ADC result to the UART transmit buffer.


Select DMA Manager from the Project Resources window



Update the DMA configuration window as follows:

  • Check the DMA Channel 1 box
  • Set Source Module to ADCC
  • Set Source Region to SFR
  • Set Source SFR to ADRESL
  • Set Source Mode to Incremented
  • Set Source Message Size to 2

Note: Since the ADC result is 12 bits, the value is spread across two 8-bit registers. Both registers are automatically read by the DMA by setting Source Mode to Incremented and Source Message Size to 2.



Continue to update the DMA configuration window as follows:

  • Set the Destination Module to UART3
  • Set the Destination Region to SFR
  • Set the Destination SFR to U3TXB
  • Set the Destination Mode to Unchanged
  • Set the Destination Message Size to 1
  • Set the Start Trigger to U3TX

Note: Destination Message Size is 1 because the UART transmit buffer is one byte wide. Both ADC result buffer values will be transmitted by the DMA.


Note: If the DMA Start Trigger was set to occur after every ADC conversion, the DMA might write the UART transmit buffer before all the bits are shifted out, corrupting the transfer. Triggering the DMA after the UART transmit buffer is empty avoids this issue.

Step 3.8 - Generate MCC Code


Press the Generate button.



Verify the MCC code generation is successful.

© 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.