3.25 UTMR - Universal Timer
3.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.
3.25.2 Supported Device Families
PIC18F-Q71 | PIC18F-Q83 | PIC18F-Q84 |
3.25.3 Required header files:
#include "mcc_generated_files/timer/tu16[X].h"
3.25.4 Specific MISRA C:2012 Deviations
- Global TU16A_MAX_COUNT
-
Advisory: misra-c2012-2.5
Justification: MCC Melody drivers provide macros that can be added to an application. It depends on the application whether a macro is used or not. - Global TU16A_Write
-
Advisory: misra-c2012-2.5
Justification: MCC Melody drivers provide macros that can be added to an application. It depends on the application whether a macro is used or not.
3.25.5 Module Documentation
3.25.5.1 TU16A
This file contains API prototypes and other data types for the TU16A module.
3.25.5.1.1 Module description
This file contains API prototypes and other data types for the TU16A module.
Definitions
#define TU16A_MAX_COUNT (0xFFFFU)
Defines the maximum count of the timer.
#define TU16A_CLOCK_FREQ (64000000UL)
Defines the timer prescaled clock frequency in hertz.
#define TU16A_Write TU16A_CounterSet
Defines the Custom Name for the TU16A_CounterSet API. The TU16A_Write will be deprecated in the future release. Use TU16A_CounterSet instead.
#define TU16A_Read TU16A_CounterGet
Defines the Custom Name for the TU16A_CounterGet API. The TU16A_Read will be deprecated in the future release. Use TU16A_CounterGet instead.
#define TU16A_CaptureValueRead TU16A_CaptureValueGet
Defines the Custom Name for the TU16A_CaptureValueGet API. The TU16A_CaptureValueRead will be deprecated in the future release. Use TU16A_CaptureValueGet instead.
#define TU16A_PeriodValueSet TU16A_PeriodSet
Defines the Custom Name for the TU16A_PeriodSet API. The TU16A_PeriodValueSet will be deprecated in the future release. Use TU16A_PeriodSet instead.
#define TU16A_IsTimerRunning TU16A_RunningStatusGet
Defines the Custom Name for the TU16A_RunningStatusGet API. The TU16A_IsTimerRunning will be deprecated in the future release. Use TU16A_RunningStatusGet instead.
#define TU16A_HasPRMatchOccured TU16A_PeriodMatchStatusGet
Defines the Custom Name for the TU16A_PeriodMatchStatusGet API. The TU16A_HasPRMatchOccured will be deprecated in the future release. Use TU16A_PeriodMatchStatusGet instead.
#define TU16A_HasResetOccured TU16A_ResetStatusGet
Defines the Custom Name for the TU16A_PeriodMatchStatusGet API. The TU16A_HasResetOccured will be deprecated in the future release. Use TU16A_ResetStatusGet instead.
#define TU16A_HasCaptureOccured TU16A_CaptureStatusGet
Defines the Custom Name for the TU16A_CaptureStatusGet API. The TU16A_HasCaptureOccured will be deprecated in the future release. Use TU16A_CaptureStatusGet instead.
#define TU16A_PRMatchInterruptHandlerSet TU16A_PeriodMatchCallbackRegister
Defines the Custom Name for the TU16A_PeriodMatchCallbackRegister API. The TU16A_PRMatchInterruptHandlerSet will be deprecated in the future release. Use TU16A_PeriodMatchCallbackRegister instead.
#define TU16A_ZeroMatchInterruptHandlerSet TU16A_ZeroMatchCallbackRegister
Defines the Custom Name for the TU16A_ZeroMatchCallbackRegister API. The TU16A_ZeroMatchInterruptHandlerSet will be deprecated in the future release. Use TU16A_ZeroMatchCallbackRegister instead.
#define TU16A_CaptureMatchInterruptHandlerSet TU16A_CaptureEventCallbackRegister
Defines the Custom Name for the TU16A_CaptureEventCallbackRegister API. The TU16A_CaptureMatchInterruptHandlerSet will be deprecated in the future release. Use TU16A_CaptureEventCallbackRegister instead.
Functions
void TU16A_Initialize (void)
Initializes the TU16A module.
void TU16A_Deinitialize (void)
Deinitializes the TU16A module.
void TU16A_Start (void)
Starts the TU16A.
void TU16A_Stop (void)
Stops the TU16A.
uint16_t TU16A_CaptureValueGet (void)
Returns the captured counter value from the Timer Capture register.
uint16_t TU16A_OnCommandCapture (void)
Executes the capture command and returns the captured count value from the Timer Capture register.
uint16_t TU16A_CounterGet (void)
Returns the current counter value.
void TU16A_CounterSet (uint16_t timerVal)
Sets the counter value.
void TU16A_CounterClear (void)
Clears the Timer Counter and the internal prescaler counter to zero.
void TU16A_PeriodSet (uint16_t periodVal)
Sets the period value to the Timer Period register.
uint16_t TU16A_PeriodGet (void)
Returns the current period value.
uint16_t TU16A_MaxCountGet (void)
Returns the maximum count value.
bool TU16A_PeriodMatchStatusGet (void)
Returns the Period Match Interrupt flag status.
bool TU16A_ResetStatusGet (void)
Returns the Zero Interrupt flag status.
bool TU16A_CaptureStatusGet (void)
Returns the Capture Interrupt flag status.
void TU16A_PeriodMatchInterruptEnable (void)
Enables the period match interrupt.
void TU16A_PeriodMatchInterruptDisable (void)
Disables the period match interrupt.
void TU16A_ZeroMatchInterruptEnable (void)
Enables the zero condition match interrupt.
void TU16A_ZeroMatchInterruptDisable (void)
Disables the zero condition match interrupt.
void TU16A_CaptureInterruptEnable (void)
Enables the capture interrupt.
void TU16A_CaptureInterruptDisable (void)
Disables the capture interrupt.
void TU16A_InterruptEnable (void)
Enables the UTMR main interrupt.
void TU16A_InterruptDisable (void)
Disables the UTMR main interrupt.
bool TU16A_IsInterruptEnable (void)
Returns the status of the UTMR Interrupt Enable bit.
bool TU16A_RunningStatusGet (void)
Returns the UTMR Running flag status.
void TU16A_InterruptFlagsClear (void)
Clears the UTMR module interrupt flags.
void TU16A_Tasks (void)
Performs tasks to be executed during the UTMR interrupt events.
void TU16A_ISR (void)
Interrupt Service Routine (ISR) of the UTMR interrupts.
void TU16A_PeriodMatchCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A Period Match interrupt event.
void TU16A_ZeroMatchCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A zero match or Reset interrupt event.
void TU16A_CaptureEventCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A capture event.
3.25.5.1.2 Definition Documentation
TU16A_CaptureMatchInterruptHandlerSet
#define TU16A_CaptureMatchInterruptHandlerSet TU16A_CaptureEventCallbackRegister
Defines the Custom Name for the TU16A_CaptureEventCallbackRegister API. The TU16A_CaptureMatchInterruptHandlerSet will be deprecated in the future release. Use TU16A_CaptureEventCallbackRegister instead.
TU16A_CaptureValueRead
#define TU16A_CaptureValueRead TU16A_CaptureValueGet
Defines the Custom Name for the TU16A_CaptureValueGet API. The TU16A_CaptureValueRead will be deprecated in the future release. Use TU16A_CaptureValueGet instead.
TU16A_CLOCK_FREQ
#define TU16A_CLOCK_FREQ (64000000UL)
Defines the timer prescaled clock frequency in hertz.
TU16A_HasCaptureOccured
#define TU16A_HasCaptureOccured TU16A_CaptureStatusGet
Defines the Custom Name for the TU16A_CaptureStatusGet API. The TU16A_HasCaptureOccured will be deprecated in the future release. Use TU16A_CaptureStatusGet instead.
TU16A_HasPRMatchOccured
#define TU16A_HasPRMatchOccured TU16A_PeriodMatchStatusGet
Defines the Custom Name for the TU16A_PeriodMatchStatusGet API. The TU16A_HasPRMatchOccured will be deprecated in the future release. Use TU16A_PeriodMatchStatusGet instead.
TU16A_HasResetOccured
#define TU16A_HasResetOccured TU16A_ResetStatusGet
Defines the Custom Name for the TU16A_PeriodMatchStatusGet API. The TU16A_HasResetOccured will be deprecated in the future release. Use TU16A_ResetStatusGet instead.
TU16A_IsTimerRunning
#define TU16A_IsTimerRunning TU16A_RunningStatusGet
Defines the Custom Name for the TU16A_RunningStatusGet API. The TU16A_IsTimerRunning will be deprecated in the future release. Use TU16A_RunningStatusGet instead.
TU16A_MAX_COUNT
#define TU16A_MAX_COUNT (0xFFFFU)
Defines the maximum count of the timer.
MISRA C:2012 Deviation Advisory: misra-c2012-2.5
Justification: MCC Melody drivers provide macros that can be added to an application. It depends on the application whether a macro is used or not.TU16A_PeriodValueSet
#define TU16A_PeriodValueSet TU16A_PeriodSet
Defines the Custom Name for the TU16A_PeriodSet API. The TU16A_PeriodValueSet will be deprecated in the future release. Use TU16A_PeriodSet instead.
TU16A_PRMatchInterruptHandlerSet
#define TU16A_PRMatchInterruptHandlerSet TU16A_PeriodMatchCallbackRegister
Defines the Custom Name for the TU16A_PeriodMatchCallbackRegister API. The TU16A_PRMatchInterruptHandlerSet will be deprecated in the future release. Use TU16A_PeriodMatchCallbackRegister instead.
TU16A_Read
#define TU16A_Read TU16A_CounterGet
Defines the Custom Name for the TU16A_CounterGet API. The TU16A_Read will be deprecated in the future release. Use TU16A_CounterGet instead.
TU16A_Write
#define TU16A_Write TU16A_CounterSet
Defines the Custom Name for the TU16A_CounterSet API. The TU16A_Write will be deprecated in the future release. Use TU16A_CounterSet instead.
MISRA C:2012 Deviation Advisory: misra-c2012-2.5
Justification: MCC Melody drivers provide macros that can be added to an application. It depends on the application whether a macro is used or not.TU16A_ZeroMatchInterruptHandlerSet
#define TU16A_ZeroMatchInterruptHandlerSet TU16A_ZeroMatchCallbackRegister
Defines the Custom Name for the TU16A_ZeroMatchCallbackRegister API. The TU16A_ZeroMatchInterruptHandlerSet will be deprecated in the future release. Use TU16A_ZeroMatchCallbackRegister instead.
3.25.5.1.3 Function Documentation
TU16A_CaptureEventCallbackRegister()
void TU16A_CaptureEventCallbackRegister (void(*)(void) CallbackHandler)
Registers a callback function for the TU16A capture event.
CallbackHandler |
- Address to the custom callback function |
None. |
TU16A_CaptureInterruptDisable()
void TU16A_CaptureInterruptDisable (void )
Disables the capture interrupt.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_CaptureInterruptEnable()
void TU16A_CaptureInterruptEnable (void )
Enables the capture interrupt.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_CaptureStatusGet()
bool TU16A_CaptureStatusGet (void )
Returns the Capture Interrupt flag status.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
True |
- A capture event has occurred |
False |
- A capture event has not occurred since this bit was last cleared |
TU16A_CaptureValueGet()
uint16_t TU16A_CaptureValueGet (void )
Returns the captured counter value from the Timer Capture register.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
Captured counter value |
TU16A_CounterClear()
void TU16A_CounterClear (void )
Clears the Timer Counter and the internal prescaler counter to zero.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
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.
TU16A_CounterGet()
Returns the current count value from the Timer Counter register.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
Counter value from the Timer Counter register |
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 PeriodSet() API.
TU16A_CounterSet()
void TU16A_CounterSet (uint16_t timerVal)
Sets the counter value.
Initialize TU16A with TU16A_Initialize() before calling this API. |
timerVal |
- Counter value to be written to the Timer Counter register |
None. |
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 PeriodSet() API.
TU16A_Deinitialize()
void TU16A_Deinitialize (void )
Deinitializes the TU16A module.
None. |
None. |
TU16A_Initialize()
void TU16A_Initialize (void )
Initializes the TU16A module.
None. |
None. |
TU16A_InterruptDisable()
void TU16A_InterruptDisable (void )
Disables the UTMR main interrupt.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_InterruptEnable()
void TU16A_InterruptEnable (void )
Enables the UTMR main interrupt.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_InterruptFlagsClear()
void TU16A_InterruptFlagsClear (void )
Clears the UTMR module interrupt flags.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_IsInterruptEnable()
bool TU16A_IsInterruptEnable (void )
Returns the status of the UTMR Interrupt Enable bit.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
True |
- Interrupt is enabled |
False |
- Interrupt is disabled |
TU16A_ISR()
void TU16A_ISR (void )
Interrupt Service Routine (ISR) of the UTMR interrupts.
None. |
None. |
TU16A_MaxCountGet()
uint16_t TU16A_MaxCountGet (void )
Returns the maximum count value.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
Maximum count value |
TU16A_OnCommandCapture()
uint16_t TU16A_OnCommandCapture (void )
Executes the capture command and returns the captured count value from the Timer Capture register.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
Captured counter value |
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.
TU16A_PeriodGet()
uint16_t TU16A_PeriodGet (void )
Returns the current period value.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
Current period count value |
TU16A_PeriodMatchCallbackRegister()
void TU16A_PeriodMatchCallbackRegister (void(*)(void) CallbackHandler)
Registers a callback function for the TU16A Period Match interrupt event.
CallbackHandler |
- Address to the custom callback function |
None. |
TU16A_PeriodMatchInterruptDisable()
void TU16A_PeriodMatchInterruptDisable (void )
Disables the period match interrupt.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_PeriodMatchInterruptEnable()
void TU16A_PeriodMatchInterruptEnable (void )
Enables the period match interrupt.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_PeriodMatchStatusGet()
bool TU16A_PeriodMatchStatusGet (void )
Returns the Period Match Interrupt flag status.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
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 |
TU16A_PeriodSet()
void TU16A_PeriodSet (uint16_t periodVal)
Sets the period value to the Timer Period register.
Initialize TU16A with TU16A_Initialize() before calling this API. |
prVal |
- Period value to be written to the Timer Period register |
None. |
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_ResetStatusGet()
bool TU16A_ResetStatusGet (void )
Returns the Zero Interrupt flag status.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
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 |
TU16A_RunningStatusGet()
bool TU16A_RunningStatusGet (void )
Returns the UTMR Running flag status.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
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 |
TU16A_Start()
void TU16A_Start (void )
Starts the TU16A.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_Stop()
void TU16A_Stop (void )
Stops the TU16A.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_Tasks()
void TU16A_Tasks (void )
Performs tasks to be executed during the UTMR interrupt events.
None. |
None. |
TU16A_ZeroMatchCallbackRegister()
void TU16A_ZeroMatchCallbackRegister (void(*)(void) CallbackHandler)
Registers a callback function for the TU16A zero match or Reset interrupt event.
CallbackHandler |
- Address to the custom callback function |
None. |
TU16A_ZeroMatchInterruptDisable()
void TU16A_ZeroMatchInterruptDisable (void )
Disables the zero condition match interrupt.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
TU16A_ZeroMatchInterruptEnable()
void TU16A_ZeroMatchInterruptEnable (void )
Enables the zero condition match interrupt.
Initialize TU16A with TU16A_Initialize() before calling this API. |
None. |
None. |
3.25.6 TU16 Examples
This section explains various use case examples of the Timer module within an MPLAB® Code Configurator (MCC) Melody Project.
3.25.6.1 TU16A PLIB Examples
3.25.6.1.1 Continuously Turn the LED On for 4 ms and Off for 8 ms in Non-Interrupt Mode
This use case configures the Timer module to toggle an LED on and off with specific timing intervals: 4 ms on and 8 ms off.
-
System>Clock Control:
-
Clock Source: HFINTOSC
-
HF Internal Clock: 64 MHz
-
-
System>Pins:
-
Pin Grid View: Select LED pin as output (Check the schematic for your board)
-
Pins: Rename Custom Name to "LED"
-
-
Drivers>UTMR:
-
Timer Dependency Selector: TU16A
-
-
Drivers>TU16A:
-
Timer Enable: False
-
Prescaler: 9
-
Synchronization Enable: False
-
Reset Condition: At PR Match
-
TMR Interrupt Enable: False
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h" /* * Development Board: PIC18F57Q84 Curiosity Nano Board * MCC Configuration: * System module: HFINTOSC (64 MHz) * UTMR module: Timer Dependency Selector - TU16A * TU16A module: Timer Enable - False, Prescaler - 9, Synchronization Enable - False, Reset Condition - At PR Match, Timer Interrupt Enable - False * Pins module: RF3 - GPIO Output, CustomName - LED */ #define USE_TASKS_API 1 #define MS_TO_TICKS(ms) (((TU16A_CLOCK_FREQ * (ms)) / 1000UL) - 1UL) #define LED_4_MS (MS_TO_TICKS(4UL)) #define LED_8_MS (MS_TO_TICKS(8UL)) static void Timer_PeriodChange(void) { static volatile bool changePeriod = false; LED_Toggle(); TU16A_Stop(); uint16_t maxCount = TU16A_MaxCountGet(); uint16_t newPeriod = changePeriod ? LED_4_MS:LED_8_MS; if(maxCount > newPeriod) { TU16A_PeriodSet(newPeriod); } else { // Invalid period } changePeriod = !changePeriod; TU16A_Start(); } int main(void) { SYSTEM_Initialize(); TU16A_PeriodSet(LED_4_MS); TU16A_InterruptFlagsClear(); #if USE_TASKS_API TU16A_PeriodMatchCallbackRegister(Timer_PeriodChange); #endif LED_SetHigh(); TU16A_Start(); while(1) { #if USE_TASKS_API TU16A_Tasks(); #else if(1U == TU16A_PeriodMatchStatusGet()) { Timer_PeriodChange(); TU16A_InterruptFlagsClear(); } #endif } }
3.25.6.1.2 1s Timer Period Using the TU16A Timer in Chaining Mode
This use case configures the TU16A PLIB in Chaining mode to generate the period match interrupt at a period of 1s while toggling an LED.
-
System>Clock Control:
-
Clock Source: HFINTOSC
-
HF Internal Clock: 64 MHz
-
-
System>Pins:
-
Pin Grid View: Select LED pin as output (Check the schematic for your board)
-
Pins: Rename Custom Name to "LED"
-
-
Drivers>UTMR:
-
Enable Timer Chaining: True
-
Timer Dependency Selector: TU16A + TU16B
-
-
Drivers>TU16A:
-
Timer Enable: True
-
Clock Source: HFINTOSC
-
Requested Period: 1s
-
Synchronization Enable: False
-
Reset Condition: At PR Match
-
TMR Interrupt Enable: True
-
Period Match Interrupt Enable: True
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h" /* * Development Board: PIC18F57Q84 Curiosity Nano Board * MCC Configuration: * System module: HFINTOSC (64 MHz) * UTMR module: Enable Timer Chaining - True, Timer Dependency Selector - TU16A + TU16B * TU16A module: Timer Enable - True, Clock Source - HFINTOSC, Synchronization Enable - False, Reset Condition - At PR Match, Timer Interrupt Enable - True, Period Match Interrupt Enable - True * Pins module: RF3 - GPIO Output, CustomName - LED */ #define POSTSCALER 16UL #define MS_TO_TICKS(ms) (((TMR0_CLOCK_FREQ * (ms)) / 1000UL) - 1UL) #define LED_4_MS (MS_TO_TICKS(4UL)/POSTSCALER) void Custom_Callback(void) { LED_Toggle(); } int main(void) { SYSTEM_Initialize(); TMR0_CounterSet(0); if(TMR0_MaxCountGet() > LED_4_MS) { TMR0_PeriodSet(LED_4_MS); } else { //Invalid period //Generate default timer period } TMR0_PeriodMatchCallbackRegister(Custom_Callback); TMR0_Start(); INTERRUPT_GlobalInterruptEnable(); while(1) { } }
3.25.6.1.3 Timer Wake From Sleep at Every 5s
This use case configures the TU16A PLIB to wake the microcontroller (MCU) from Sleep mode every five seconds. The wake up event toggles an LED, then puts the MCU back to Sleep.
-
System>Clock Control:
-
Clock Source: HFINTOSC
-
HF Internal Clock: 64 MHz
-
-
System>Pins:
-
Pin Grid View: Select LED pin as output (Check the schematic for your board)
-
Pins: Rename Custom Name to "LED"
-
-
Drivers>UTMR:
-
Enable Timer Chaining: False
-
Timer Dependency Selector: TU16A
-
-
Drivers>TU16A:
-
Timer Enable: True
-
Clock Source: LFINTOSC
-
Prescaler: 2
-
Requested Period: 5s
-
Synchronization Enable: False
-
Reset Condition: At PR Match
-
Timer Interrupt Enable: True
-
Period Match Interrupt Enable: True
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h" /* * Development Board: PIC18F57Q84 Curiosity Nano Board * MCC Configuration: * System module: HFINTOSC (64 MHz) * TU16A module: Timer Enable - True, Clock Source - LFINTOSC, Prescaler - 2, Synchronization Enable - False, Requested Period - 5s, Reset Condition - At PR Match, Timer Interrupt Enable - True, Period Match Interrupt Enable - True * Pins module: RF3 - GPIO Output, CustomName - LED */ int main(void) { SYSTEM_Initialize(); // Enable the Global Interrupts INTERRUPT_GlobalInterruptEnable(); while(1) { LED_Toggle(); SLEEP(); // Add your code here to execute after exiting Sleep mode } }
3.25.7 File Documentation
3.25.7.1 source/tu16a.c File Reference
This file contains the API definitions for the TU16A module.
#include <xc.h> #include "../tu16a.h"
3.25.7.1.1 Functions
static void TU16A_PeriodMatchDefaultCallback (void)
static void TU16A_ZeroMatchDefaultCallback (void)
static void TU16A_CaptureEventDefaultCallback (void)
void TU16A_Initialize (void)
Initializes the TU16A module.
void TU16A_Deinitialize (void)
Deinitializes the TU16A module.
void TU16A_Start (void)
Starts the TU16A.
void TU16A_Stop (void)
Stops the TU16A.
uint16_t TU16A_CaptureValueGet (void)
Returns the captured counter value from the Timer Capture register.
uint16_t TU16A_OnCommandCapture (void)
Executes the capture command and returns the captured count value from the Timer Capture register.
uint16_t TU16A_CounterGet (void)
Returns the current counter value.
void TU16A_CounterSet (uint16_t timerVal)
Sets the counter value.
void TU16A_CounterClear (void)
Clears the Timer Counter and the internal prescaler counter to zero.
void TU16A_PeriodSet (uint16_t periodVal)
Sets the period value to the Timer Period register.
uint16_t TU16A_PeriodGet (void)
Returns the current period value.
uint16_t TU16A_MaxCountGet (void)
Returns the maximum count value.
bool TU16A_PeriodMatchStatusGet (void)
Returns the Period Match Interrupt flag status.
bool TU16A_ResetStatusGet (void)
Returns the Zero Interrupt flag status.
bool TU16A_CaptureStatusGet (void)
Returns the Capture Interrupt flag status.
bool TU16A_RunningStatusGet (void)
Returns the UTMR Running flag status.
void TU16A_InterruptFlagsClear (void)
Clears the UTMR module interrupt flags.
void TU16A_Tasks (void)
Performs tasks to be executed during the UTMR interrupt events.
void TU16A_PeriodMatchCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A Period Match interrupt event.
void TU16A_ZeroMatchCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A zero match or Reset interrupt event.
void TU16A_CaptureEventCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A capture event.
3.25.7.1.2 Variables
static void(* TU16A_PeriodMatchCallback )(void)
static void(* TU16A_ZeroMatchCallback )(void)
static void(* TU16A_CaptureEventCallback )(void)
3.25.7.1.3 Detailed Description
This file contains the API definitions for the TU16A module.
This file contains the API definitions for the TU16A Timer driver.
TU16A Generated Driver File
TU16A Generated Timer Driver File
3.25.7.1.4 Function Documentation
TU16A_CaptureEventDefaultCallback()
static void TU16A_CaptureEventDefaultCallback (void )[static]
TU16A_PeriodMatchDefaultCallback()
static void TU16A_PeriodMatchDefaultCallback (void )[static]
TU16A_ZeroMatchDefaultCallback()
static void TU16A_ZeroMatchDefaultCallback (void )[static]
3.25.7.1.5 Variable Documentation
TU16A_CaptureEventCallback
void(* TU16A_CaptureEventCallback) (void)[static]
TU16A_PeriodMatchCallback
void(* TU16A_PeriodMatchCallback) (void)[static]
TU16A_ZeroMatchCallback
void(* TU16A_ZeroMatchCallback) (void)[static]
3.25.7.2 source/tu16a.h File Reference
This file contains the deprecated macros or APIs for the TU16A driver.
#include <stdint.h> #include <stdbool.h>
3.25.7.2.1 Functions
void TU16A_Initialize (void)
Initializes the TU16A module.
void TU16A_Deinitialize (void)
Deinitializes the TU16A module.
void TU16A_Start (void)
Starts the TU16A.
void TU16A_Stop (void)
Stops the TU16A.
uint16_t TU16A_CaptureValueGet (void)
Returns the captured counter value from the Timer Capture register.
uint16_t TU16A_OnCommandCapture (void)
Executes the capture command and returns the captured count value from the Timer Capture register.
uint16_t TU16A_CounterGet (void)
Returns the current counter value.
void TU16A_CounterSet (uint16_t timerVal)
Sets the counter value.
void TU16A_CounterClear (void)
Clears the Timer Counter and the internal prescaler counter to zero.
void TU16A_PeriodSet (uint16_t periodVal)
Sets the period value to the Timer Period register.
uint16_t TU16A_PeriodGet (void)
Returns the current period value.
uint16_t TU16A_MaxCountGet (void)
Returns the maximum count value.
bool TU16A_PeriodMatchStatusGet (void)
Returns the Period Match Interrupt flag status.
bool TU16A_ResetStatusGet (void)
Returns the Zero Interrupt flag status.
bool TU16A_CaptureStatusGet (void)
Returns the Capture Interrupt flag status.
void TU16A_PeriodMatchInterruptEnable (void)
Enables the period match interrupt.
void TU16A_PeriodMatchInterruptDisable (void)
Disables the period match interrupt.
void TU16A_ZeroMatchInterruptEnable (void)
Enables the zero condition match interrupt.
void TU16A_ZeroMatchInterruptDisable (void)
Disables the zero condition match interrupt.
void TU16A_CaptureInterruptEnable (void)
Enables the capture interrupt.
void TU16A_CaptureInterruptDisable (void)
Disables the capture interrupt.
void TU16A_InterruptEnable (void)
Enables the UTMR main interrupt.
void TU16A_InterruptDisable (void)
Disables the UTMR main interrupt.
bool TU16A_IsInterruptEnable (void)
Returns the status of the UTMR Interrupt Enable bit.
bool TU16A_RunningStatusGet (void)
Returns the UTMR Running flag status.
void TU16A_InterruptFlagsClear (void)
Clears the UTMR module interrupt flags.
void TU16A_Tasks (void)
Performs tasks to be executed during the UTMR interrupt events.
void TU16A_ISR (void)
Interrupt Service Routine (ISR) of the UTMR interrupts.
void TU16A_PeriodMatchCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A Period Match interrupt event.
void TU16A_ZeroMatchCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A zero match or Reset interrupt event.
void TU16A_CaptureEventCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A capture event.
3.25.7.2.2 Macros
#define TU16A_MAX_COUNT (0xFFFFU)
Defines the maximum count of the timer.
#define TU16A_CLOCK_FREQ (64000000UL)
Defines the timer prescaled clock frequency in hertz.
3.25.7.2.3 Detailed Description
This file contains the deprecated macros or APIs for the TU16A driver.
This file contains API prototypes and other data types for the TU16A Timer driver.
TU16A Generated Driver API Header File
TU16A Generated Driver API Header File
""
TU16A Generated Timer Driver API Header File
3.25.7.3 source/tu16a_deprecated.h File Reference
3.25.7.3.1 Macros
#define TU16A_Write TU16A_CounterSet
Defines the Custom Name for the TU16A_CounterSet API. The TU16A_Write will be deprecated in the future release. Use TU16A_CounterSet instead.
#define TU16A_Read TU16A_CounterGet
Defines the Custom Name for the TU16A_CounterGet API. The TU16A_Read will be deprecated in the future release. Use TU16A_CounterGet instead.
#define TU16A_CaptureValueRead TU16A_CaptureValueGet
Defines the Custom Name for the TU16A_CaptureValueGet API. The TU16A_CaptureValueRead will be deprecated in the future release. Use TU16A_CaptureValueGet instead.
#define TU16A_PeriodValueSet TU16A_PeriodSet
Defines the Custom Name for the TU16A_PeriodSet API. The TU16A_PeriodValueSet will be deprecated in the future release. Use TU16A_PeriodSet instead.
#define TU16A_IsTimerRunning TU16A_RunningStatusGet
Defines the Custom Name for the TU16A_RunningStatusGet API. The TU16A_IsTimerRunning will be deprecated in the future release. Use TU16A_RunningStatusGet instead.
#define TU16A_HasPRMatchOccured TU16A_PeriodMatchStatusGet
Defines the Custom Name for the TU16A_PeriodMatchStatusGet API. The TU16A_HasPRMatchOccured will be deprecated in the future release. Use TU16A_PeriodMatchStatusGet instead.
#define TU16A_HasResetOccured TU16A_ResetStatusGet
Defines the Custom Name for the TU16A_PeriodMatchStatusGet API. The TU16A_HasResetOccured will be deprecated in the future release. Use TU16A_ResetStatusGet instead.
#define TU16A_HasCaptureOccured TU16A_CaptureStatusGet
Defines the Custom Name for the TU16A_CaptureStatusGet API. The TU16A_HasCaptureOccured will be deprecated in the future release. Use TU16A_CaptureStatusGet instead.
#define TU16A_PRMatchInterruptHandlerSet TU16A_PeriodMatchCallbackRegister
Defines the Custom Name for the TU16A_PeriodMatchCallbackRegister API. The TU16A_PRMatchInterruptHandlerSet will be deprecated in the future release. Use TU16A_PeriodMatchCallbackRegister instead.
#define TU16A_ZeroMatchInterruptHandlerSet TU16A_ZeroMatchCallbackRegister
Defines the Custom Name for the TU16A_ZeroMatchCallbackRegister API. The TU16A_ZeroMatchInterruptHandlerSet will be deprecated in the future release. Use TU16A_ZeroMatchCallbackRegister instead.
#define TU16A_CaptureMatchInterruptHandlerSet TU16A_CaptureEventCallbackRegister
Defines the Custom Name for the TU16A_CaptureEventCallbackRegister API. The TU16A_CaptureMatchInterruptHandlerSet will be deprecated in the future release. Use TU16A_CaptureEventCallbackRegister instead.
3.25.7.4 source/tu16a_drv.c File Reference
#include <xc.h> #include "../tu16a.h"
3.25.7.4.1 Functions
static void TU16A_PeriodMatchDefaultCallback (void)
void TU16A_Initialize (void)
Initializes the TU16A module.
void TU16A_Deinitialize (void)
Deinitializes the TU16A module.
void TU16A_Start (void)
Starts the TU16A.
void TU16A_Stop (void)
Stops the TU16A.
uint32_t TU16A_CounterGet (void)
Returns the current counter value.
void TU16A_CounterSet (uint32_t timerVal)
Sets the count value to the Timer Counter register.
void TU16A_PeriodSet (uint32_t prVal)
Sets the timer period count to the Timer Period register.
uint32_t TU16A_PeriodGet (void)
Returns the current period value.
uint32_t TU16A_MaxCountGet (void)
Returns the maximum count value.
void TU16A_ISR (void)
Interrupt Service Routine (ISR) of the UTMR interrupts.
void TU16A_PeriodMatchCallbackRegister (void(*CallbackHandler)(void))
Registers a callback function for the TU16A Period Match interrupt event.
3.25.7.4.2 Variables
const struct TIMER_INTERFACE myTimer
static void(* TU16A_PeriodMatchCallback )(void) = TU16A_PeriodMatchDefaultCallback
3.25.7.4.3 Function Documentation
TU16A_PeriodMatchDefaultCallback()
static void TU16A_PeriodMatchDefaultCallback (void )[static]
3.25.7.4.4 Variable Documentation
myTimer
const struct TIMER_INTERFACE myTimer
Initial value:
= { .Initialize = TU16A_Initialize, .Deinitialize = TU16A_Deinitialize, .Start = TU16A_Start, .Stop = TU16A_Stop, .PeriodSet = TU16A_PeriodSet, .PeriodGet = TU16A_PeriodGet, .CounterGet = TU16A_CounterGet, .CounterSet = TU16A_CounterSet, .MaxCountGet = TU16A_MaxCountGet, .TimeoutCallbackRegister = TU16A_PeriodMatchCallbackRegister, .Tasks = NULL }
TU16A_PeriodMatchCallback
void(* TU16A_PeriodMatchCallback) (void) = TU16A_PeriodMatchDefaultCallback[static]
3.25.7.5 source/tu16a_drv.h File Reference
#include <stdint.h> #include <stdbool.h> #include "timer_interface.h"
3.25.7.5.1 Functions
void TU16A_Initialize (void)
Initializes the TU16A module. This routine must be called before any other TU16A routines.
void TU16A_Deinitialize (void)
Deinitializes the TU16A module.
void TU16A_Start (void)
Starts the TU16A timer.
void TU16A_Stop (void)
Stops the TU16A timer.
uint32_t TU16A_CounterGet (void)
Returns the current count value from the Timer Counter register.
void TU16A_CounterSet (uint32_t timerVal)
Sets the count value to the Timer Counter register.
void TU16A_PeriodSet (uint32_t periodVal)
Sets the timer period count to the Timer Period register.
uint32_t TU16A_PeriodGet (void)
Returns the TU16A period count value.
uint32_t TU16A_MaxCountGet (void)
Returns the TU16A maximum count value.
void TU16A_ISR (void)
Timer Interrupt Service Routine (ISR) for the TU16A interrupt events.
void TU16A_Tasks (void)
Performs the tasks to be executed during timer interrupt events.
void TU16A_PeriodMatchCallbackRegister (void(*CallbackHandler)(void))
Setter function for the Timer period match callback.
3.25.7.5.2 Macros
#define TU16A_MAX_COUNT (65535U)
Defines the maximum count of the timer.
#define TU16A_CLOCK_FREQ (64000000UL)
Defines the TU16A prescaled clock frequency in hertz.
#define MYTIMER_MAX_COUNT TU16A_MAX_COUNT
Defines the Custom Name for the TU16A_MAX_COUNT.
#define MYTIMER_CLOCK_FREQ TU16A_CLOCK_FREQ
Defines the Custom Name for the TU16A_CLOCK_FREQ.
#define myTimer_Initialize TU16A_Initialize
Defines the Custom Name for the TU16A_Initialize API.
#define myTimer_Deinitialize TU16A_Deinitialize
Defines the Custom Name for the TU16A_Deinitialize API.
#define myTimer_Start TU16A_Start
Defines the Custom Name for the TU16A_Start API.
#define myTimer_Stop TU16A_Stop
Defines the Custom Name for the TU16A_Stop API.
#define myTimer_CounterGet TU16A_CounterGet
Defines the Custom Name for the TU16A_CounterGet API.
#define myTimer_CounterSet TU16A_CounterSet
Defines the Custom Name for the TU16A_CounterSet API.
#define myTimer_PeriodSet TU16A_PeriodSet
Defines the Custom Name for the TU16A_PeriodSet API.
#define myTimer_PeriodGet TMR2_PeriodGet
Defines the Custom Name for the TMR2_PeriodGet API.
#define myTimer_MaxCountGet TU16A_MaxCountGet
Defines the Custom Name for the TU16A_MaxCountGet API.
#define myTimer_ISR TU16A_ISR
Defines the Custom Name for the TU16A_ISR API.
#define myTimer_Tasks TU16A_Tasks
Defines the Custom Name for the TU16A_Tasks API.
#define myTimer_PeriodMatchCallbackRegister TU16A_PeriodMatchCallbackRegister
Defines the Custom Name for the TU16A_PeriodMatchCallbackRegister API.
3.25.7.5.3 Variables
const struct TIMER_INTERFACE Timer1
3.25.7.5.4 Variable Documentation
Timer1
const struct TIMER_INTERFACE Timer1