Skip to content

This repository provides a bare-metal code example for using TMR0 in 16-bit Mode with sleep operation. An interrupt will wake up the device every 10s and LED0 will light up for 100 ms and then the MCU will be put back to sleep.

microchip-pic-avr-examples/pic18f47q10-cnano-tmr0-16bit-sleep-int-bare

Repository files navigation

MCHP

PIC18F47Q10 Using TMR0 in 16-bit Mode with Periodic Interrupt

Objective

This repository contains an example of bare-metal source code for TMR0 as described in TB3285 - Getting Started with Timers/Counters on PIC18 document from Microchip.

This example describes how to configure TMR0 in 16-bit mode and generate an overflow interrupt every ten seconds, using LFINTOSC as clock source. TMR0 is running while the microcontroller 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.

Related Documentation

Software Used

Hardware Used

Setup

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

Microchip

The following configurations must be made for this project:

  • Clock
    • Oscillator Select: HFINTOSC
    • HF Internal Clock: 1 MHz
    • Clock Divider: 1
  • TMR0
    • TMR0 Enabled
    • Clock Prescaler: 1:32
    • Postscaler: 1:1
    • Timer mode: 16-bit
    • Clock Source: LFINTOSC
    • Synchronization: disabled
    • Timer period: 10 seconds
    • Timer interrupt: enabled
  • Watchdog Timer: disabled
  • Low-voltage Programming: enabled
Pin Configuration
RE0 (LED0) Digital Output

Operation

  1. Connect the board to the PC.

  2. Open the pic18f47q10-cnano-tmr0-16bit-sleep-int-bare.X project in MPLAB® X IDE.

  3. Set pic18f47q10-cnano-tmr0-16bit-sleep-int-bare project as main project. Right click on the project in the Projects tab and click Set as Main Project:

Microchip

  1. Select the PIC18F47Q10 Curiosity Nano in the Hardware Tool section of the project settings:
  • Right click on the project and click Properties;
  • Select the PIC18F47Q10 Curiosity Nano (click on the SN) in the Hardware Tool tab and then click OK:

Microchip

  1. Program the project to the board: right click on the project and click Make and Program Device:

Microchip

Demo:

Microchip

Summary

This project is an illustration for a basic use case based around TMR0.

About

This repository provides a bare-metal code example for using TMR0 in 16-bit Mode with sleep operation. An interrupt will wake up the device every 10s and LED0 will light up for 100 ms and then the MCU will be put back to sleep.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published