Timer Peripheral Library

This library allows you to:

  • Set the clock source for the timer
  • Read and set the timer value
  • Read and set the timer period match value
  • Start and stop the timer
  • Set 8-, 16- or 32-bit data width for the timer
  • Operate in SLEEP, IDLE, or DEBUG modes
  • Set the pre- and post-scaler settings
  • Control timer special event trigger settings
  • Control asynchronous clock counter mode for Timer1
  • Control gated clock counter mode

The Timer Peripheral Library (PLIB) controls the timers by accessing the timer's Special Function Registers (SFRs). Timer SFR access is by function rather than by name. The developer does not need to know an SFR name or the specific SFR bit-field when calling a timer PLIB function. The user just has to identify the specific timer and the function to be performed on that timer.

Example Library Functions

Stopping a Timer
Stop Timer3
Configuring a Timer
Use internal peripheral clock to drive Timer1
Set Timer2 prescale value to 256
Configure Timer3 as a 16 bit timer/counter
Clear 16-bit Timer2 value
PLIB_TMR_Period16BitSet(TMR_ID_1, 0x1000);
Set 16-bit Timer1 period
Starting a Timer
Start Timer4
Reading a Timer's Current Value
MyVar = PLIB_TMR_Counter32BitGet (TMR_ID_2);
Get 32-bit Timer2 value

The PLIB parameter for specifying a timer (TMR_ID_x) is defined by the enum TMR_MODULE_ID. The default values for this enumeration equates Timer1 with TMR_ID_1, Timer2 with TMR_ID_2, …etc

 Learn More

Harmony Timer Tutorial
Learn more >
Example Code and Projects
Learn more >
Entire Timer PLIB Interface
Learn more >
Timer Hardware Description
Learn more >
© 2018 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.