modm API documentation
modm::platform::Timer1 Class Reference

Advanced Control Timer 1. More...

#include <modm/platform/timer/timer_1.hpp>

Inheritance diagram for modm::platform::Timer1:
modm::platform::AdvancedControlTimer modm::platform::GeneralPurposeTimer modm::platform::BasicTimer

Public Typedefs

using Value = uint16_t
 

Public Types

enum  BreakInputPolarity : uint32_t { ActiveLow = 0, ActiveHigh = 1 }
 
enum  CaptureCompareControlUpdate : uint32_t { CaptureCompareControlUpdate::SetComg = 0, CaptureCompareControlUpdate::SetComgOrRisingTrigEdge = TIM_CR2_CCUS }
 
enum  DeadTimeResolution : uint32_t { From0With125nsStep = 0, From16usWith250nsStep = TIM_BDTR_DTG_7, From32usWith1usStep = TIM_BDTR_DTG_7 | TIM_BDTR_DTG_6, From64usWith2usStep }
 
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  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
}
 
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  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  MasterMode : uint32_t {
  Reset = 0, Enable = TIM_CR2_MMS_0, Update = TIM_CR2_MMS_1, ComparePulse = TIM_CR2_MMS_1 | TIM_CR2_MMS_0,
  CompareOc1Ref = TIM_CR2_MMS_2, CompareOc2Ref = TIM_CR2_MMS_2 | TIM_CR2_MMS_0, CompareOc3Ref = TIM_CR2_MMS_2 | TIM_CR2_MMS_1, CompareOc4Ref
}
 
enum  MasterMode2 : uint32_t {
  Reset = 0, Enable = TIM_CR2_MMS2_0, Update = TIM_CR2_MMS2_1, ComparePulse,
  CompareOc1Ref = TIM_CR2_MMS2_2, CompareOc2Ref, CompareOc3Ref, CompareOc4Ref,
  CompareOc5RefF = TIM_CR2_MMS2_3, CompareOc6Ref
}
 
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  OffStateForIdleMode : uint32_t { Disable = 0, Enable = TIM_BDTR_OSSI }
 
enum  OffStateForRunMode : uint32_t { Disable = 0, Enable = TIM_BDTR_OSSR }
 
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  OutputComparePolarity : uint32_t { ActiveHigh = 0, ActiveLow = TIM_CCER_CC1P }
 
enum  OutputComparePreload : uint32_t { Disable = 0, Enable = TIM_CCMR1_OC1PE }
 
enum  OutputIdleState : uint32_t { Reset = 0, Set = TIM_CR2_OIS1 }
 
enum  PinState : uint32_t { Disable = 0, Enable = 1 }
 
enum  SlaveMode : uint32_t {
  SlaveMode::Disabled = 0, SlaveMode::Encoder1 = TIM_SMCR_SMS_0, SlaveMode::Encoder2 = TIM_SMCR_SMS_1, SlaveMode::Encoder3 = TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0,
  SlaveMode::Reset = TIM_SMCR_SMS_2, SlaveMode::Gated = TIM_SMCR_SMS_2 | TIM_SMCR_SMS_0, SlaveMode::Trigger = TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1, SlaveMode::ExternalClock = TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0
}
 
enum  SlaveModeTrigger : uint32_t {
  Internal0 = 0, Internal1 = TIM_SMCR_TS_0, Internal2 = TIM_SMCR_TS_1, Internal3 = TIM_SMCR_TS_1 | TIM_SMCR_TS_0,
  TimerInput1EdgeDetector = TIM_SMCR_TS_2, TimerInput1Filtered = TIM_SMCR_TS_2 | TIM_SMCR_TS_0, TimerInput2Filtered = TIM_SMCR_TS_2 | TIM_SMCR_TS_1, External = TIM_SMCR_TS_2 | TIM_SMCR_TS_1 | TIM_SMCR_TS_0
}
 

Public Member Functions

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

Static Public Member Functions

template<class... Signals>
static void connect ()
 
static void enable ()
 
static void disable ()
 
static bool isEnabled ()
 
static void pause ()
 
static void start ()
 
