Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::TimerUtils Namespace Reference

Timer utilities. More...

Enumerations

enum class  TriggerSource : uint16_t {
  ITR0 = 0 , ITR1 = TIM_SMCR_TS_0 , ITR2 = TIM_SMCR_TS_1 , ITR3 = TIM_SMCR_TS_1 | TIM_SMCR_TS_0 ,
  TI1F_ED = TIM_SMCR_TS_2 , TI1FP1 = TIM_SMCR_TS_2 | TIM_SMCR_TS_0 , TI2FP2 = TIM_SMCR_TS_2 | TIM_SMCR_TS_1
}
 Trigger sources. More...
 
enum class  MasterMode : uint32_t {
  RESET = 0 , ENABLE = TIM_CR2_MMS_0 , UPDATE = TIM_CR2_MMS_1 , COMPARE_PULSE = TIM_CR2_MMS_1 | TIM_CR2_MMS_0 ,
  OC1REF_OUTPUT = TIM_CR2_MMS_2 , OC2REF_OUTPUT = TIM_CR2_MMS_2 | TIM_CR2_MMS_0 , OC3REF_OUTPUT = TIM_CR2_MMS_2 | TIM_CR2_MMS_1 , OC4REF_OUTPUT = TIM_CR2_MMS
}
 
enum class  SlaveMode : uint16_t {
  DISABLED = 0 , RESET_MODE = TIM_SMCR_SMS_2 , GATED_MODE = TIM_SMCR_SMS_2 | TIM_SMCR_SMS_0 , TRIGGER_MODE = TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1 ,
  EXTERNAL_CLOCK_MODE_1 = TIM_SMCR_SMS_0 | TIM_SMCR_SMS_1 | TIM_SMCR_SMS_2
}
 
enum class  OutputCompareMode : uint16_t {
  FROZEN = 0 , ACTIVE_ON_MATCH = 0x1 , INACTIVE_ON_MATCH = 0x2 , TOGGLE = 0x3 ,
  FORCE_INACTIVE = 0x4 , FORCE_ACTIVE = 0x5 , PWM_MODE_1 = 0x6 , PWM_MODE_2 = 0x7
}
 
enum class  OutputComparePolarity : uint16_t { ACTIVE_HIGH = 0 , ACTIVE_LOW = 0x1 }
 
enum class  Channel : uint8_t { CHANNEL_1 = 0 , CHANNEL_2 = 1 , CHANNEL_3 = 2 , CHANNEL_4 = 3 }
 

Functions

ClockUtils::APB getTimerInputClock (const TIM_TypeDef *timer)
 Returns the timer input clock.
 
uint32_t getPrescalerInputFrequency (const TIM_TypeDef *timer)
 Returns the timer clock frequency before the prescaler.
 
uint32_t getFrequency (TIM_TypeDef *timer)
 Return the timer clock frequency.
 
float toMicroSeconds (TIM_TypeDef *timer, uint32_t value)
 Returns the specified value converted in microseconds based on the timer clock frequency and prescaler.
 
float toMicroSeconds (TIM_TypeDef *timer)
 Returns the timer counter converted in microseconds based on the timer clock frequency and prescaler.
 
uint64_t toIntMicroSeconds (TIM_TypeDef *timer, uint32_t value)
 Returns the specified value converted in microseconds based on the timer clock frequency and prescaler.
 
uint64_t toIntMicroSeconds (TIM_TypeDef *timer)
 Returns the timer counter converted in microseconds based on the timer clock frequency and prescaler.
 
float toMilliSeconds (TIM_TypeDef *timer, uint32_t value)
 Returns the specified value converted in milliseconds based on the timer clock frequency and prescaler.
 
float toMilliSeconds (TIM_TypeDef *timer)
 Returns the timer counter converted in milliseconds based on the timer clock frequency and prescaler.
 
float toSeconds (TIM_TypeDef *timer)
 Returns the timer counter converted in seconds based on the timer clock frequency and prescaler.
 
float getResolution (TIM_TypeDef *timer)
 Computes the timer resolution in microseconds.
 
float getMaxDuration (TIM_TypeDef *timer)
 Computes the number of seconds for timer reset.
 
uint16_t computePrescalerValue (TIM_TypeDef *timer, int targetFrequency)
 Compute the prescaler value for the specified target frequency.
 
MasterMode masterModeFromChannel (const Channel channel)
 Returns the corresponding master for for the given channel.
 

Detailed Description

Timer utilities.

Enumeration Type Documentation

