Generate Drivers and Modify main.c
Step 9 - Click on the Generate code button to have MCC create the software libraries for this project.

Step 11 - The PWM Duty cycle is adjusted by a value of 0 to 1023 in the PWM control routine. This is a 10-bit resolution. This example will only use half of the range of 1 to 512 to change the brightness of the LED connected to the PWM output. The main loop of code adjusts the PWM value in increments of ten and uses a for-loop delay routine to allow the PWM value to be displayed on the D2 (RA4) LED. To perform this routine, the following code needs to be entered in the main.c file under the while (1) area where the MCC generated template says // Add your application code.
while (1)
{
// Add your application code
PWM6_Initialize();
for (int duty = 1; duty < 512; duty = duty + 10)
{
PWM6_LoadDutyValue(duty);
for (int delay = 1; delay < 500; delay++)
{;}
}
}
The PWM6_LoadDutyValue(duty) function was generated by the MCC and its definition is located in the pwm6.h file.
The PWM6_Initialize() function is also generated to initialize the PWM peripheral. It's also located in the pwm6.h file.
This is a simple example of how the MCC generates a library of useful functions to make creating a PWM project code much easier and quicker.
