modm API documentation
modm::platform::GeneralPurposeTimer Class Reference
Inheritance diagram for modm::platform::GeneralPurposeTimer:
modm::platform::BasicTimer modm::platform::AdvancedControlTimer modm::platform::Timer14 modm::platform::Timer15 modm::platform::Timer16 modm::platform::Timer17 modm::platform::Timer2 modm::platform::Timer3 modm::platform::Timer1

Public Typedefs

using Value = uint16_t
 

Public Types

enum  DmaRequestEnable : uint32_t {
  Update = TIM_DIER_UDE, CaptureCompare1 = TIM_DIER_CC1DE, CaptureCompare2 = TIM_DIER_CC2DE, CaptureCompare3 = TIM_DIER_CC3DE,
  CaptureCompare4 = TIM_DIER_CC4DE, COM = TIM_DIER_COMDE, Trigger = TIM_DIER_TDE
}
 
enum  Interrupt : uint32_t {
  Update = TIM_DIER_UIE, CaptureCompare1 = TIM_DIER_CC1IE, CaptureCompare2 = TIM_DIER_CC2IE, CaptureCompare3 = TIM_DIER_CC3IE,
  CaptureCompare4 = TIM_DIER_CC4IE, Trigger = TIM_DIER_TIE, COM = TIM_DIER_COMIE, Break = TIM_DIER_BIE
}
 
enum  InterruptFlag : uint32_t {
  Update = TIM_SR_UIF, CaptureCompare1 = TIM_SR_CC1IF, CaptureCompare2 = TIM_SR_CC2IF, CaptureCompare3 = TIM_SR_CC3IF,
  CaptureCompare4 = TIM_SR_CC4IF, Trigger = TIM_SR_TIF, Overcapture1 = TIM_SR_CC1OF, Overcapture2 = TIM_SR_CC2OF,
  Overcapture3 = TIM_SR_CC3OF, Overcapture4 = TIM_SR_CC4OF, COM = TIM_SR_COMIF, Break = TIM_SR_BIF
}
 
enum  SlaveModeTrigger : uint32_t
 
enum  SlaveMode : uint32_t { Disabled = 0, SlaveMode::Encoder1 = TIM_SMCR_SMS_0, SlaveMode::Encoder2 = TIM_SMCR_SMS_1, SlaveMode::Encoder3 = TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0 }
 
enum  Mode : uint32_t {
  UpCounter = 0, DownCounter = TIM_CR1_DIR, OneShotUpCounter = TIM_CR1_OPM, OneShotDownCounter = TIM_CR1_DIR | TIM_CR1_OPM,
  Mode::CenterAligned1 = TIM_CR1_CMS_0, Mode::CenterAligned2 = TIM_CR1_CMS_1, Mode::CenterAligned3 = TIM_CR1_CMS_1 | TIM_CR1_CMS_0
}
 
enum  OutputCompareMode : uint32_t {
  OutputCompareMode::Inactive = 0, OutputCompareMode::HighOnMatch = TIM_CCMR1_OC1M_0, OutputCompareMode::LowOnMatch = TIM_CCMR1_OC1M_1, OutputCompareMode::Toggle = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0,
  OutputCompareMode::ForceInactive = TIM_CCMR1_OC1M_2, OutputCompareMode::ForceActive = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0, OutputCompareMode::Pwm = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1, OutputCompareMode::Pwm2 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0
}
 
enum  OutputComparePreload : uint32_t { Disable = 0, Enable = TIM_CCMR1_OC1PE }
 
enum  OutputComparePolarity : uint32_t { ActiveHigh = 0, ActiveLow = TIM_CCER_CC1P }
 
enum  InputCaptureMapping : uint32_t { InputOwn = 1, InputOther = 2, InternalTrigger = 3 }
 
enum  InputCapturePolarity : uint32_t { Rising = 0, Falling = TIM_CCER_CC1P, Both = TIM_CCER_CC1NP | TIM_CCER_CC1P }
 
enum  InputCapturePrescaler : uint32_t { Div1 = 0, Div2 = 1, Div4 = 2, Div8 = 3 }
 
enum  PinState : uint32_t { Disable = 0, Enable = 1 }
 
enum  DeadTimeResolution : uint32_t { From0With125nsStep = 0, From16usWith250nsStep = TIM_BDTR_DTG_7, From32usWith1usStep = TIM_BDTR_DTG_7 | TIM_BDTR_DTG_6, From64usWith2usStep }
 
enum  OffStateForRunMode : uint32_t { Disable = 0, Enable = TIM_BDTR_OSSR }
 
enum  OffStateForIdleMode : uint32_t { Disable = 0, Enable = TIM_BDTR_OSSI }
 
enum  Event : uint32_t {
  Break2 = TIM_EGR_B2G, Break = TIM_EGR_BG, CaptureCompareControlUpdate = TIM_EGR_COMG, Trigger = TIM_EGR_TG,
  CaptureCompare4 = TIM_EGR_CC4G, CaptureCompare3 = TIM_EGR_CC3G, CaptureCompare2 = TIM_EGR_CC2G, CaptureCompare1 = TIM_EGR_CC1G,
  Update = TIM_EGR_UG
}
 

