Skip to content

Getting Started with Timers/Counters on PIC18. The TMR1 is configured in gate single pulse mode.

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/pic18f47q10-cnano-tmr1-button-press-count-bare

Repository files navigation

MCHP

PIC18F47Q10 Using TMR1 Gate to measure short vs long button press

The PIC18F47Q10 features Timers with Gate Control. This example shows how to use the TMR1 configured in gate single pulse mode. It will start counting on a falling edge when the button is pressed. Two different interrupts will be activated based on how long the button was pressed. If the leading edge appears, a gate interrupt will be generated, denoting that the button was short pressed. If the timer overflows before the leading edge appears, an overflow interrupt will be generated, denoting that the button was long pressed.

Related Documentation

Software Used

Hardware Used

Setup

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

The following configurations must be made for this project:

Pin Configuration
RB5 Digital Input

Demo:

Connect a button to Pin RB5. Run the code in debug mode. Set breakpoints inside "TMR1_GATE_ISR()" and "TMR1_ISR()" functions. The button signal is read from the pin RB5. When the button is short pressed, the code will stop at the breakpoint set in the "TMR1_GATE_ISR()" function. When the button is long pressed, the code will stop at the breakpoint set in the "TMR1_ISR()" function.

Hardware Setup