4.25 UTMR - Universal Timer

4.25.1 Introduction

The MCC Melody UTMR PLIB Driver (Peripheral Library) generates API's to support UTMR-specific peripheral functionality on PIC18 target MCU's.

The Universal Timer (UTMR) is a 16-bit timer/counter with a combination of signal measurement and hardware limit timer functions. It is designed to provide all timer/counter related functions in a single peripheral.

4.25.2 Supported Device Families

PIC18F-Q71 PIC18F-Q83 PIC18F-Q84

4.25.3 Required header files:

#include "mcc_generated_files/timer/tu16[X].h"
Note: Replace [X] with the selected instance of the UTMR module.

4.25.4 Module Documentation

4.25.4.1 TU16x

This file contains the API prototypes for the TU16x module.

4.25.4.1.1 Module description

This file contains the API prototypes for the TU16x module.

Version: TU16x Driver Version 2.1.0
Functions

4.25.4.1.2 Function Documentation

__interrupt()

void __interrupt (irq(TU16X) , base(8) )

Vectored interrupt of the UTMR module.

Precondition:

Initialize the UTMR module with interrupts enabled before calling this API.

Parameters:
None.
Returns:

None.

Note:

The vectored interrupt can be configured to either high or low priority.

TU16x_CaptureInterruptDisable()

void TU16x_CaptureInterruptDisable (void )

Disables the capture interrupt.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_CaptureInterruptEnable()

void TU16x_CaptureInterruptEnable (void )

Enables the capture interrupt.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_CaptureMatchDefaultInterruptHandler()

void TU16x_CaptureMatchDefaultInterruptHandler (void )

Default Capture Match interrupt handler function.

Precondition:

Initialize the UTMR module with interrupts enabled before calling the ISR.

Parameters:
None.
Returns:

None.

TU16x_CaptureMatchInterruptHandlerSet()

void TU16x_CaptureMatchInterruptHandlerSet (void(*InterruptHandler)(void))

Registers a callback function to be called for the Capture Match interrupt event.

Precondition:

Initialize the UTMR module with interrupts enabled before calling this API.

Parameters:
void(*InterruptHandler)(void)

- Pointer to the Capture Match interrupt event handler.

Returns:

None.

TU16x_CaptureValueRead()

uint32_t TU16x_CaptureValueRead (void )

Reads the uint32-bit value of the Capture register.

Reads the uint16-bit value of the Capture register.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
None.
Returns:

uint32-bit value of the Capture register.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
None.
Returns:

uint16-bit value of the Capture register.

Reads the uint32-bit value of the Capture register.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
None.
Returns:

uint16-bit value of the Capture register.

TU16x_CounterClear()

void TU16x_CounterClear (void )

Clears the Timer Counter and the internal prescaler counter to zero.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
None.
Returns:

None.

Note:

When the UTMR Enable and Clock Synchronization (CSYNC) bits are set, it takes three timer clock cycles to synchronize the clocks. Clearing the UTMR Enable bit would require the selected clock source, especially the External Cock Sources (ERS), to supply at least three additional clock cycles to resolve the internal state. The user must be careful because if the timer is already running, any Stop/Reset-related ERS events that get processed will continue to affect the Run state of the timer.

TU16x_DefaultInterruptHandler()

void TU16x_DefaultInterruptHandler (void )

Default interrupt handler function.

Precondition:

Initialize the UTMR module with interrupts enabled before calling the ISR.

Parameters:
None.
Returns:

None.

TU16x_HasCaptureOccured()

bool TU16x_HasCaptureOccured (void )

Returns the Capture Interrupt flag status.

Precondition:

None.

Parameters:
None.
Return values:
True

- A capture event has occurred.

False

- A capture event has not occurred since this bit was last cleared.

TU16x_HasPRMatchOccured()

bool TU16x_HasPRMatchOccured (void )

Returns the Period Match Interrupt flag status.

Precondition:

None.

Parameters:
None.
Return values:
True

- The counter has incremented from PR-1 to PR.

False

- The counter has not incremented from PR-1 to PR since this bit was last cleared.

TU16x_HasResetOccured()

bool TU16x_HasResetOccured (void )

Returns the Zero Interrupt flag status.

Precondition:

None.

Parameters:
None.
Return values:
True

- The counter has reset or rolled over to zero.

False

- The counter has not reset or rolled over since this bit was last cleared.

TU16x_Initialize()

void TU16x_Initialize (void )

Initializes the module register values.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_InterruptDisable()

void TU16x_InterruptDisable (void )