Public Member Functions

 MODM_FLAGS32 (Interrupt)
 
 MODM_FLAGS32 (InterruptFlag)
 
 MODM_FLAGS32 (OutputCompareMode)
 
 MODM_FLAGS32 (Interrupt)
 
 MODM_FLAGS32 (InterruptFlag)
 

Static Public Member Functions

static void setMode (Mode mode, SlaveMode slaveMode=SlaveMode::Disabled, SlaveModeTrigger slaveModeTrigger=(SlaveModeTrigger) 0)
 
static void configureInputChannel (uint32_t channel, InputCaptureMapping input, InputCapturePrescaler prescaler, InputCapturePolarity polarity, uint8_t filter)
 
static void configureOutputChannel (uint32_t channel, OutputCompareMode_t mode, uint16_t compareValue)
 
static void setCompareValue (uint32_t channel, uint16_t value)
 
static uint16_t getCompareValue (uint32_t channel)
 
template<typename Signal >
static consteval bool isComplementaryChannel ()
 
static void acknowledgeInterruptFlags (InterruptFlag_t flags)
 
static void applyAndReset ()
 Reset the counter, and update the prescaler and overflow values. More...
 
static void disable ()
 
static void disableInterrupt (Interrupt_t interrupt)
 
static void enable ()
 
static void enableInterrupt (Interrupt_t interrupt)
 
static void enableInterruptVector (bool enable, uint8_t priority)
 
static InterruptFlag_t getInterruptFlags ()
 
static Value getOverflow ()
 
static uint16_t getPrescaler ()
 
static Value getValue ()
 
static constexpr bool hasAdvancedPwmControl ()
 
static bool isCountingDown ()
 
static bool isCountingUp ()
 
static bool isEnabled ()
 
static void pause ()
 
static void setMode (Mode mode)
 
static void setOverflow (Value overflow)
 
template<class Rep , class Period >
static Value setPeriod (std::chrono::duration< Rep, Period > duration, bool autoApply=true)
 
static void setPrescaler (uint16_t prescaler)
 
static void setValue (Value value)
 
static void start ()
 

Static Protected Member Functions

template<Peripheral p, typename Signal >
static consteval int signalToChannel ()
 

Member Enumeration Documentation

If more than one Compare Channel is available they are always paired. (A channel with an odd number is paired with the next even numbered channel) It is possible to choose as trigger for the input capture functionality either the own timer input or the input associated with the paired channel.

For working with Internal Triggers, TRC can also be selected.

Enum ValuesDocumentation
CenterAligned1 

Output compare flags only set when counting down.

CenterAligned2 

Output compare flags only set when counting up.

CenterAligned3 

Output compare flags set when counting up and down (default)

Enum ValuesDocumentation
Inactive 

Output is independent from the compare result.

HighOnMatch 

Output is forced high on match.

LowOnMatch 

Output is forced low on match.

Toggle 

Output is toggled on match.

ForceInactive 

Output is forced low.

ForceActive 

Output is forced high.

Pwm 

PWM Mode 1.

While up-counting, channel is active as long as count is less than channel capture/compare register, else inactive. In downcounting, channel is inactive as long as count exceeds capture/compare register, else active

Pwm2 

PWM mode 2.

In upcounting, channel is inactive as long as count is less than capture/compare register, else active. In downcounting, channel is active as long as count exceeds capture/compare register, else inactive.

Enum ValuesDocumentation
Encoder1 

Counter counts up/down on TI2FP2 edge depending on TI1FP1 level.

Encoder2 

Counter counts up/down on TI1FP1 edge depending on TI2FP2 level.

Encoder3 

Counter counts up/down on both TI1FP1 and TI2FP2 edges depending on the level of the other input.

Member Function Documentation

static void modm::platform::BasicTimer::acknowledgeInterruptFlags ( InterruptFlag_t  flags)
inheritedstatic

Clears one or multiple flags.

Parameters
flagsBitmap of StateFlag
static void modm::platform::BasicTimer::applyAndReset ( )
inheritedinlinestatic

Reset the counter, and update the prescaler and overflow values.

Generates an Update-Event without generating an Update-Interrupt.

This will reset the counter to 0 in up-counting mode (the default) or to the maximal value in down-counting mode. It will also update the timer's prescaler and overflow values if you have set them up to be changed using setPrescaler() or setOverflow() (or setPeriod()).

An Update-Event is also generated when the timer reaches its maximal (up-counting) or minimal (down-counting) value. The settings for Prescaler, Overflow and Compare values are applied then without calling this function.

static void modm::platform::GeneralPurposeTimer::configureInputChannel ( uint32_t  channel,
InputCaptureMapping  input,
InputCapturePrescaler  prescaler,
InputCapturePolarity  polarity,
uint8_t  filter 
)
static

TODO Description

static void modm::platform::GeneralPurposeTimer::configureOutputChannel ( uint32_t  channel,
OutputCompareMode_t  mode,
uint16_t  compareValue 
)
static

Configure output channel 1..4.

