This repository contains an example of MCC Melody-generated source code for Timer0 (TMR0) as described in TB3285 - Getting Started with Timers/Counters on PIC18 document from Microchip. This example shows how to configure the TMR0 in 16-bit mode, and generate an overflow interrupt every 10 seconds, using LFINOSC as a clock source. TMR0 runs while the microcontroller (MCU) is in Sleep mode.
A GPIO pin (the development board’s on-board LED) will be configured as output and when the interrupt occurs, the microcontroller is woken up, the LED is lit for 100 ms and then the microcontroller is put back in Sleep mode.
The code was generated using MPLAB® Code Configurator.
- TB3285 - Getting Started with Timers/Counters on PIC18
- PIC18-Q10 Product Family Page
- PIC18F47Q10 Data Sheet
- PIC18F47Q10 Code Examples on GitHub
- MPLAB® X IDE v6.05 or newer
- MPLAB® XC8 2.40 or newer
- MPLAB® Code Configurator Melody
- PIC18F-Q_DFP Device Family Pack v1.15.360 or newer
- Logic analyzer software
- PIC18F47Q10 Curiosity Nano Development Board is used as a test platform. (DM182029)
- Oscilloscope / Logic Analyzer
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.
The following peripheral and clock configurations are set up using MCC Melody for the PIC18F47Q10:
-
Clock Control:
-
TMR0:
Configuration Bits:
The following pin configuration must be made for this project:
Pin | Configuration | Function |
---|---|---|
RE0 | Digital Output | LED0 |
This demo shows how the TMR0 interrupt works when the MCU is in Sleep mode. The on-board LED toggles every 10 seconds when the timer interrupt wakes up the MCU.
The LED signal is shown in the logic analyzer software picture below.
This project provides an example of a basic use case based on TMR0 interrupt.
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.
-
Clean and build the Example_Project.X project.
-
Select the PICxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:
-
Program the project to the board.