static void setMode (Mode mode, SlaveMode slaveMode=SlaveMode::Disabled, SlaveModeTrigger slaveModeTrigger=SlaveModeTrigger::Internal0, MasterMode masterMode=MasterMode::Reset, bool enableOnePulseMode=false, MasterMode2 masterMode2=MasterMode2::Reset)
 
static void setCaptureCompareControlUpdate (CaptureCompareControlUpdate update)
 
static void enableCaptureComparePreloadedControl (CaptureCompareControlUpdate update=CaptureCompareControlUpdate::SetComg)
 
static void disableCaptureComparePreloadedControl ()
 
static void setPrescaler (uint16_t prescaler)
 
static uint16_t getPrescaler ()
 
static void setOverflow (Value overflow)
 
static Value getOverflow ()
 
template<class SystemClock >
static constexpr uint32_t getClockFrequency ()
 
template<class SystemClock , class Rep , class Period >
static Value setPeriod (std::chrono::duration< Rep, Period > duration, bool autoApply=true)
 
static void generateEvent (Event ev)
 
static void applyAndReset ()
 
static Value getValue ()
 
static void setValue (Value value)
 
static constexpr bool hasAdvancedPwmControl ()
 
static bool isCountingUp ()
 
static bool isCountingDown ()
 
static void enableOutput ()
 
static void disableOutput ()
 
static bool isOutputEnabled ()
 
static void enableBreak ()
 
static void disableBreak ()
 
static void enableBreakInput ()
 
static void disableBreakInput ()
 
static void setBreakPolarity (BreakInputPolarity polarity)
 
static void setAutomaticUpdate (bool enable)
 
static void setOffState (OffStateForRunMode runMode, OffStateForIdleMode idleMode)
 
static void setOutputIdleState (uint32_t channel, OutputIdleState idle, OutputIdleState idle_n=OutputIdleState::Reset)
 
template<typename Signal >
static void setOutputIdleState (OutputIdleState idle, OutputIdleState idle_n=OutputIdleState::Reset)
 
static void setDeadTime (uint8_t deadTime)
 
static void setDeadTime (DeadTimeResolution resolution, uint8_t deadTime)
 
static void setRepetitionCount (uint16_t repetitionCount)
 
static void configureInputChannel (uint32_t channel, uint8_t filter)
 
template<typename Signal >
static void configureInputChannel (uint8_t filter)
 
static void configureInputChannel (uint32_t channel, InputCaptureMapping input, InputCapturePrescaler prescaler, InputCapturePolarity polarity, uint8_t filter, bool xor_ch1_3=false)
 
template<typename Signal >
static void configureInputChannel (InputCaptureMapping input, InputCapturePrescaler prescaler, InputCapturePolarity polarity, uint8_t filter, bool xor_ch1_3=false)
 
static void configureOutputChannel (uint32_t channel, OutputCompareMode mode, Value compareValue, PinState out=PinState::Enable)
 
template<typename Signal >
static void configureOutputChannel (OutputCompareMode mode, Value compareValue, PinState out=PinState::Enable)
 
static void configureOutputChannel (uint32_t channel, OutputCompareMode mode, Value compareValue, PinState out, OutputComparePolarity polarity, PinState out_n, OutputComparePolarity polarity_n=OutputComparePolarity::ActiveHigh, OutputComparePreload preload=OutputComparePreload::Disable)
 
template<typename Signal >
static void configureOutputChannel (OutputCompareMode mode, Value compareValue, PinState out, OutputComparePolarity polarity, PinState out_n, OutputComparePolarity polarity_n=OutputComparePolarity::ActiveHigh, OutputComparePreload preload=OutputComparePreload::Disable)
 
static void configureOutputChannel (uint32_t channel, OutputCompareMode mode, PinState out, OutputComparePolarity polarity, PinState out_n, OutputComparePolarity polarity_n=OutputComparePolarity::ActiveHigh, OutputComparePreload preload=OutputComparePreload::Disable)
 
template<typename Signal >
static void configureOutputChannel (OutputCompareMode mode, PinState out, OutputComparePolarity polarity, PinState out_n, OutputComparePolarity polarity_n=OutputComparePolarity::ActiveHigh, OutputComparePreload preload=OutputComparePreload::Disable)
 