Parameters
channel[1..4]
modeOutput compare mode
compareValuePreloaded output compare value (can be changed later via setCompareValue())
static void modm::platform::BasicTimer::disable ( )
inheritedstatic

Disable clock.

All settings are ignored in this mode and the timer is shut down. Calling any function other than enable() won't have any effect.

static void modm::platform::BasicTimer::disableInterrupt ( Interrupt_t  interrupt)
inheritedstatic

Disables interrupts.

Parameters
interruptInterrupts to disable
static void modm::platform::BasicTimer::enable ( )
inheritedstatic

Enables the clock for the timer and resets all settings

Has to be called before calling any other function from this class! Otherwise the settings won't have any effect.

static void modm::platform::BasicTimer::enableInterrupt ( Interrupt_t  interrupt)
inheritedstatic

Enables interrupts. Don't forget to enable the Interrupt Vector.

Parameters
interruptInterrupts to enable
See also
enableInterruptVector()
static void modm::platform::BasicTimer::enableInterruptVector ( bool  enable,
uint8_t  priority 
)
inheritedstatic

Enables or disables the Interrupt Vector.

Parameters
enableEnable/disable the interrupt vector
priorityPriority of the interrupt vector (0=highest to 15=lowest).
static uint16_t modm::platform::GeneralPurposeTimer::getCompareValue ( uint32_t  channel)
static

Read compare value for channel 1..4.

Parameters
channel[1..4]
Returns
Current compare value
static InterruptFlag_t modm::platform::BasicTimer::getInterruptFlags ( )
inheritedstatic

Returns a bitmap of the enum StateFlag. Use this method while executing an interrupt or in other situations where you want to know which of the flags are set.

If a flag is a cause of an enabled interrupt (and the Interrupt Vector is enabled) then interrupt will be triggered as long the flag is set.

Warning
You cannot use a switch statement for the returned value, since multiple flags may be set!
InterruptFlag flags = TimerX::getInterruptFlags()
if (flags & TimerX::FLAG_XX){
// Flag was set, clear the flag since flags are set by
// hardware, but have to be cleared by software
TimerX::resetInterruptFlags(TIMx::FLAG_XX)
}
static Value modm::platform::BasicTimer::getOverflow ( )
inheritedinlinestatic

Get current overflow

static uint16_t modm::platform::BasicTimer::getPrescaler ( )
inheritedinlinestatic

Get current prescaler

static Value modm::platform::BasicTimer::getValue ( )
inheritedinlinestatic

Get the counter value

static constexpr bool modm::platform::BasicTimer::hasAdvancedPwmControl ( )
inheritedstaticconstexpr

Allows to check, whether the timer has BDTR and DTR2 registers for PWM deadtime, break and output enable control.

static bool modm::platform::BasicTimer::isCountingUp ( )
inheritedinlinestatic

Check current count direction

static bool modm::platform::BasicTimer::isEnabled ( )
inheritedstatic

Check, whether clock has been enabled.

static void modm::platform::BasicTimer::pause ( )
inheritedstatic

Pause timer operation

All settings are stored but the timer operation is suspend until start() is called.

static void modm::platform::GeneralPurposeTimer::setCompareValue ( uint32_t  channel,
uint16_t  value 
)
static

Set compare value for channel 1..4.

Parameters
channel[1..4]
valueCompare value
static void modm::platform::BasicTimer::setMode ( Mode  mode)
inheritedstatic

Set operation mode of the timer

static void modm::platform::GeneralPurposeTimer::setMode ( Mode  mode,
SlaveMode  slaveMode = SlaveMode::Disabled,
SlaveModeTrigger  slaveModeTrigger = (SlaveModeTrigger) 0 
)
static

Set operation mode of the timer

In Encoder mode the encoder channels A and B must be connected to channel 1 and 2 of the timer (e.g. TIM2_CH1 and TIM2_CH2).

static void modm::platform::BasicTimer::setOverflow ( Value  overflow)
inheritedinlinestatic

Set overflow.

This sets the maximum counter value of the timer. The timer is blocked if overflow is set to zero.

Takes effect at next update event.

See also
applyAndReset()
template<class Rep , class Period >
static Value modm::platform::BasicTimer::setPeriod ( std::chrono::duration< Rep, Period >  duration,
bool  autoApply = true 
)
inheritedstatic

Set Timer period

Changes prescaler and overflow values. Takes effect at next update event.

Parameters
durationRequested duration of period
autoApplyUpdate the new value immediately and reset the counter value.
Returns
New overflow value.
See also
applyAndReset()
static void modm::platform::BasicTimer::setPrescaler ( uint16_t  prescaler)
inheritedinlinestatic

Set new prescaler

The prescaler can divide the counter clock frequency by any factor between 1 and 65'536. The new prescaler ratio is taken into account at the next update event.

See also
applyAndReset()
static void modm::platform::BasicTimer::setValue ( Value  value)
inheritedinlinestatic

Set a new counter value

static void modm::platform::BasicTimer::start ( )
inheritedstatic

Re-enable timer operations

Has to called after the initial configuration to start timer or after pause() to restart the timer.


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