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.

Version: Timer Interface Version 1.0.0

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.

Version: TMR1 Driver Version 3.0.1
Functions

Function Documentation

Timer1_CheckGateValueStatus()

uint8_t Timer1_CheckGateValueStatus (void )

Reads the TMR1 gate value and returns it.

Precondition:

Use this function when the TMR1 gate is enabled.

Parameters:
None.
Returns:

Gate value status.

Timer1_GateISR()

void Timer1_GateISR (void )

Timer Gate ISR called by the Interrupt Manager.

Parameters:
None.
Returns:

None.

Timer1_HasOverflowOccured()

bool Timer1_HasOverflowOccured (void )

Checks for the timer Overflow flag when in Polling mode.

Parameters:
None.
Return values:
True

- Timer overflow has occured.

False

- Timer overflow has not occured.

Timer1_Initialize()

void Timer1_Initialize (void )

Initializes the timer module. This routine must be called before any other timer routines.

Parameters:
None.
Returns:

None.

Timer1_OverflowCallbackRegister()

void Timer1_OverflowCallbackRegister (void(*)(void) CallbackHandler)

Setter function for the timer overflow callback.

Parameters:
void

(* CallbackHandler)(void) - Pointer to custom callback.

Returns:

None.

Timer1_OverflowISR()

void Timer1_OverflowISR (void )

Timer Interrupt Service Routine (ISR) called by the Interrupt Manager for overflow events.

Parameters:
None.
Returns:

None.

Timer1_Read()

uint16_t Timer1_Read (void )

Reads the 16-bit value from the TMR1 register.

Precondition:

Initialize timer with Timer1_Initialize() before calling this API.

Parameters:
None.
Returns:

16-bit data from the TMR1 register.

Timer1_Reload()

void Timer1_Reload (void )

Loads a 8-bit value to TMR1 register.

Precondition:

Initialize timer with Timer1_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

Timer1_Start()

void Timer1_Start (void )

Starts the timer.

Precondition:

Initialize timer with Timer1_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

Timer1_StartSinglePulseAcquisition()

void Timer1_StartSinglePulseAcquisition (void )

Starts the single pulse acquisition in TMR1 gate operation.

Precondition:

Use this function when the TMR1 gate is enabled.

Parameters:
None.
Returns:

None.

Timer1_Stop()

void Timer1_Stop (void )

Stops the timer.

Precondition:

Initialize timer with Timer1_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

Timer1_Write()

void Timer1_Write (size_t timerVal)

Writes a 16-bit value to the TMR1 register.

Precondition:

Initialize timer with Timer1_Initialize() before calling this API.

Parameters:
size_t

timerVal - 16-bit value to be written to the TMR1 register.

Returns:

None.

4.24.2.1.7 Class Documentation

TMR_INTERFACE Struct Reference

Instance of TMR_INTERFACE for the timer module.

Member Data Documentation

The documentation for this struct was generated from the following file:

source/

timer_interface.h

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>

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

Detailed Description

This file contains the API implementations for the TMR1 driver.

TMR1 Generated Driver File

Version: TMR1 Driver Version 3.0.1

Function Documentation

Timer1_DefaultOverflowCallback()

static void Timer1_DefaultOverflowCallback (void )[static]

Variable Documentation

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

Detailed Description

TMR1 Generated Driver API Header File