Timer Peripheral Library for MPLAB® Harmony v2

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. You have to identify the specific timer and the function to be performed on that timer.

Example Library Functions

Stopping a Timer

Function Name Description
PLIB_TMR_Stop (TMR_ID_3) Stops Timer3

Configuring a Timer

Function Name Description
PLIB_TMR_ClockSourceSelect (TMR_ID_1, TMR_CLOCK_SOURCE_PERIPHERAL_CLOCK) Uses internal peripheral clock to drive Timer1
PLIB_TMR_PrescaleSelect (TMR_ID_2, TMR_PRESCALE_VALUE_256) Sets Timer2 prescale value to 256
PLIB_TMR_Mode16BitEnable (TMR_ID_3) Configures Timer3 as a 16 bit timer/counter
PLIB_TMR_Counter16BitClear (TMR_ID_2) Clears 16-bit Timer2 value
PLIB_TMR_Period16BitSet (TMR_ID_1, 0x1000) Sets 16-bit Timer1 period

Starting a Timer

Function Name Description
PLIB_TMR_Start (TMR_ID_4) Starts Timer4

Reading a Timer's Current Value

Function Name Description
MyVar = PLIB_TMR_Counter32BitGet (TMR_ID_2) Gets 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 >
© 2019 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.