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

Public Typedefs

using Value = uint16_t
 

Public Types

enum  Mode : uint32_t { UpCounter = 0, OneShotUpCounter = TIM_CR1_OPM }
 
enum  Interrupt : uint32_t { Update = TIM_DIER_UIE }
 
enum  InterruptFlag : uint32_t { Update = TIM_SR_UIF }
 
enum  Event : uint32_t {
  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)
 

Static Public Member Functions

static void enable ()
 
static void disable ()
 
static bool isEnabled ()
 
static void pause ()
 
static void start ()
 
static void setMode (Mode mode)
 
static void setPrescaler (uint16_t prescaler)
 
static uint16_t getPrescaler ()
 
static void setOverflow (Value overflow)
 
static Value getOverflow ()
 
template<class Rep , class Period >
static Value setPeriod (std::chrono::duration< Rep, Period > duration, bool autoApply=true)
 
static void applyAndReset ()
 Reset the counter, and update the prescaler and overflow values. More...
 
static Value getValue ()
 
static void setValue (Value value)
 
static constexpr bool hasAdvancedPwmControl ()
 
static bool isCountingUp ()
 
static bool isCountingDown ()
 
static void enableInterruptVector (bool enable, uint8_t priority)
 
static void enableInterrupt (Interrupt_t interrupt)
 
static void disableInterrupt (Interrupt_t interrupt)
 
static InterruptFlag_t getInterruptFlags ()
 
static void acknowledgeInterruptFlags (InterruptFlag_t flags)
 

Member Function Documentation

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

Clears one or multiple flags.

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

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::BasicTimer::disable ( )
static

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

Disables interrupts.

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

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

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

Enables or disables the Interrupt Vector.

Parameters
enableEnable/disable the interrupt vector
priorityPriority of the interrupt vector (0=highest to 15=lowest).
static InterruptFlag_t modm::platform::BasicTimer::getInterruptFlags ( )
static

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 ( )
inlinestatic

Get current overflow

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

Get current prescaler

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

Get the counter value

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

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 ( )
inlinestatic

Check current count direction

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

Check, whether clock has been enabled.

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

Pause timer operation

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

static void modm::platform::BasicTimer::setMode ( Mode  mode)
static

Set operation mode of the timer

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

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

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

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

Set a new counter value

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

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: