Skip to content

microchip-pic-avr-examples/pic18f47q10-cnano-pwm-constant-on-time-mcc

Repository files navigation

MCHP

PIC18F47Q10 PWM Constant on-time

Objective:

This repository contains an example of MCC generated code for PWM as described in TB3270 - Getting Started with PWM Using CCP on PIC18 document from Microchip.
The PIC18F47Q10 features four 10-bit PWM generators. This example describes how to configure the CCP2 peripheral in conjunction with TMR4 to produce a PWM signal with variable frequency and constant on-time.
Two GPIO pins are used. RE2 as an input to read the on-board button for controlling the demo and RC7 as a PWM output.

Related Documentation

Software Used

Hardware Used

  • PIC18F47Q10 Curiosity Nano (DM182029)
  • Oscilloscope or logic analyzer for visualization

Setup

The PIC18F47Q10 Curiosity Nano Development Board is used as the test platform.


The following configuration is done for this example:

  • RC7 pin - Configured as digital PWM output (CCP2)
  • RE2 pin - Configured as digital input with pull-up for button SW0

Operation

Hardware Setup

Hook the oscilloscope probe on RC7 and run the code generated by MCC. A signal with the frequency of 50kHz and 1 microsecond on-time will be visualized.

  • A press on the push-button (SW0) produces a change of frequency (50, 100, 200, 400 or 800kHz). The on-time is kept at 1 microsecond.

Timing diagram

Summary

This project showcases how to configure the PIC18F47Q10 microcontroller for generating a PWM with constant on-time while varying the frequency. The example shows both MCC initialization of the CCP2 and TMR4 for PWM and update of parameters at run-time.