Step 6.1 - Launch MCC
1
Open MPLAB® Code Configurator (MCC) by clicking the MCC logo in the MPLAB X Integrated Development Environment (IDE) toolbar.
Step 6.2 - Configure System Module
Now you can start configuring the settings for MCU2.
1
Click on System Module in the Project Resources window.
2
As before, we will use the HFINTOSC Oscillator for the clock source.
Step 6.3 – Configure PWM
Now we will add the Core Independent Peripherals (CIPs) needed to the project and configure them. The PWM is used to control the LED brightness with its duty cycle value.
1
Add PWM by opening the PWM folder under Device Resources window and clicking the + icon for PWM1_16BIT.
2
Select the PWM1_16BIT CIP in the Project Resources window to configure its settings:
3
Make necessary changes to the PWM configuration window to match the following settings:
- Enable PWM: Check
- Clock Selection: FOSC
- Clock Prescaler: 0
- Mode: Left aligned mode
- Requested Frequency: 1 kHz
- Output1 Duty Cycle (%): 50
- Output2 Duty Cycle (%): 50
Step 6.4 – Configure UART
The UART is used to receive the ADC results.
1
Open the UART folder in the Device Resources window and click on the + icon for UART3.
2
Open the UART3 setting by clicking UART3 in the Project Resources window.
3
Configure UART3 for the following settings:
- Mode: Asynchronous 8-bit mode
- Enable UART: Check
- Enable Transmit: Check
- Enable Receive: Check
- Baud Rate: 9600
- Transmit Polarity: not inverted
- Receive Polarity: not inverted
Step 6.5 – Configure GPIO
GPIO will be configured to output the PWM waveform and to receive 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:
Step 6.6 – Configure DMA
The DMA is used to transfer the UART receive buffer contents to the PWM duty cycle register
1
Select DMA Manager from the Project Resources window.
2
Update the DMA configuration window as follows:
- DMA Channel 1 Box: Check
- Source Module: UART3
- Source Region: SFR
- Source SFR: U3RXB
- Source Mode: unchanged
- Source Message Size: 1
3
Continue to update the DMA configuration window as follows:
- Destination Module: PWM1_16BIT
- Destination Region: SFR
- Destination SFR: PWM1S1P1L
- Destination Mode: incremented
- Destination Message Size: 2
- Start Trigger: U3RX
Step 6.7 – Update PWM Settings
The PWM needs to be assigned to DMA Channel 1.
1
Select the PWM1_16BIT CIP from the Project Resources window again.
2
Open the UART3 setting by clicking UART3 in the Project Resources window.
Step 6.8 - Generate MCC Code
1
Press the Generate button.
2
Verify the MCC code generation is successful.