◆ Channel

enum class Boardcore::TimerUtils::Channel : uint8_t
strong
Enumerator
CHANNEL_1 
CHANNEL_2 
CHANNEL_3 
CHANNEL_4 

Definition at line 246 of file TimerUtils.h.

◆ MasterMode

enum class Boardcore::TimerUtils::MasterMode : uint32_t
strong
Enumerator
RESET 

Only the updateGeneration() function is used as trigger output.

ENABLE 

Only the timer enable is used as trigger output.

This is useful to start several timers at the same time.

UPDATE 

The UEV is selected as trigger output.

This is useful when one timer is used as a prescaler for another timer.

COMPARE_PULSE 

The trigger output send a positive pulse when the OC1IF flag is to be set (even if it was already high), as soon as a capture or a compare match occurred.

OC1REF_OUTPUT 

OC1REF signal is used as trigger output (TRGO).

OC2REF_OUTPUT 

OC2REF signal is used as trigger output (TRGO).

OC3REF_OUTPUT 

OC3REF signal is used as trigger output (TRGO).

OC4REF_OUTPUT 

OC4REF signal is used as trigger output (TRGO).

Definition at line 97 of file TimerUtils.h.

◆ OutputCompareMode

enum class Boardcore::TimerUtils::OutputCompareMode : uint16_t
strong
Enumerator
FROZEN 

The comparison between the output compare register and the counter has no effect on the outputs.

ACTIVE_ON_MATCH 

Set channel to active level on match.

INACTIVE_ON_MATCH 

Set channel to inactive level on match.

TOGGLE 

The output toggles when the output compare register and the counter match.

FORCE_INACTIVE 

Output is forced low.

FORCE_ACTIVE 

Output is forced high.

PWM_MODE_1 

Output is active as long as the counter is smaller than the compare register (reverse when downcounting).

PWM_MODE_2 

Output is active as long as the counter is greater than the compare register (reverse when downcounting).

Definition at line 193 of file TimerUtils.h.

◆ OutputComparePolarity

enum class Boardcore::TimerUtils::OutputComparePolarity : uint16_t
strong
Enumerator
ACTIVE_HIGH 
ACTIVE_LOW 

Definition at line 240 of file TimerUtils.h.

◆ SlaveMode

enum class Boardcore::TimerUtils::SlaveMode : uint16_t
strong
Enumerator
DISABLED 

Slave mode disabled.

The clock is only enabled by software.

RESET_MODE 

Reset mode.

Rising edge of the selected trigger input (TRGI) reinitialize the counter and generates an update of the registers.

GATED_MODE 

Gated mode.

The counter clock is enabled when the trigger input (TRGI) is high. The counter stops (but is not reset) as soon as the trigger becomes low. Counter starts and stops are both controlled.

Note: The gated mode must not be used if TI1F_ED is selected as the trigger input.

TRIGGER_MODE 

Trigger mode.

The counter starts on a rising edge of the trigger TRGI (but it is not reset). Only the start of the counter is controlled.

EXTERNAL_CLOCK_MODE_1 

External clock mode 1.

Rising edges of the selected trigger (TRGI) clock the counter

Definition at line 148 of file TimerUtils.h.

◆ TriggerSource

enum class Boardcore::TimerUtils::TriggerSource : uint16_t
strong

Trigger sources.

Here a quick recap of the internal trigger sources:

  ITR0  ITR1  ITR2  ITR3

TIM1 TIM5 TIM2 TIM3 TIM4 TIM2 TIM1 TIM8 TIM3 TIM4 TIM3 TIM1 TIM2 TIM5 TIM4 TIM4 TIM1 TIM2 TIM3 TIM8 TIM5 TIM2 TIM3 TIM4 TIM8 TIM6 -— -— -— -— TIM7 -— -— -— -— TIM8 TIM1 TIM2 TIM4 TIM5 TIM9 TIM2 TIM3 TIM10 TIM11 TIM10 -— -— -— -— TIM11 -— -— -— -— TIM12 TIM4 TIM5 TIM13 TIM14 TIM13 -— -— -— -— TIM14 -— -— -— -—

Enumerator
ITR0 

Internal trigger 0.

ITR1 

Internal trigger 1.

ITR2 

Internal trigger 2.

ITR3 

Internal trigger 3.

TI1F_ED 

TI1 edge detector.

TI1FP1 

Filtered timer input 1.

TI2FP2 

Filtered timer input 2.

Definition at line 59 of file TimerUtils.h.

Function Documentation

