![]() |
|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
january 2015 docid022500 rev 4 1/37 1 AN4013 application note stm32f0, stm32f1, stm32f2, stm32f4, stm32l1 series, stm32f30x, stm32f3x8, stm32f373 lines timer overview introduction the purpose of this document: is detailed hereafter; ? present an overview of the timer peripherals in the stm32f0, stm32f1, stm32f2, stm32f4 and stm32l1 microcontroller series, stm32f30x and stm32f3x8, stm32f37x microcontrollers lines . stm32f30x corresponds to stm32f301, stm32f302 and stm32f303 lines. ? describe the various modes and specific features of the timers, such as clock sources. ? explain how to use the available modes and features. ? explain how to compute the time base in each configuration. ? describe the timer synchronization sequences and the advanced features for motor control applications, in addition to the general-purpose timer modes. for each mode, typical configurations are presented and examples of how to use the modes are provided. in the rest of this document (unless otherwise specified), the term stm32xx is used to refer to the products listed in table 1 . table 1. applicable products type applicable products microcontrollers stm32f0, stm32f1, stm32f2, stm32f4, stm32l1 series. stm32f301, stm32f302, stm32f303, stm32f3x8, stm32f373 lines. www.st.com
contents AN4013 2/37 docid022500 rev 4 contents 1 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 general-purpose timer modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1 clock input sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1.1 internal clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1.2 external clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2 time base generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.3 timer input capture mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.4 timer output compare mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.5 timer pwm mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.6 timer one pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.7 timer asymmetric pwm mode available for stm32f30x and stm32f3x8 lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.8 timer combined pwm mode available for stm32f30x and stm32f3x8 lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.9 retriggerable one pulse mode available for stm32f30x and stm32f3x8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3 timer synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.1 timer system link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.2 master configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.3 slave configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4 advanced features for motor control . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.1 signal generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.2 combined three-phase pwm mode available for stm32f30x and stm32f3x8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.3 specific features for motor control applications . . . . . . . . . . . . . . . . . . . . 27 4.3.1 complementary signal and dead time feature . . . . . . . . . . . . . . . . . . . . 27 4.3.2 break input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.3.3 locking mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.3.4 specific features for feedback measurement . . . . . . . . . . . . . . . . . . . . 30 5 specific applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 docid022500 rev 4 3/37 AN4013 contents 3 5.1 infrared application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 5.2 3-phase ac and pmsm control motor . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 5.3 six-step mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 6 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 list of tables AN4013 4/37 docid022500 rev 4 list of tables table 1. applicable products. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 table 2. stm32 family timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 table 3. timer features overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 table 4. advanced timer configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25 table 5. behavior of timer outputs versus break1 and break2 inputs . . . . . . . . . . . . . . . . . . . . . . . 29 table 6. locking levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 table 7. document revision history. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 docid022500 rev 4 5/37 AN4013 list of figures 5 list of figures figure 1. asymmetric pwm mode versus center aligned pwm mode . . . . . . . . . . . . . . . . . . . . . . . 17 figure 2. combined pwm mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 figure 3. retriggerable opm mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 figure 4. timer system link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 figure 5. combined three-phase pwm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 figure 6. two signals are generated with insertion of a dead time . . . . . . . . . . . . . . . . . . . . . . . . . . 27 figure 7. position at x4 resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 figure 8. position at x2 resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 figure 9. output waveform of a typical hall sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 figure 10. commutation sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 overview AN4013 6/37 docid022500 rev 4 1 overview stm32 devices use various types of timers, with the following features for each: ? general-purpose timers are used in any application for output compare (timing and delay generation), one-pulse mode, input capture (for external signal frequency measurement), sensor interface (encoder, hall sensor)... ? advanced timers : these timers have the most features. in addition to general purpose functions, they include several features related to motor control and digital power conversion applications: three complementary signals with deadtime insertion, emergency shut-down input. ? one or two channel timers : used as general-purpose timers with a limited number of channels. ? one or two channel timers with complementary output : same as previous type, but having a deadtime generator on one channel. this allows having complementary signals with a time base independent from the advanced timers. ? basic timers have no input/outputs and are used either as timebase timers or for triggering the dac peripheral. table 2 summarizes the stm32 family timers. table 3 presents a general overview of timer features. docid022500 rev 4 7/37 AN4013 overview 36 note: stm32f30x and stm32f3x8 timers present several new modes: asymmetric mode, combined mode, one retriggerable mode, combined 3 pwm mode and a second break input, these modes are available only for these families. table 2. stm32 family timers timer type stm32f0 series stm32f101 /102/103/ 105/107 lines stm32f100 value line stm32l1 series stm32f2 and stm32f4 series stm32f30x and stm32f3x8 stm32f37x lines advanced tim1 tim1 tim1 - tim1 tim1 - - tim8 - - tim8 tim8 - tim20 (1) general purpose 16-bit - tim2 tim2 tim2 - tim2 tim2 tim3 tim3 tim3 tim3 tim3 tim3 tim3 - tim4 tim4 tim4 tim4 tim4 tim4 - tim5 tim5 - - - tim5 - - - - - - tim19 32-bit tim2 - - - tim2 tim2 tim2 - - - - tim5 tim5 basic tim6 tim6 tim6 tim6 tim6 tim6 tim6 - tim7 tim7 tim7 tim7 tim7 tim7 - - - - - - tim18 1-channel - tim10 - tim10 tim10 - - - tim11 - tim11 tim11 - - - tim13 tim13 tim13 - tim13 tim14 tim14 tim14 tim14 - tim14 2-channel - tim9 tim9 tim9 - - - tim12 tim12 - tim12 - tim12 1-channel with one complementary output tim15 - tim15 - - tim15 tim15 - - - - - - - 2-channel with one complementary output tim16 - tim16 - - tim16 tim16 tim17 - tim17 - - tim17 tim17 1. tim20 is only available for stm32f303xdxe and stm32f398ve devices. overview AN4013 8/37 docid022500 rev 4 table 3. timer features overview timer type counter resolution counter type dma channels comp. channels synchronization master config. slave config. advanced 16 bit up, down and center aligned yes 4 3 yes yes general-purpose 16 bit 32 bit (1) up, down and center aligned yes 4 0 yes yes basic 16 bit up yes 0 0 yes no 1-channel 16 bit up no 1 0 yes (oc signal) no 2-channel 16 bit up no 2 0 yes yes 1-channel with one complementary output 16 bit up yes 1 1 yes (oc signal) no 2-channel with one complementary output 16 bit up yes 2 1 no yes 1. tim2 and tim5 are 32-bit counter resolution in the stm32f2, stm32f4 series, stm32f303xb/c/d/e and stm32f3x8 devices. docid022500 rev 4 9/37 AN4013 general-purpose timer modes 36 2 general-purpose timer modes general-purpose timers can be programmed to work in one of the following configurations. 2.1 clock input sources the timer can be synchronized by several clocks simultaneously: ? internal clock ? external clock ? external mode1 (ti1 or ti2 pins) ? external clock mode2 (etr pin) ? internal trigger clock (itrx) 2.1.1 internal clock the timer is clocked by default by the internal clock provided from the rcc. to select this clock source, the smcr_sms (if present) bits should be reset. 2.1.2 external clock the external clock timer is divided in two categories: ? external clock connected to ti1 or ti2 pins ? external clock connected to etr pin in these cases, the clock is provided by an external signal connected to tix pins or etr pin. the maximum external clock frequency should be verified. note: 1 in addition to all these clock sources, the timer should be clocked with the apbx clock. 2 the external clocks are not directly feeding the prescaler, but they are first synchronized with the apbx clock through dedicated logical blocks. external clock mode1 (ti1 or ti2 pins) in this mode the external clock will be applied on timer input ti1 pin or ti2 pin. to do this: 1. configure the timers to use the tix pin as input: a) select the pin to be used by writing ccxs bits in the timx_ccmr1 register. b) select the polarity of the input: for the stm32f100/101/102/103/105/107 lines: by writing ccxp in the timx_ccer register to select the rising or the falling edge; for the other series & lines: by writing ccxp and ccxnp in the timx_ccer register to select the rising/falling edge, or both edges (a) . a. for the stm32f100/101/102/103/105/107 lines, polarity selection for both edges can be achieved by using ti1f_ed, but only for ti1 input. general-purpose timer modes AN4013 10/37 docid022500 rev 4 c) enable the corresponding channel by setting the ccex bit in the timx_ccer register. 2. select the timer tix as the trigger input source by writing ts bits in the timx_smcr register. 3. select the external clock mode1 by writing sms=111 in the timx_smcr register. external clock mode2 (etr pin) the external clock mode2 uses the etr pin as timer input clock. to use this feature: 1. select the external clock mode2 by writing ece = 1 in the timx_smcr register. 2. configure, if needed, the prescaler, the filter and the polarity by writing etps [1:0], etf [3:0] and etp in the timx_smcr register. internal trigger clock (itrx) this is a particular mode of timer synchronization. when using one timer as a prescaler for another timer, the first timer update event or output compare signal is used as a clock for the second one. 2.2 time base generator the timer can be used as a time base generator. depending on the clock, prescaler and auto reload, repetition counter (if present) parameters, the 16-bit timer can generate an update event from a nanosecond to a few minutes. for the 32-bit timer, the range is larger. example update event period the update event period is calculated as follows: update_event = tim_clk/((psc + 1)*(arr + 1)*(rcr + 1)) tim_clk = 72 mhz prescaler = 1 auto reload = 65535 no repetition counter rcr = 0 update_event = 72*106/((1 + 1)*(65535 + 1)*(1)) update_event = 549.3 hz where: tim_clk = timer clock input psc = 16-bit prescaler register arr = 16/32-bit autoreload register rcr = 16-bit repetition counter docid022500 rev 4 11/37 AN4013 general-purpose timer modes 36 example external clock mode2 in this mode, the update event period is calculated as follows: update_event = etr_clk/((etr_psc)*(psc + 1)*(arr + 1)*(rcr + 1)) where etr_clk = the external clock frequency connected to etr pin. etr_clk = 100 khz prescaler = 1 etr_psc = 2 autoreload = 255 repetition counter = 2 update_event= 100*103/((2 + 1)* (1+ 1)*((255 + 1)*(2 + 1)) update_event = 21.7 hz example external clock mode1 in this mode, the update event period is calculated as follows: update_event = tix_clk/((psc + 1)*(arr + 1)*(rcr +1)) where tix_clk = the external clock frequency connected to ti1 pin or ti2 pin. tix_clk = 50 khz prescaler = 1 auto reload = 255 repetition counter = 2 update_event = 50 000/((1+ 1)*((255 + 1)*(2 + 1)) update_event = 32.55 hz example internal trigger clock (itrx) mode1 in this mode, the update event period is calculated as follows: update_event = itrx_clk/((psc + 1)*(arr + 1)*(rcr + 1)) where itrx_clk = the internal trigger frequency mapped to timer trigger input (trgi) itrx_clk = 8 khz prescaler = 1 auto reload = 255 repetition counter = 1 update_event = 8000/((1+ 1)*((255 + 1)*(1 + 1)) update_event = 7.8 hz depending on the counter mode, the update event is generated each: ? overflow, if up counting mode is used: the dir bit is reset in timx_cr1 register ? underflow, if down counting mode is used: the dir bit is set in timx_cr1 register ? overflow and underflow, if center aligned mode is used: the cms bits are different from zero. general-purpose timer modes AN4013 12/37 docid022500 rev 4 the update event is generated also by: ? software, if the ug (update generation) bit is set in tim_egr register. ? update generation through the slave mode controller as the buffered registers (arr, psc, ccrx) need an update event to be loaded with their preload values, set the urs (update request source) to 1 to avoid the update flag each time these values are loaded. in this case, the update event is only generated if the counter overflow/underflow occurs. the update event can be also disabled by setting the bit udis (update disable) in the cr1 register. in this case, the update event is not generated, and shadow registers (arr, psc, ccrx) keep their value. the counter and the prescaler are reinitialized if the ug bit is set, or if a hardware reset is received from the slave mode controller. an interrupt or/ and a dma request can be generated when the uie bit or/and ude bit are set in the dier register. for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries in the /project/stm32xx_stdperiph_examples/ tim/timebase folder. stm32cube f3 firmware package includes examples in the following directories: ? projects\stm32f3348-discovery\examples\tim\tim_timebase, ? projects\stm32f302r8-nucleo\examples\tim\tim_timebase, ? projects\stm32f3-discovery\examples\tim\tim_timebase, ? projects\stm32373c_eval\examples\tim\tim_timebase, ? projects\stm32303e_eval\examples\tim\tim_timebase and ? projects\stm32303c_eval\examples\tim\tim_timebase 2.3 timer input capture mode the timer can be used in input capture mode to measure an external signal. depending on timer clock, prescaler and timer resolution, the maximum measured period is deduced. to use the timer in this mode: 1. select the active input by setting the ccxs bits in ccmrx register. these bits should be different from zero, otherwise the ccrx register will be read only. 2. program the filter by writing the ic1f[3:0] bits in the ccmrx register, and the prescaler by writing the ic1psc[1:0] if needed. 3. program the polarity by writing the ccxnp/ccxp bits to select between rising, falling or both edges. the input capture module is used to capture the value of the counter after a transition is detected by the corresponding input channel. to get the external signal period, two consecutive captures are needed. the period is calculated by subtracting these two values. period = capture(1) /(timx_clk *(psc+1)*(icxpsc)*polarity_index(2)) the capture difference between two consecutive captures ccrx_tn and ccrx_tn+1: ? if ccrx_tn < ccrx_tn+1: capture = ccrx_tn+1 - ccrx_tn ? if ccrx_tn > ccrx_tn+1: capture = (arr_max - ccrx_tn) + ccrx_tn+1 the polarity index is 1 if the rising or falling edge is used, and 2 if both edges are used. docid022500 rev 4 13/37 AN4013 general-purpose timer modes 36 particular case to facilitate the input capture measurement, the timer counter is reset after each rising edge detected on the timer input channel by: ? selecting tixfpx as the input trigger by setting the ts bits in the smcr register ? selecting the reset mode as the slave mode by configuring the sms bits in the smcr register using this configuration, when an edge is detected, the counter is reset and the period of the external signal is automatically given by the value on the ccrx register. this method is used only with channel 1 or channel 2. in this case, the input capture prescaler (icpsc) is not considered in the period computation. the period is computed as follows: period = ccrx /(timx_clk *(psc+1)* polarity_index(1)) the polarity index is 1 if rising or falling edge is used, and 2 if both edges are used. for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries in the /project/stm32xx_stdperiph_examples/ tim/inputcapture folder. stm32cube f3 firmware package includes examples in the following directories: ? projects\stm32f3-discovery\examples\tim\tim_inputcapture, ? projects\stm32373c_eval\examples\timtim_inputcapture, ? projects\stm32303e_eval\examples\tim\tim_inputcapture and ? projects\stm32303c_eval\examples\tim\tim_inputcapture 2.4 timer output compare mode to control an output waveform, or to indicate when a period of time has elapsed, the timer is used in one of the following output compare modes. the main difference between these modes is the output signal waveform. ? output compare timing : the comparison between the output compare register ccrx and the counter cnt has no effect on the outputs. this mode is used to generate a timing base. ? output compare active : set the channel output to active level on match. the ocxref signal is forced high when the counter (cnt) matches the capture/compare register (ccrx). ? output compare inactive : set channel to inactive level on match. the ocxref signal is forced low when the counter (cnt) matches the capture/compare register (ccrx). ? output compare toggle : ocxref toggles when the counter (cnt) matches the capture/compare register (ccrx). ? output compare forced active/inactive : ocref is forced high (active mode) or low (inactive mode) independently from counter value. general-purpose timer modes AN4013 14/37 docid022500 rev 4 to configure the timer in one of these modes: 1. select the clock source. 2. write the desired data in the arr and ccrx registers. 3. configure the output mode: a) select the output compare mode: timing / active / inactive / toggle. b) in case of active, inactive and toggle modes, select the polarity by writing ccxp in ccer register. c) disable the preload feature for ccx by writing ocxpe in ccmrx register. d) enable the capture / compare output by writing ccxe in ccmrx register. 4. enable the counter by setting the cen bit in the timx_cr1 register. 5. set the ccxie / ccxde bit if an interrupt / dma request is to be generated. timer output compare timing / toggle update rate computation ccx update rate = timx_counter_clk / ccrx ? if internal clock: timx_counter_clk = tim_clk / (psc + 1) ? if external clock mode2: timx_counter_clk = etr_clk / ((etr_psc)*(psc + 1)) ? if external clock mode1: timx_counter_clk = tix_clk/(psc + 1) ? if etrf used as clock source: trgi_clk = etr_clk / etr_psc ? if ti1fp1 used as clock source: trgi_clk = ti1_clk / ti1_psc ? if ti2fp2 used as clock source: trgi_clk = ti2_clk / ti2_psc ? if ti1_ed used as clock source: trgi_clk = ti1_ed_clk ? if itrx used as clock source: trgi_clk = itrx_clk timer output compare active/inactive delay computation ccx_delay = ccrx /timx_counter_clk ? if internal clock: timx_counter_clk = tim_clk / (psc + 1) ? if external clock mode2: timx_counter_clk = etr_clk / ((etr_psc)*(psc + 1)) ? if external clock mode1: timx_counter_clk = tix_clk/(psc + 1) ? if etrf used as clock source: trgi_clk = etr_clk / etr_psc ? if ti1fp1 used as clock source: trgi_clk = ti1_clk / ti1_psc ? if ti2fp2 used as clock source: trgi_clk = ti2_clk / ti2_psc ? if ti1_ed used as clock source: trgi_clk = ti1_ed_clk ? if itrx used as clock source: trgi_clk = itrx_clk for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries, in the /project/stm32xx_stdperiph_examples/ tim/oc_toggle, /ocactive and /ocinactive folders. docid022500 rev 4 15/37 AN4013 general-purpose timer modes 36 2.5 timer pwm mode the timer is able to generate pwm in edge-aligned mode or center-aligned mode independently on each channel, with a frequency determined by the value of the timx_arr register, and a duty cycle determined by the value of the timx_ccrx register. pwm mode 1 ? in up-counting, channelx is active as long as cnt< ccrx, otherwise it is inactive. ? in down-counting, channelx is inactive as long as cnt> ccrx, otherwise it is active pwm mode 2 ? in up-counting, channelx is inactive as long as cnt < ccrx, otherwise it is active. ? in down-counting, channelx is active as long as cnt > ccrx, otherwise it is inactive. note: active when ocref = 1, inactive when ocref = 0. to configure the timer in this mode: 1. configure the output pin: a) select the output mode by writing ccs bits in ccmrx register. b) select the polarity by writing the ccxp bit in ccer register. 2. select the pwm mode (pwm1 or pwm2) by writing ocxm bits in ccmrx register. 3. program the period and the duty cycle respectively in arr and ccrx registers. 4. set the preload bit in ccmrx register and the arpe bit in the cr1 register. 5. select the counting mode: a) pwm edge-aligned mode: the counter must be configured up-counting or down- counting. b) pwm center aligned mode: the counter mode must be center aligned counting mode (cms bits different from '00'). 6. enable the capture compare. 7. enable the counter. for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries, in the /project/stm32xx_stdperiph_examples/ tim/pwm_output and /7pwm_output folders. stm32cube f3 firmware package includes examples in the following directories: ? projects\stm32f303re-nucleo\examples\tim\tim_pwmoutput, ? projects\stm32f302r8-nucleo\examples\tim\tim_pwmoutput, ? projects\stm32f3-discovery\examples\tim\tim_pwmoutput, ? projects\stm32373c_eval\examples\tim\tim_pwmoutput, ? projects\stm32303e_eval\examples\tim\tim_pwmoutputand ? projects\stm32303c_eval\examples\tim\tim_pwmoutput general-purpose timer modes AN4013 16/37 docid022500 rev 4 2.6 timer one pulse mode one pulse mode (opm) is a particular case of the input capture mode and the output compare mode. it allows the counter to be started in response to a stimulus and to generate a pulse with a programmable length after a programmable delay. to configure the timer this mode: 1. configure the input pin and mode: a) select the tixfpx trigger to be used by writing ccxs bits in ccmrx register. b) select the polarity of the input pin by writing ccxp and ccxnp bits in ccer register. c) configure the tixfpx trigger for the slave mode trigger by writing ts bits in smcr register. d) select the trigger mode for the slave mode by writing sms = 110 in smcr register. 2. configure the output pin and mode: a) select the output polarity by writing ccyp bit in ccer register. b) select the output compare mode by writing ocym bits in ccmry register (pwm1 or pwm2 mode). c) set the delay value by writing in ccry register. d) set the auto reload value to have the desired pulse: pulse = timy_arr - timy_ccry. 3. select the one pulse mode by setting the opm bit in cr1 register, if only one pulse is to be generated. otherwise this bit should be reset. delay = ccry/(timx_clk/(psc + 1)) pulse-length = (arr - ccry)/(timx_clk/(psc + 1)) for more details on using the timer in this mode, refer to the examples provided in the stm32xx standard peripheral libraries, in the /project/stm32xx_stdperiph_examples/ tim/onepulse folder. 2.7 timer asymmetric pwm mode available for stm32f30x and stm32f3x8 lines the asymmetric mode allows generating a center-aligned pwm signals with a programmable phase shift. for a dedicated channel, the phase shift and the pulse length are programmed using the two timx_ccrx register (timx_ccr1 and timx_ccr2 or timx_ccr3 and timx_ccr4), the frequency is determined by the value of the timx_arr register. so the asymmetric pwm mode can be selected independently on two channels by programming the ocxm bits in timx_ccmrx register: ? ocxm = 1110 to use the asymmetric pwm1, in this mode the output reference has the same behavior as in pwm1 mode. when the counter is counting up the output reference is identical to oc1/3ref, when the counter is down counting, the output reference is identical to oc2/4ref ? ocxm = 1111 to use the asymmetric pwm2, in this mode the output reference has the same behavior as in pwm2 mode. when the counter is counting up the output reference is identical to oc1/3ref, when the counter is down counting, the output reference is identical to oc2/4ref docid022500 rev 4 17/37 AN4013 general-purpose timer modes 36 the following figure resumes the asymmetric behavior versus the center aligned pwm mode figure 1. asymmetric pwm mode versus center aligned pwm mode to configure the timer in this mode: 1. configure the output pin: a) select the output mode by writing ccs bits in ccmrx register. b) select the polarity by writing the ccxp bit in ccer register. 2. select the asymmetric pwm mode (asymmetric pwm1 or asymmetric pwm2) by writing ocxm bits in ccmrx register. 3. program the period, the pulse length and the phase shift respectively in arr, ccrx and ccry registers. 4. select the counting mode: the asymmetric pwm mode is working only with center aligned mode: the counter mode must be center aligned counting mode (cms bits different from '00'). 5. enable the capture compare. 6. enable the counter. for more details on how to use the timer in this mode, refer to the examples provided in the stm32f30x standard peripheral libraries, in the /project/stm32f30x_stdperiph_examples/ tim/asymmetric folders. 0 6 9 3 : 0 f h q w h u d o l j q h g $ 5 5 d q g & |