Disables the UTMR main interrupt.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_InterruptEnable()

void TU16x_InterruptEnable (void )

Enables the UTMR main interrupt.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_InterruptFlagsClear()

void TU16x_InterruptFlagsClear (void )

Clears the status bit of the UTMR module interrupt flags.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_InterruptHandlerSet()

void TU16x_InterruptHandlerSet (void(*InterruptHandler)(void))

Registers a callback function to be called for the main interrupt event.

Precondition:

Initialize the UTMR module with interrupts enabled before calling this API.

Parameters:
void(*InterruptHandler)(void)

- Pointer to the interrupt event handler.

Returns:

None.

TU16x_IsInterruptEnabled()

bool TU16x_IsInterruptEnabled (void )

Returns the status of the main UTMR interrupt flag.

Precondition:

None.

Parameters:
None.
Return values:
True

- Interrupt is enabled.

False

- Interrupt is disabled.

TU16x_IsTimerRunning()

bool TU16x_IsTimerRunning (void )

Returns the UTMR running flag status.

Precondition:

None.

Parameters:
None.
Return values:
True

- UTMR is running and not being held in Reset by the External Reset Source (ERS).

False

- UTMR is not running or is held in Reset by the ERS.

TU16x_OnCommandCapture()

uint32_t TU16x_OnCommandCapture (void )

Captures the current timer value and stores it in the Capture register.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
None.
Returns:

uint32-bit value of the Capture register.

Note:

When the UTMR Enable and Clock Synchronization (CSYNC) bits are set, it takes three timer clock cycles to synchronize the clocks. Clearing the UTMR Enable bit would require the selected clock source, especially the External Cock Sources (ERS), to supply at least three additional clock cycles to resolve the internal state. The user must be careful because if the timer is already running, any Stop/Reset-related ERS events that get processed will continue to affect the Run state of the timer.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
None.
Returns:

uint16-bit value of the Capture register.

Note:

When the UTMR Enable and Clock Synchronization (CSYNC) bits are set, it takes three timer clock cycles to synchronize the clocks. Clearing the UTMR Enable bit would require the selected clock source, especially the External Cock Sources (ERS), to supply at least three additional clock cycles to resolve the internal state. The user must be careful because if the timer is already running, any Stop/Reset-related ERS events that get processed will continue to affect the Run state of the timer.

TU16x_PeriodValueSet() for 16-bit mode

void TU16x_PeriodValueSet (uint16_t prVal)

Writes the value to the Period registers.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
prVal

- Value to load to the Period register.

Returns:

None.

Note:

Writing to the Timer Period register is double-buffered, thus stopping the UTMR is not required. This must be followed by a Reset event for the new period value to become effective.

TU16A_PeriodValueSet() for 32-bit mode

void TU16A_PeriodValueSet (uint32_t prVal)

Writes the value to the Period registers.

Precondition:

Initialize the TU16A before calling this function.

Parameters:
prVal

- Value to load to the Period register.

Returns:

None.

Note:

Writing to the Timer Period register is double-buffered, thus stopping the UTMR is not required. This must be followed by a Reset event for the new period value to become effective.

Note: The 32-bit mode is only available in the TU16A instance.
TU16x_PRMatchDefaultInterruptHandler()

void TU16x_PRMatchDefaultInterruptHandler (void )

Default Period Match interrupt handler function.

Precondition:

Initialize the UTMR module with interrupts enabled before calling the ISR.

Parameters:
None.
Returns:

None.

TU16x_PRMatchInterruptDisable()

void TU16x_PRMatchInterruptDisable (void )

Disables the Period register match interrupt.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_PRMatchInterruptEnable()

void TU16x_PRMatchInterruptEnable (void )

Enables the Period register match interrupt.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_PRMatchInterruptHandlerSet()

void TU16x_PRMatchInterruptHandlerSet (void(*InterruptHandler)(void))

Registers a callback function to be called for the Period Match interrupt event.

Precondition:

Initialize the UTMR module with interrupts enabled before calling this API.

Parameters:
void(*InterruptHandler)(void)

- Pointer to the Period Match interrupt event handler.

Returns:

None.

TU16x_Read()

uint32_t TU16x_Read (void )

Reads the Timer Counter register value.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
None.
Returns:

Current value of the Timer Counter register.

Note:

The Timer Counter register is not double-buffered, thus the timer must be stopped before writing to it. If the desired action is to clear the counter while the timer is running, consider using the CounterClear() API. If the desired action is to change the overall period of the timer (running or not), consider changing the Timer Period register (which is double-buffered) through the PeriodValueSet() API.

