General-purpose timers (TIM)
22.2 TIM Firmware driver API description
The following section lists the various functions of the TIM library.
22.2.1 Output Compare management functions
TIM Driver: how to use it in Output Compare Mode
To use the Timer in Output Compare mode, the following steps are mandatory:
1. Enable TIM clock using RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx,
ENABLE) function
2. Configure the TIM pins by configuring the corresponding GPIO pins
3. Configure the Time base unit as described in the first part of this driver, if needed,
else the Timer will run with the default configuration:
ï€ Autoreload value = 0xFFFF
ï€ Prescaler value = 0x0000
ï€ Counter mode = Up counting
ï€ Clock Division = TIM_CKD_DIV1
4. Fill the TIM_OCInitStruct with the desired parameters including:
ï€ The TIM Output Compare mode: TIM_OCMode
ï€ TIM Output State: TIM_OutputState
ï€ TIM Pulse value: TIM_Pulse
ï€ TIM Output Compare Polarity : TIM_OCPolarity
5. Call TIM_OCxInit(TIMx, &TIM_OCInitStruct) to configure the desired channel with the
corresponding configuration
6. Call the TIM_Cmd(ENABLE) function to enable the TIM counter.
All other functions can be used separately to modify, if needed, a specific feature
of the Timer.
In case of PWM mode, this function is mandatory: TIM_OCxPreloadConfig(TIMx,
TIM_OCPreload_ENABLE);
If the corresponding interrupt or DMA request are needed, the user should:
1. Enable the NVIC (or the DMA) to use the TIM interrupts (or DMA requests).
2. Enable the corresponding interrupt (or DMA request) using the function
TIM_ITConfig(TIMx, TIM_IT_CCx) (or TIM_DMA_Cmd(TIMx,
TIM_DMA_CCx))
ï‚· TIM_OC1Init()
ï‚· TIM_OC2Init()
ï‚· TIM_OC3Init()
ï‚· TIM_OC4Init()
ï‚· TIM_OC5Init()
ï‚· TIM_OC6Init()
ï‚· TIM_SelectGC5C1()