static void configureOutputChannel (uint32_t channel, uint32_t modeOutputPorts)
 
template<typename Signal >
static void configureOutputChannel (uint32_t modeOutputPorts)
 
static void setCompareValue (uint32_t channel, Value value)
 
template<typename Signal >
static void setCompareValue (Value value)
 
static Value getCompareValue (uint32_t channel)
 
template<typename Signal >
static Value getCompareValue ()
 
static void enableInterruptVector (Interrupt interrupt, bool enable, uint32_t priority)
 
static void enableInterrupt (Interrupt interrupt)
 
static void disableInterrupt (Interrupt interrupt)
 
static void enableDmaRequest (DmaRequestEnable dmaRequests)
 
static void disableDmaRequest (DmaRequestEnable dmaRequests)
 
static InterruptFlag getInterruptFlags ()
 
static void acknowledgeInterruptFlags (InterruptFlag flags)
 
static void acknowledgeInterruptFlags (InterruptFlag_t flags)
 
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 disableInterrupt (Interrupt_t interrupt)
 
static void enableInterrupt (Interrupt_t interrupt)
 
static void enableInterruptVector (bool enable, uint8_t priority)
 
template<typename Signal >
static consteval bool isComplementaryChannel ()
 
static void setMode (Mode mode, SlaveMode slaveMode=SlaveMode::Disabled, SlaveModeTrigger slaveModeTrigger=(SlaveModeTrigger) 0)
 
static void setMode (Mode mode)
 

Static Protected Member Functions

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

Detailed Description

Advanced Control Timer 1.

Interrupt handler (for LD, MD, HD and CL):

  • TIM1_BRK
  • TIM1_UP
  • TIM1_TRG_COM
  • TIM1_CC

Interrupt handler for XL Density:

  • TIM1_BRK_TIM9
  • TIM1_UP_TIM10
  • TIM1_TRG_COM_TIM11
  • TIM1_CC

Example:

MODM_ISR(TIM1_UP)
{
Timer1::resetInterruptFlags(Timer1::...);
...
}
Warning
The Timer has much more possibilities than presented by this interface (e.g. Input Capture, Trigger for other Timers, DMA). It might be expanded in the future.
Author
Fabian Greif
Kevin Laeufer

Member Enumeration Documentation

If capture compare control bit preloading is enabled (CCPC=1), this selects how to update them.

Enum ValuesDocumentation
SetComg 

Update by setting COMG bit.

SetComgOrRisingTrigEdge 

Update by setting COMG bit or when a rising edge occures on the trigger input.

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 modm::platform::GeneralPurposeTimer::Mode : uint32_t
inheritedstrong
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 modm::platform::AdvancedControlTimer::SlaveMode : uint32_t
inheritedstrong
Enum ValuesDocumentation
Disabled 

Slave mode disabled - if CEN = '1' then the prescaler is clocked directly by the internal clock.

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.

Reset 

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

Gated 

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. Both start and stop of the counter are controlled.

Trigger 

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

ExternalClock 

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

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::GeneralPurposeTimer::configureInputChannel ( uint32_t  channel,
InputCaptureMapping  input,
InputCapturePrescaler  prescaler,
InputCapturePolarity  polarity,
uint8_t  filter 
)
inheritedstatic

TODO Description

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

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::disableInterrupt ( Interrupt_t  interrupt)
inheritedstatic

Disables interrupts.

Parameters
interruptInterrupts to disable
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).
void modm::platform::Timer1::enableInterruptVector ( Interrupt  interrupt,
bool  enable,
uint32_t  priority 
)
static

Enables or disables Interrupt Vectors.

You must pass an or-conjuncted list of entries from the Interrupt enum. Interrupt vectors which fit to will be enabled (or disabled if enable = false).

The Adanvced timers have four interrupt vectors:

  • UP (used by INTERRUPT_UPDATE)
  • BRK (used by INTERRUPT_BREAK)
  • TRG_COM (used by INTERRUPT_TRIGGER and INTERRUPT_COM)
  • CC (used by INTERRUPT_CAPTURE_COMPARE_1..3)
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 
)
inheritedstatic

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).


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