Giter VIP home page Giter VIP logo

pic18f47q10-cnano-pwm-basic-demo-mcc's Introduction

MCHP

PWM Basic Configuration Example using the PIC18F47Q10 Microcontroller with MCC Melody

This repository contains an example of MCC® Melody generated code for Pulse Width Modulation (PWM) signals using Capture/Compare/PWM (CCP) module as described in Getting Started with PWM Using CCP on PIC18.
The PIC18F47Q10 features four 10-bit PWM generators. This example describes how to configure the CCP1 peripheral in conjunction with TMR2 to produce a low speed PWM signal.
Two GPIO pins are used:

  • RE2 as an input to read the on-board button for controlling the demo
  • RB4 as a PWM output

Related Documentation

Software Used

Hardware Used

  • PIC18F47Q10 Curiosity Nano Development Board is used as a test platform. (DM182029)
  • Oscilloscope or Logic Analyzer

Operation

To program the Curiosity Nano board with this MPLAB® X project, follow the steps provided in the How to Program the Curiosity Nano Board chapter.

1. Setup

The following peripheral and clock configurations are set up using MCC Melody for the PIC18F47Q10:

  • Clock Control:

    • Clock Source: LFINTOSC
    • Clock Divider: 1
  • Configuration Bits:

    • CONFIG3L
      • WDT Operating Mode: WDT Disabled
  • CCP1:

    • CCP Mode: PWM
    • Select Timer: Timer2
    • TMR Dependency Selector: Timer2
    • CCPR Alignment: Right Aligned
    • Enable CCP: Enabled
  • TMR2:

    • TMR Dependency Selector: Timer2
    • Enable Timer: Enabled
    • Clock Source: FOSC/4
    • Prescaler: 1/32
    • Time Period (s): 1
  • Pin Grid View:

    • CCP1 (in/out): RB4
    • GPIO input: RE2
  • Pins:

    • RB4:
      • Function: CCP1
      • Direction: In/Out
    • RE2:
      • Function: GPIO
      • Direction: Input
      • Custom Name: Button
      • Weak Pullup: Enabled


The following pin configuration must be made for this project:

Pin Configuration Function
RB4 Digital Output PWM CCP1
RE2 Digital Input GPIO - Button

Note: RE0 (LED0) pin is used as input for LED visualization. (optional)

2. Demo

There are two options to run this example:

  • hook the oscilloscope or the logic analyzer probe on RB4 pin
  • run a wire between RB4 and RE0

Then run the code generated by MCC, RB4 will generate a PWM signal with a frequency of 1 Hz. To demonstrate the run-time update of the PWM parameters, SW0 (RE2) push-button is used.

  • A short button press (less than 1.5 seconds) results in a change of duty-cycle in steps of 25% (from 25% up to 75%)
  • A long button press (1.5 to 2.0 seconds) results in a change of frequency from 1 Hz to 4 Hz in steps of 1 Hz

Snapshots of different cofigurations:

  • Frequency: 1 Hz, Duty-Cycle: 25%

  • Frequency: 1 Hz, Duty-Cycle: 50%

  • Frequency: 1 Hz, Duty-Cycle: 75%

  • Frequency: 2 Hz, Duty-Cycle: 25%

  • Frequency: 3 Hz, Duty-Cycle: 25%

  • Frequency: 4 Hz, Duty-Cycle: 25%

3. Summary

This project showcases how to configure basic PWM functionalities, such like duty cycle and frequency on the PIC18F47Q10 microcontroller. The example shows both MCC initialization of the CCP1 and TMR2 for PWM and update of parameters at run-time.

How to Program the Curiosity Nano board

This chapter shows how to use the MPLAB® X IDE to program an PIC® device with an Example_Project.X. This can be applied for any other projects.

  • Connect the board to the PC.

  • Open the Example_Project.X project in MPLAB X IDE.

  • Set the Example_Project.X project as main project.

    • Right click on the project in the Projects tab and click Set as Main Project.
  • Clean and build the Example_Project.X project.

    • Right click on the Example_Project.X project and select Clean and Build.
  • Select the PICxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:

    • Right click on the project and click Properties
    • Click on the arrow under the Connected Hardware Tool
    • Select the PICxxxxx Curiosity Nano (click on the SN), click Apply and then click OK:
  • Program the project to the board.

    • Right click on the project and click Make and Program Device.

pic18f47q10-cnano-pwm-basic-demo-mcc's People

Contributors

aku-work avatar grig-barbulescu avatar iustinian-mchp avatar mariusnicolae avatar mchpcristianpop avatar shaimahusain avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.