TU16x_Start()

void TU16x_Start (void )

Starts the TU16X.

Precondition:

Intialize the TU16X before calling this function.

Parameters:
None.
Returns:

None.

TU16x_Stop()

void TU16x_Stop (void )

Stops the TU16X.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
None.
Returns:

None.

TU16x_Write()

void TU16x_Write (size_t timerVal)

Writes the Timer Counter register value.

Precondition:

Initialize the TU16X before calling this function.

Parameters:
timerVal

- Value to write to the Timer Counter register.

Returns:

None.

Note:

The Timer Counter register is not double-buffered, thus the timer must be stopped before writing to it. If the desired action is to clear the counter while the timer is running, consider using the CounterClear() API. If the desired action is to change the overall period of the timer (running or not), consider changing the Timer Period register (which is double-buffered) through the PeriodValueSet() API.

TU16x_ZeroInterruptDisable()

void TU16x_ZeroInterruptDisable (void )

Disables the zero condition match interrupt.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_ZeroInterruptEnable()

void TU16x_ZeroInterruptEnable (void )

Enables the zero condition match interrupt.

Precondition:

None.

Parameters:
None.
Returns:

None.

TU16x_ZeroMatchDefaultInterruptHandler()

void TU16x_ZeroMatchDefaultInterruptHandler (void )

Default Zero Match interrupt handler function.

Precondition:

Initialize the UTMR module with interrupts enabled before calling the ISR.

Parameters:
None.
Returns:

None.

TU16x_ZeroMatchInterruptHandlerSet()

void TU16x_ZeroMatchInterruptHandlerSet (void(*InterruptHandler)(void))

Registers a callback function to be called for the Zero Match interrupt event.

Precondition:

Initialize the UTMR module with interrupts enabled before calling this API.

Parameters:
void(*InterruptHandler)(void)

- Pointer to the Zero Match interrupt event handler.

Returns:

None.

4.25.5 Class Documentation

4.25.5.1 TMR_INTERFACE Struct Reference

Instance of the TMR_INTERFACE for the Universal Timer (UTMR) module.

4.25.5.1.1 Detailed Description

Instance of the TMR_INTERFACE for the Universal Timer (UTMR) module.

Section: Included Files Section: TU16X APIs

#include <tu16x (32-bit mode).h>

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

source/source-files/

tu16x (32-bit mode).h

4.25.6 File Documentation

4.25.6.1 source/source-files/tu16a.c (32-bit mode) File Reference

#include <xc.h>
#include "../tu16a.h"

4.25.6.1.1 Functions

4.25.6.1.3 Variable Documentation

TU16x_CaptureMatchInterruptHandler

void(* TU16x_CaptureMatchInterruptHandler) (void)[static]

TU16x_InterruptHandler

void(* TU16x_InterruptHandler) (void)[static]

TU16x_PRMatchInterruptHandler

void(* TU16x_PRMatchInterruptHandler) (void)[static]

TU16x_ZeroMatchInterruptHandler

void(* TU16x_ZeroMatchInterruptHandler) (void)[static]

4.25.6.2 source/source-files/tu16a.h (32-bit mode) File Reference

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "timer_interface.h"

4.25.6.2.1 Functions

4.25.6.2.3 Variable Documentation

TU16x

const struct TMR_INTERFACE TU16x

4.25.6.3 source/source-files/tu16x.c File Reference

This file contains the API definitions for the TU16X module.

#include <xc.h>
#include "../tu16x.h"

4.25.6.3.1 Functions

4.25.6.3.3 Detailed Description

This file contains the API definitions for the TU16X module.

TU16X Generated Driver File

Version: TU16X Driver Version 2.1.0

4.25.6.3.4 Variable Documentation

TU16x_CaptureMatchInterruptHandler

void(* TU16x_CaptureMatchInterruptHandler) (void)[static]

TU16x_InterruptHandler

void(* TU16x_InterruptHandler) (void)[static]

TU16x_PRMatchInterruptHandler

void(* TU16x_PRMatchInterruptHandler) (void)[static]

TU16x_ZeroMatchInterruptHandler

void(* TU16x_ZeroMatchInterruptHandler) (void)[static]

4.25.6.4 source/source-files/tu16x.h File Reference

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "timer_interface.h"

4.25.6.4.1 Functions

4.25.6.4.3 Detailed Description

TU16X Generated Driver API Header File

4.25.6.4.4 Variable Documentation

TU16x

const struct TMR_INTERFACE TU16x