◆ computePrescalerValue()

uint16_t Boardcore::TimerUtils::computePrescalerValue ( TIM_TypeDef * timer,
int targetFrequency )
inline

Compute the prescaler value for the specified target frequency.

If the target frequency is above the prescaler input frequency, the returned value will be 0 which is the maximum.

Returns
Prescaler value for the target frequency.

Definition at line 448 of file TimerUtils.h.

◆ getFrequency()

uint32_t Boardcore::TimerUtils::getFrequency ( TIM_TypeDef * timer)
inline

Return the timer clock frequency.

Parameters
timerTimer to use.
Returns
Timer frequency.

Definition at line 392 of file TimerUtils.h.

◆ getMaxDuration()

float Boardcore::TimerUtils::getMaxDuration ( TIM_TypeDef * timer)
inline

Computes the number of seconds for timer reset.

Returns
Timer duration before counter reset in seconds.

Definition at line 442 of file TimerUtils.h.

◆ getPrescalerInputFrequency()

uint32_t Boardcore::TimerUtils::getPrescalerInputFrequency ( const TIM_TypeDef * timer)
inline

Returns the timer clock frequency before the prescaler.

Class borrowed from the SynchronizedServo class in Miosix.

Parameters
timerTimer to use.
Returns
Prescaler input frequency.

Definition at line 387 of file TimerUtils.h.

◆ getResolution()

float Boardcore::TimerUtils::getResolution ( TIM_TypeDef * timer)
inline

Computes the timer resolution in microseconds.

Returns
Microseconds per timer tick.

Definition at line 437 of file TimerUtils.h.

◆ getTimerInputClock()

ClockUtils::APB Boardcore::TimerUtils::getTimerInputClock ( const TIM_TypeDef * timer)
inline

Returns the timer input clock.

Returns
Timer input clock, APB1 or ABP2.

Definition at line 370 of file TimerUtils.h.

◆ masterModeFromChannel()

TimerUtils::MasterMode Boardcore::TimerUtils::masterModeFromChannel ( const Channel channel)
inline

Returns the corresponding master for for the given channel.

Definition at line 456 of file TimerUtils.h.

◆ toIntMicroSeconds() [1/2]

uint64_t Boardcore::TimerUtils::toIntMicroSeconds ( TIM_TypeDef * timer)
inline

Returns the timer counter converted in microseconds based on the timer clock frequency and prescaler.

Calculation using integer values.

Returns
Timer counter in microseconds.

Definition at line 415 of file TimerUtils.h.

◆ toIntMicroSeconds() [2/2]

uint64_t Boardcore::TimerUtils::toIntMicroSeconds ( TIM_TypeDef * timer,
uint32_t value )
inline

Returns the specified value converted in microseconds based on the timer clock frequency and prescaler.

Calculation using integer values.

Returns
Timer counter in microseconds.

Definition at line 408 of file TimerUtils.h.

◆ toMicroSeconds() [1/2]

float Boardcore::TimerUtils::toMicroSeconds ( TIM_TypeDef * timer)
inline

Returns the timer counter converted in microseconds based on the timer clock frequency and prescaler.

Returns
Timer counter in microseconds.

Definition at line 403 of file TimerUtils.h.

◆ toMicroSeconds() [2/2]

float Boardcore::TimerUtils::toMicroSeconds ( TIM_TypeDef * timer,
uint32_t value )
inline

Returns the specified value converted in microseconds based on the timer clock frequency and prescaler.

Returns
Timer counter in microseconds.

Definition at line 397 of file TimerUtils.h.

◆ toMilliSeconds() [1/2]

float Boardcore::TimerUtils::toMilliSeconds ( TIM_TypeDef * timer)
inline

Returns the timer counter converted in milliseconds based on the timer clock frequency and prescaler.

Returns
Timer counter in milliseconds.

Definition at line 426 of file TimerUtils.h.

◆ toMilliSeconds() [2/2]

float Boardcore::TimerUtils::toMilliSeconds ( TIM_TypeDef * timer,
uint32_t value )
inline

Returns the specified value converted in milliseconds based on the timer clock frequency and prescaler.

Returns
Timer counter in milliseconds.

Definition at line 420 of file TimerUtils.h.

◆ toSeconds()

float Boardcore::TimerUtils::toSeconds ( TIM_TypeDef * timer)
inline

Returns the timer counter converted in seconds based on the timer clock frequency and prescaler.

Returns
Timer counter in seconds.

Definition at line 431 of file TimerUtils.h.