TIMER - Timer/Counter#
Timer/Counter (TIMER) Peripheral API.
The timer module consists of three main parts:
General timer configuration and enable control.
Compare/capture control.
Dead time insertion control (may not be available for all timers).
Modules#
Enumerations#
Timer compare/capture mode.
Clock select.
Input capture edge select.
Input capture event control.
Input edge action.
Timer mode.
Compare/capture output action.
Prescaler.
PRS input type.
DT (Dead Time) Fault Actions.
PRS Output configuration.
Typedefs#
Peripheral Reflex System signal.
Functions#
Initialize TIMER.
Initialize the TIMER compare/capture channel.
Initialize the TIMER DTI unit.
Reset the TIMER to the same state that it was in after a hardware reset.
Wait for pending synchronization to finish.
Validate the TIMER register block pointer.
Check whether the TIMER is valid and supports Dead Timer Insertion (DTI).
Get the Max count of the timer.
Get compare/capture value for the compare/capture channel.
Get the buffered compare/capture value for compare/capture channel.
Set the compare value buffer for the compare/capture channel when operating in compare or PWM mode.
Set the compare value for compare/capture channel when operating in compare or PWM mode.
Get the TIMER counter value.
Set the TIMER counter value.
Start/stop TIMER.
Enable or disable DTI unit.
Get DTI fault source flags status.
Clear DTI fault source flags.
Clear one or more pending TIMER interrupts.
Disable one or more TIMER interrupts.
Enable one or more TIMER interrupts.
Get pending TIMER interrupt flags.
Get enabled and pending TIMER interrupt flags.
Set one or more pending TIMER interrupts from SW.
Set the top value buffer for the timer.
Get the top value setting for the timer.
Set the top value for timer.
Macros#
Default configuration for TIMER initialization structure.
Default configuration for TIMER compare/capture initialization structure.
Default configuration for TIMER DTI initialization structure.
Enumeration Documentation#
TIMER_CCMode_TypeDef#
TIMER_CCMode_TypeDef
Timer compare/capture mode.
Enumerator | |
---|---|
timerCCModeOff | Channel turned off. |
timerCCModeCapture | Input capture. |
timerCCModeCompare | Output compare. |
timerCCModePWM | Pulse-Width modulation. |
87
of file platform/emlib/inc/em_timer.h
TIMER_ClkSel_TypeDef#
TIMER_ClkSel_TypeDef
Clock select.
Enumerator | |
---|---|
timerClkSelHFPerClk | Prescaled EM01GRPA clock. |
timerClkSelCC1 | Compare/Capture Channel 1 Input. |
timerClkSelCascade | Cascaded clocked by underflow or overflow by lower numbered timer. |
103
of file platform/emlib/inc/em_timer.h
TIMER_Edge_TypeDef#
TIMER_Edge_TypeDef
Input capture edge select.
Enumerator | |
---|---|
timerEdgeRising | Rising edges detected. |
timerEdgeFalling | Falling edges detected. |
timerEdgeBoth | Both edges detected. |
timerEdgeNone | No edge detection, leave signal as is. |
117
of file platform/emlib/inc/em_timer.h
TIMER_Event_TypeDef#
TIMER_Event_TypeDef
Input capture event control.
Enumerator | |
---|---|
timerEventEveryEdge | PRS output pulse, interrupt flag, and DMA request set on every capture. |
timerEventEvery2ndEdge | PRS output pulse, interrupt flag, and DMA request set on every second capture. |
timerEventRising | PRS output pulse, interrupt flag, and DMA request set on rising edge (if input capture edge = BOTH). |
timerEventFalling | PRS output pulse, interrupt flag, and DMA request set on falling edge (if input capture edge = BOTH). |
132
of file platform/emlib/inc/em_timer.h
TIMER_InputAction_TypeDef#
TIMER_InputAction_TypeDef
Input edge action.
Enumerator | |
---|---|
timerInputActionNone | No action taken. |
timerInputActionStart | Start counter without reload. |
timerInputActionStop | Stop counter without reload. |
timerInputActionReloadStart | Reload and start counter. |
150
of file platform/emlib/inc/em_timer.h
TIMER_Mode_TypeDef#
TIMER_Mode_TypeDef
Timer mode.
Enumerator | |
---|---|
timerModeUp | Up-counting. |
timerModeDown | Down-counting. |
timerModeUpDown | Up/down-counting. |
timerModeQDec | Quadrature decoder. |
165
of file platform/emlib/inc/em_timer.h
TIMER_OutputAction_TypeDef#
TIMER_OutputAction_TypeDef
Compare/capture output action.
Enumerator | |
---|---|
timerOutputActionNone | No action. |
timerOutputActionToggle | Toggle on event. |
timerOutputActionClear | Clear on event. |
timerOutputActionSet | Set on event. |
181
of file platform/emlib/inc/em_timer.h
TIMER_Prescale_TypeDef#
TIMER_Prescale_TypeDef
Prescaler.
Enumerator | |
---|---|
timerPrescale1 | Divide by 1. |
timerPrescale2 | Divide by 2. |
timerPrescale4 | Divide by 4. |
timerPrescale8 | Divide by 8. |
timerPrescale16 | Divide by 16. |
timerPrescale32 | Divide by 32. |
timerPrescale64 | Divide by 64. |
timerPrescale128 | Divide by 128. |
timerPrescale256 | Divide by 256. |
timerPrescale512 | Divide by 512. |
timerPrescale1024 | Divide by 1024. |
196
of file platform/emlib/inc/em_timer.h
TIMER_PrsInput_TypeDef#
TIMER_PrsInput_TypeDef
PRS input type.
Enumerator | |
---|---|
timerPrsInputNone | No PRS input. |
timerPrsInputSync | Synchronous PRS selected. |
timerPrsInputAsyncLevel | Asynchronous level PRS selected. |
timerPrsInputAsyncPulse | Asynchronous pulse PRS selected. |
247
of file platform/emlib/inc/em_timer.h
TIMER_DtiFaultAction_TypeDef#
TIMER_DtiFaultAction_TypeDef
DT (Dead Time) Fault Actions.
Enumerator | |
---|---|
timerDtiFaultActionNone | No action on fault. |
timerDtiFaultActionInactive | Set outputs inactive. |
timerDtiFaultActionClear | Clear outputs. |
timerDtiFaultActionTristate | Tristate outputs. |
257
of file platform/emlib/inc/em_timer.h
TIMER_PrsOutput_t#
TIMER_PrsOutput_t
PRS Output configuration.
Enumerator | |
---|---|
timerPrsOutputPulse | Pulse PRS output from a channel. |
timerPrsOutputLevel | PRS output follows CC out level. |
timerPrsOutputDefault | Default PRS output behavior. |
391
of file platform/emlib/inc/em_timer.h
Typedef Documentation#
TIMER_PRSSEL_TypeDef#
typedef uint8_t TIMER_PRSSEL_TypeDef
Peripheral Reflex System signal.
226
of file platform/emlib/inc/em_timer.h
Function Documentation#
TIMER_Init#
void TIMER_Init (TIMER_TypeDef * timer, const TIMER_Init_TypeDef * init)
Initialize TIMER.
[in] | timer | A pointer to the TIMER peripheral register block. |
[in] | init | A pointer to the TIMER initialization structure. |
Notice that the counter top must be configured separately with, for instance TIMER_TopSet(). In addition, compare/capture and dead-time insertion initialization must be initialized separately if used, which should probably be done prior to using this function if configuring the TIMER to start when initialization is completed.
178
of file platform/emlib/src/em_timer.c
TIMER_InitCC#
void TIMER_InitCC (TIMER_TypeDef * timer, unsigned int ch, const TIMER_InitCC_TypeDef * init)
Initialize the TIMER compare/capture channel.
[in] | timer | A pointer to the TIMER peripheral register block. |
[in] | ch | A compare/capture channel to initialize for. |
[in] | init | A pointer to the TIMER initialization structure. |
Notice that if operating the channel in compare mode, the CCV and CCVB register must be set separately, as required.
264
of file platform/emlib/src/em_timer.c
TIMER_InitDTI#
void TIMER_InitDTI (TIMER_TypeDef * timer, const TIMER_InitDTI_TypeDef * init)
Initialize the TIMER DTI unit.
[in] | timer | A pointer to the TIMER peripheral register block. |
[in] | init | A pointer to the TIMER DTI initialization structure. |
331
of file platform/emlib/src/em_timer.c
TIMER_Reset#
void TIMER_Reset (TIMER_TypeDef * timer)
Reset the TIMER to the same state that it was in after a hardware reset.
[in] | timer | A pointer to the TIMER peripheral register block. |
Note
The ROUTE register is NOT reset by this function to allow for a centralized setup of this feature.
430
of file platform/emlib/src/em_timer.c
TIMER_SyncWait#
void TIMER_SyncWait (TIMER_TypeDef * timer)
Wait for pending synchronization to finish.
[in] | timer |
510
of file platform/emlib/src/em_timer.c
TIMER_Valid#
bool TIMER_Valid (const TIMER_TypeDef * ref)
Validate the TIMER register block pointer.
[in] | ref | Pointer to the TIMER peripheral register block. |
Returns
True if ref points to a valid timer, false otherwise.
590
of file platform/emlib/inc/em_timer.h
TIMER_SupportsDTI#
bool TIMER_SupportsDTI (const TIMER_TypeDef * ref)
Check whether the TIMER is valid and supports Dead Timer Insertion (DTI).
[in] | ref | Pointer to the TIMER peripheral register block. |
Returns
True if ref points to a valid timer that supports DTI, false otherwise.
645
of file platform/emlib/inc/em_timer.h
TIMER_MaxCount#
uint32_t TIMER_MaxCount (const TIMER_TypeDef * ref)
Get the Max count of the timer.
[in] | ref | Pointer to the TIMER peripheral register block. |
Returns
The max count value of the timer. This is 0xFFFF for 16 bit timers and 0xFFFFFFFF for 32 bit timers.
701
of file platform/emlib/inc/em_timer.h
TIMER_CaptureGet#
uint32_t TIMER_CaptureGet (TIMER_TypeDef * timer, unsigned int ch)
Get compare/capture value for the compare/capture channel.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | ch | Compare/capture channel to access. |
Returns
Current capture value.
743
of file platform/emlib/inc/em_timer.h
TIMER_CaptureBufGet#
uint32_t TIMER_CaptureBufGet (TIMER_TypeDef * timer, unsigned int ch)
Get the buffered compare/capture value for compare/capture channel.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | ch | Compare/capture channel to access. |
Returns
Current buffered capture value.
769
of file platform/emlib/inc/em_timer.h
TIMER_CompareBufSet#
void TIMER_CompareBufSet (TIMER_TypeDef * timer, unsigned int ch, uint32_t val)
Set the compare value buffer for the compare/capture channel when operating in compare or PWM mode.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | ch | Compare/capture channel to access. |
[in] | val | Value to set in compare value buffer register. |
The compare value buffer holds the value which will be written to TIMERn_CCx_CCV on an update event if the buffer has been updated since the last event.
801
of file platform/emlib/inc/em_timer.h
TIMER_CompareSet#
void TIMER_CompareSet (TIMER_TypeDef * timer, unsigned int ch, uint32_t val)
Set the compare value for compare/capture channel when operating in compare or PWM mode.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | ch | Compare/capture channel to access. |
[in] | val | Value to set in compare value register. |
828
of file platform/emlib/inc/em_timer.h
TIMER_CounterGet#
uint32_t TIMER_CounterGet (TIMER_TypeDef * timer)
Get the TIMER counter value.
[in] | timer | Pointer to TIMER peripheral register block. |
Returns
Current TIMER counter value.
851
of file platform/emlib/inc/em_timer.h
TIMER_CounterSet#
void TIMER_CounterSet (TIMER_TypeDef * timer, uint32_t val)
Set the TIMER counter value.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | val | Value to set counter to. |
866
of file platform/emlib/inc/em_timer.h
TIMER_Enable#
void TIMER_Enable (TIMER_TypeDef * timer, bool enable)
Start/stop TIMER.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | enable | Set to true to enable counting; set to false otherwise. |
896
of file platform/emlib/inc/em_timer.h
TIMER_EnableDTI#
void TIMER_EnableDTI (TIMER_TypeDef * timer, bool enable)
Enable or disable DTI unit.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | enable | Set to true to enable DTI unit; set to false otherwise. |
925
of file platform/emlib/inc/em_timer.h
TIMER_GetDTIFault#
uint32_t TIMER_GetDTIFault (TIMER_TypeDef * timer)
Get DTI fault source flags status.
[in] | timer | Pointer to the TIMER peripheral register block. |
Note
Event bits are not cleared by this function.
Returns
Status of the DTI fault source flags. Returns one or more valid DTI fault source flags (TIMER_DTFAULT_nnn) OR'ed together.
966
of file platform/emlib/inc/em_timer.h
TIMER_ClearDTIFault#
void TIMER_ClearDTIFault (TIMER_TypeDef * timer, uint32_t flags)
Clear DTI fault source flags.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | flags | DTI fault source(s) to clear. Use one or more valid DTI fault source flags (TIMER_DTFAULT_nnn) OR'ed together. |
983
of file platform/emlib/inc/em_timer.h
TIMER_IntClear#
void TIMER_IntClear (TIMER_TypeDef * timer, uint32_t flags)
Clear one or more pending TIMER interrupts.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | flags | Pending TIMER interrupt source(s) to clear. Use one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together. |
1006
of file platform/emlib/inc/em_timer.h
TIMER_IntDisable#
void TIMER_IntDisable (TIMER_TypeDef * timer, uint32_t flags)
Disable one or more TIMER interrupts.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | flags | TIMER interrupt source(s) to disable. Use one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together. |
1026
of file platform/emlib/inc/em_timer.h
TIMER_IntEnable#
void TIMER_IntEnable (TIMER_TypeDef * timer, uint32_t flags)
Enable one or more TIMER interrupts.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | flags | TIMER interrupt source(s) to enable. Use one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together. |
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using TIMER_IntClear() prior to enabling the interrupt.
1048
of file platform/emlib/inc/em_timer.h
TIMER_IntGet#
uint32_t TIMER_IntGet (TIMER_TypeDef * timer)
Get pending TIMER interrupt flags.
[in] | timer | Pointer to the TIMER peripheral register block. |
Note
Event bits are not cleared by this function.
Returns
TIMER interrupt source(s) pending. Returns one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
1067
of file platform/emlib/inc/em_timer.h
TIMER_IntGetEnabled#
uint32_t TIMER_IntGetEnabled (TIMER_TypeDef * timer)
Get enabled and pending TIMER interrupt flags.
[in] | timer | Pointer to the TIMER peripheral register block. |
Useful for handling more interrupt sources in the same interrupt handler.
Note
Interrupt flags are not cleared by this function.
Returns
Pending and enabled TIMER interrupt sources. The return value is the bitwise AND combination of
the OR combination of enabled interrupt sources in TIMERx_IEN_nnn register (TIMERx_IEN_nnn) and
the OR combination of valid interrupt flags of the TIMER module (TIMERx_IF_nnn).
1091
of file platform/emlib/inc/em_timer.h
TIMER_IntSet#
void TIMER_IntSet (TIMER_TypeDef * timer, uint32_t flags)
Set one or more pending TIMER interrupts from SW.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | flags | TIMER interrupt source(s) to set to pending. Use one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together. |
1114
of file platform/emlib/inc/em_timer.h
TIMER_TopBufSet#
void TIMER_TopBufSet (TIMER_TypeDef * timer, uint32_t val)
Set the top value buffer for the timer.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | val | Value to set in top value buffer register. |
When top value buffer register is updated, value is loaded into top value register at the next wrap around. This feature is useful in order to update top value safely when timer is running.
1167
of file platform/emlib/inc/em_timer.h
TIMER_TopGet#
uint32_t TIMER_TopGet (TIMER_TypeDef * timer)
Get the top value setting for the timer.
[in] | timer | Pointer to the TIMER peripheral register block. |
Returns
Current top value.
1187
of file platform/emlib/inc/em_timer.h
TIMER_TopSet#
void TIMER_TopSet (TIMER_TypeDef * timer, uint32_t val)
Set the top value for timer.
[in] | timer | Pointer to the TIMER peripheral register block. |
[in] | val | Value to set in top value register. |
1202
of file platform/emlib/inc/em_timer.h
Macro Definition Documentation#
TIMER_INIT_DEFAULT#
#define TIMER_INIT_DEFAULTValue:
Default configuration for TIMER initialization structure.
336
of file platform/emlib/inc/em_timer.h
TIMER_INITCC_DEFAULT#
#define TIMER_INITCC_DEFAULTValue:
Default configuration for TIMER compare/capture initialization structure.
456
of file platform/emlib/inc/em_timer.h
TIMER_INITDTI_DEFAULT#
#define TIMER_INITDTI_DEFAULTValue:
Default configuration for TIMER DTI initialization structure.
550
of file platform/emlib/inc/em_timer.h