Step 3: Configure MCU1 Resources with MCC

Step 3.1 - Launch MCC

1

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

MCC-Open-Close.png

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.

1

Click on System Module in the Project Resources window.

8-bit-PIC-DMA9a.png

2

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

8-bit-PIC-DMA10b.png

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.

1

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

Timer0_DR.png

2

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

Timer0_PR.png

3

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.

8-bit-PIC-DMA14.png

Step 3.4 – Configure ADC

The ADC is used to read the potentiometer voltage.

1

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

8-bit-PIC-DMA11b.png

2

Now select the ADCC CIP in the Project Resources window.

8-bit-PIC-DMA15.png

3

Update the ADCC configuration window to match the following:

8-bit-PIC-DMA16.png

Step 3.5 – Configure UART

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

1

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

8-bit-PIC-DMA31a.png

2

Select UART3 in the Project Resources window.

8-bit-PIC-DMA33a.png

3

Update the UART3 configuration window to match the following:

8-bit-PIC-DMA18.png

Step 3.6 – Configure GPIO

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

1

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:

8-bit-PIC-DMA19.png

Step 3.7 – Configure DMA

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

1

Select DMA Manager from the Project Resources window

DMA_PR.png

2

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.

8-bit-PIC-DMA22.png

3

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.

8-bit-PIC-DMA23.png

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

1

Press the Generate button.

8-bit-PIC-DMA25.png

2

Verify the MCC code generation is successful.

8-bit-PIC-DMA27.png
© 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.