4.24.2.1 TMR1
Timer1
4.24.2.1.1 Introduction
The Timer1 (TMR1) module is a 16-bit timer with configurable timeout period and gate control features.
4.24.2.1.2 Supported Device Families
PIC16F145x | PIC12/16F150x | PIC16F151x |
PIC16F152x | PIC16F152xx | PIC16F153xx |
PIC12/16F157x | PIC12/16F161x | PIC16F170x |
PIC16F171x | PIC16F171xx | PIC16F176x |
PIC16F177x | PIC16F178x | PIC16F180xx |
PIC16F181xx | PIC16F183xx | PIC16F184xx |
PIC12/16F184x | PIC16F188xx | PIC16F191xx |
PIC16F194x | PIC16LF190x | PIC16LF156x |
PIC12/16LF155x | PIC18F-K20 | PIC18F-K22 |
PIC18F-K40 | PIC18F-K42 | PIC18F-K50 |
PIC18F-K80 | PIC18F-K83 | PIC18F-K90 |
PIC18F-Q10 | PIC18F-Q20 | PIC18F-Q24 |
PIC18F-Q40 | PIC18F-Q41 | PIC18F-Q43 |
PIC18F-Q71 | PIC18F-Q83 | PIC18F-Q84 |
4.24.2.1.3 Timer Interface
-
struct TMR_INTERFACE
Structure containing the function pointers of the TMR driver.
4.24.2.1.4 Required header files:
#include "mcc_generated_files/timer/tmr1.h"
4.24.2.1.5 How to Use the Timer1 or Timer2 PLIB Drivers
For use cases see: 4.24.1.2.5 How to Use the Timer0 PLIB Driver
Since Timer0 (TMR0), Timer1 (TMR1) and Timer2 (TMR2) share the same timer interface, running the TMR0 use cases on the other timers is relatively simple. Specifically, look for the TMR_INTERFACE definition in timerX.c, then set the timer pointer to use the correct timer interface, e.g., *Timer = &TimerX, where X is the timer instance.
/* Create a pointer of the type TMR_INTERFACE and assign it to the Timer0 TMR_INTERFACE struct address. This enables access to the portable API interface, facilitating the change of the peripheral instance the timer runs on. */ const struct TMR_INTERFACE *Timer = &Timer0;
Similarly, for more specific code, such as the line below, replace these with the equivalent code for the selected timer.
timerTMR0ReloadVal16bit = (uint16_t)LED_500ms; //Clear the Counter register
4.24.2.1.6 Module Documentation
TIMER INTERFACE
This file contains API prototypes and other data types for Timer module.
This file contains API prototypes and other data types for Timer module.
TMR1
This file contains the API prototypes and other data types for the TMR1 module.
Module description
This file contains the API prototypes and other data types for the TMR1 module.
Data structures
struct TMR_INTERFACE
Instance of TMR_INTERFACE for the timer module.
Functions
void Timer1_Initialize (void)
Initializes the timer module. This routine must be called before any other timer routines.
void Timer1_Start (void)
Starts the timer.
void Timer1_Stop (void)
Stops the timer.
uint16_t Timer1_Read (void)
Reads the 16-bit value from the TMR1 register.
void Timer1_Write (size_t timerVal)
Writes a 16-bit value to the TMR1 register.
void Timer1_Reload (void)
Loads a 8-bit value to TMR1 register.
void Timer1_StartSinglePulseAcquisition (void)
Starts the single pulse acquisition in TMR1 gate operation.
uint8_t Timer1_CheckGateValueStatus (void)
Reads the TMR1 gate value and returns it.
void Timer1_OverflowISR (void)
Timer Interrupt Service Routine (ISR) called by the Interrupt Manager for overflow events.
void Timer1_OverflowCallbackRegister (void(*CallbackHandler)(void))
Setter function for the timer overflow callback.
bool Timer1_HasOverflowOccured (void)
Checks for the timer Overflow flag when in Polling mode.
void Timer1_GateISR (void)
Timer Gate ISR called by the Interrupt Manager.
Function Documentation
Timer1_CheckGateValueStatus()
uint8_t Timer1_CheckGateValueStatus (void )
Reads the TMR1 gate value and returns it.
Use this function when the TMR1 gate is enabled. |
|
Gate value status. |
Timer1_GateISR()
void Timer1_GateISR (void )
Timer Gate ISR called by the Interrupt Manager.
|
None. |
Timer1_HasOverflowOccured()
bool Timer1_HasOverflowOccured (void )
Checks for the timer Overflow flag when in Polling mode.
|
|
Timer1_Initialize()
void Timer1_Initialize (void )
Initializes the timer module. This routine must be called before any other timer routines.
|
None. |
Timer1_OverflowCallbackRegister()
void Timer1_OverflowCallbackRegister (void(*)(void) CallbackHandler)
Setter function for the timer overflow callback.
|
None. |
Timer1_OverflowISR()
void Timer1_OverflowISR (void )
Timer Interrupt Service Routine (ISR) called by the Interrupt Manager for overflow events.
|
None. |
Timer1_Read()
uint16_t Timer1_Read (void )
Reads the 16-bit value from the TMR1 register.
Initialize timer with Timer1_Initialize() before calling this API. |
|
16-bit data from the TMR1 register. |
Timer1_Reload()
void Timer1_Reload (void )
Loads a 8-bit value to TMR1 register.
Initialize timer with Timer1_Initialize() before calling this API. |
|
None. |
Timer1_Start()
void Timer1_Start (void )
Starts the timer.
Initialize timer with Timer1_Initialize() before calling this API. |
|
None. |
Timer1_StartSinglePulseAcquisition()
void Timer1_StartSinglePulseAcquisition (void )
Starts the single pulse acquisition in TMR1 gate operation.
Use this function when the TMR1 gate is enabled. |
|
None. |
Timer1_Stop()
void Timer1_Stop (void )
Stops the timer.
Initialize timer with Timer1_Initialize() before calling this API. |
|
None. |
Timer1_Write()
void Timer1_Write (size_t timerVal)
Writes a 16-bit value to the TMR1 register.
Initialize timer with Timer1_Initialize() before calling this API. |
|
None. |
4.24.2.1.7 Class Documentation
TMR_INTERFACE Struct Reference
Instance of TMR_INTERFACE for the timer module.
Detailed Description
Instance of TMR_INTERFACE for the timer module.
#include <timer_interface.h>
Public Attributes
void(* Initialize )(void)
void(* Start )(void)
void(* Stop )(void)
void(* PeriodCountSet )(size_t count)
void(* TimeoutCallbackRegister )(void(*CallbackHandler)(void))
void(* Tasks )(void)
Member Data Documentation
Initialize
void(* TMR_INTERFACE::Initialize) (void)
PeriodCountSet
void(* TMR_INTERFACE::PeriodCountSet) (size_t count)
Start
void(* TMR_INTERFACE::Start) (void)
Stop
void(* TMR_INTERFACE::Stop) (void)
Tasks
void(* TMR_INTERFACE::Tasks) (void)
TimeoutCallbackRegister
void(* TMR_INTERFACE::TimeoutCallbackRegister) (void(*CallbackHandler)(void))
4.24.2.1.8 File Documentation
source/timer_interface.h File Reference
#include <stddef.h>
Data structures
struct TMR_INTERFACE
Instance of TMR_INTERFACE for the timer module.
Detailed Description
Timer Interface Generated Driver API Header File
source/tmr1.c File Reference
This file contains the API implementations for the TMR1 driver.
#include <xc.h> #include "../tmr1.h"
Functions
static void Timer1_DefaultOverflowCallback (void)
void Timer1_Initialize (void)
Initializes the timer module. This routine must be called before any other timer routines.
void Timer1_Start (void)
Starts the timer.
void Timer1_Stop (void)
Stops the timer.
uint16_t Timer1_Read (void)
Reads the 16-bit value from the TMR1 register.
void Timer1_Write (size_t timerVal)
Writes a 16-bit value to the TMR1 register.
void Timer1_Reload (void)
Loads a 8-bit value to TMR1 register.
void Timer1_StartSinglePulseAcquisition (void)
Starts the single pulse acquisition in TMR1 gate operation.
uint8_t Timer1_CheckGateValueStatus (void)
Reads the TMR1 gate value and returns it.
void Timer1_OverflowISR (void)
Timer Interrupt Service Routine (ISR) called by the Interrupt Manager for overflow events.
void Timer1_OverflowCallbackRegister (void(*CallbackHandler)(void))
Setter function for the timer overflow callback.
bool Timer1_HasOverflowOccured (void)
Checks for the timer Overflow flag when in Polling mode.
void Timer1_GateISR (void)
Timer Gate ISR called by the Interrupt Manager.
Variables
volatile uint16_t timer1ReloadVal
void(* Timer1_InterruptHandler )(void)
const struct TMR_INTERFACE Timer1
static void(* Timer1_OverflowCallback )(void)
Detailed Description
This file contains the API implementations for the TMR1 driver.
TMR1 Generated Driver File
Function Documentation
Timer1_DefaultOverflowCallback()
static void Timer1_DefaultOverflowCallback (void )[static]
Variable Documentation
Timer1
const struct TMR_INTERFACE Timer1
Initial value:
= { .Initialize = Timer1_Initialize, .Start = Timer1_Start, .Stop = Timer1_Stop, .PeriodCountSet = Timer1_Write, .TimeoutCallbackRegister = Timer1_OverflowCallbackRegister, .Tasks = NULL }
Timer1_InterruptHandler
void(* Timer1_InterruptHandler) (void)
Timer1_OverflowCallback
void(* Timer1_OverflowCallback) (void)[static]
timer1ReloadVal
volatile uint16_t timer1ReloadVal
Section: Included FilesSection: Global Variables Definitions
source/tmr1.h File Reference
#include <stdbool.h> #include <stdint.h> #include "timer_interface.h"
Functions
void Timer1_Initialize (void)
Initializes the timer module. This routine must be called before any other timer routines.
void Timer1_Start (void)
Starts the timer.
void Timer1_Stop (void)
Stops the timer.
uint16_t Timer1_Read (void)
Reads the 16-bit value from the TMR1 register.
void Timer1_Write (size_t timerVal)
Writes a 16-bit value to the TMR1 register.
void Timer1_Reload (void)
Loads a 8-bit value to TMR1 register.
void Timer1_StartSinglePulseAcquisition (void)
Starts the single pulse acquisition in TMR1 gate operation.
uint8_t Timer1_CheckGateValueStatus (void)
Reads the TMR1 gate value and returns it.
void Timer1_OverflowISR (void)
Timer Interrupt Service Routine (ISR) called by the Interrupt Manager for overflow events.
void Timer1_OverflowCallbackRegister (void(*CallbackHandler)(void))
Setter function for the timer overflow callback.
bool Timer1_HasOverflowOccured (void)
Checks for the timer Overflow flag when in Polling mode.
void Timer1_GateISR (void)
Timer Gate ISR called by the Interrupt Manager.
Variables
const struct TMR_INTERFACE Timer1
Detailed Description
TMR1 Generated Driver API Header File
Variable Documentation
Timer1
const struct TMR_INTERFACE Timer1