AN2581 Application note

Similar documents
AN3332 Application note

STEVAL-ISQ010V1. High-side current-sense amplifier demonstration board based on the TSC102. Features. Description

STEVAL-ISA005V1. 1.8W buck topology power supply evaluation board with VIPer12AS. Features. Description. ST Components

AN4014 Application Note Adjustable LED blinking frequency using a potentiometer and STM8SVLDISCOVERY Application overview

BD235 BD237. Low voltage NPN power transistors. Features. Applications. Description. Low saturation voltage NPN transistors

BUX87. High voltage NPN power transistor. Features. Applications. Description

D44H8 - D44H11 D45H8 - D45H11

R 1 typ. = 15 kω. Order codes Marking Polarity Package Packaging. 2N6036 2N6036 NPN SOT-32 Tube 2N6039 2N6039 PNP SOT-32 Tube

EVAL-RHF310V1. EVAL-RHF310V1 evaluation board. Features. Description

Order codes Marking Polarity Package Packaging. MJD44H11T4 MJD44H11 NPN DPAK Tape and reel MJD45H11T4 MJD45H11 PNP DPAK Tape and reel

Obsolete Product(s) - Obsolete Product(s)

Obsolete Product(s) - Obsolete Product(s)

BD533 BD535 BD537 BD534 BD536

BD241A BD241C. NPN power transistors. Features. Applications. Description. NPN transistors. Audio, general purpose switching and amplifier transistors

Obsolete Product(s) - Obsolete Product(s)

2STR2215. Low voltage fast-switching PNP power transistor. Features. Applications. Description

AN279 Application note

MJE182 Low voltage high speed switching NPN transistor Features Applications Description High speed switching NPN device

STD1802T4-A. Low voltage fast-switching NPN power transistor. Features. Description. Applications

UM0791 User manual. Demonstration firmware for the DMX-512 communication protocol receiver based on the STM32F103Zx. Introduction

ST26025A. PNP power Darlington transistor. Features. Applications. Description

STEVAL-CCA040V1. 4X10 Watt dual/quad power amplifier demonstration board based on the STA540SAN. Features. Description

STB High voltage fast-switching NPN power transistor. Features. Applications. Description

2STA1943. High power PNP epitaxial planar bipolar transistor. Features. Application. Description

2STC4468. High power NPN epitaxial planar bipolar transistor. Features. Application. Description

Obsolete Product(s) - Obsolete Product(s)

2STA1695. High power PNP epitaxial planar bipolar transistor. Features. Applications. Description

BD243C BD244C. Complementary power transistors. Features. Applications. Description. Complementary NPN-PNP devices. Power linear and switching TO-220

TIP2955 TIP3055. Complementary power transistors. Features. Applications. Description

3STL2540. Low voltage high performance PNP power transistor. Features. Applications. Description

Obsolete Product(s) - Obsolete Product(s)

Order codes Marking Package Packaging 2STF SOT-89 2STN2550 N2550 SOT-223. November 2008 Rev 1 1/8

Obsolete Product(s) - Obsolete Product(s)

2STX2220. High Gain Low Voltage PNP Power Transistor. General features. Description. Internal schematic diagram. Applications.

LM323. Three-terminal 3 A adjustable voltage regulators. Features. Description

AN2333 Application note

2STN2540. Low voltage fast-switching PNP power bipolar transistor. Features. Applications. Description

Obsolete Product(s) - Obsolete Product(s)

Order codes Marking Package Packaging. STD2805T4 D2805 DPAK Tape & reel STD D2805 IPAK Tube. June 2007 Rev 1 1/9

R 1 typ. = 15 kω. Order codes Marking Polarity Package Packaging. STX112-AP X112 NPN TO92-AP Ammopack STX117-AP X117 PNP TO92-AP Ammopack

BUL39D. High voltage fast-switching NPN power transistor. Features. Application. Description

SPV1001T40. Cool bypass switch for photovoltaic application. Features. Application. Description TO-220

2STR SOT-23 Tape and reel 2STR1230G 130G SOT-23 Tape and reel

Obsolete Product(s) - Obsolete Product(s) Obsolete Product(s) - Obsolete Product(s)

2STC4468. High power NPN epitaxial planar bipolar transistor. Features. Application. Description

AN1756 Application note

2STD1665. Low voltage fast-switching NPN power transistor. Features. Applications. Description

Obsolete Product(s) - Obsolete Product(s)

STN9260. High voltage fast-switching PNP power transistor. Features. Applications. Description. High voltage capability Fast switching speed

BDX53B - BDX53C BDX54B - BDX54C

Order codes Marking Package Packaging. STX0560 X0560 TO-92 Bag STX0560-AP X0560 TO-92AP Ammopack. December 2010 Doc ID Rev 1 1/9

2STC5242. High power NPN epitaxial planar bipolar transistor. Features. Application. Description

2ST2121. High power PNP epitaxial planar bipolar transistor. Features. Applications. Description 1 2 TO-3

STEVAL-CCA011V1. Filter-free stereo 2x2.5 W Class-D audio power amplifier demonstration board based on the TS2012FC. Features.

2N2219AHR. Hi-Rel NPN bipolar transistor 40 V A. Features. Description

2STD1360 2STF1360-2STN1360

TR136. High voltage fast-switching NPN power transistor. Features. Applications. Description

STC04IE170HV. Monolithic emitter switched bipolar transistor ESBT 1700 V - 4 A Ω. Features. Application. Description

LM723CN. High precision voltage regulator. Features. Description

SD1728 (TH430) RF & Microwave transistors HF SSB application. Features. Description. Pin connection

AN2837 Application note

STN High voltage fast-switching PNP power transistor. Features. Application. Description. High voltage capability Very high switching speed

ST13003D-K High voltage fast-switching NPN power transistor Features Applications Description

AN440 Application note

AN3134 Application note

AN1441 Application note

BUL38D. High voltage fast-switching NPN power transistor. Features. Applications. Description

AN4112 Application note

STD840DN40. Dual NPN high voltage transistors in a single package. Features. Applications. Description

Obsolete Product(s) - Obsolete Product(s)

Part Number Marking Package Packing. MD1802FX MD1802FX ISOWATT218FX Tube. August 2006 Rev 1 1/8

HCF4093. QUAD 2-input NAND Schmidt trigger. Features. Description

MD1802FX. High voltage NPN power transistor for standard definition CRT display. Features. Applications. Description

AN2979 Application note

LET9060C. RF power transistor from the LdmoST family of n-channel enhancement-mode lateral MOSFETs. Features. Description

STC04IE170HV. Emitter switched bipolar transistor ESBT 1700V - 4A W. General features. Internal schematic diagrams. Description.

Obsolete Product(s) - Obsolete Product(s)

Obsolete Product(s) - Obsolete Product(s)

MD2310FX. High voltage NPN power transistor for standard definition CRT display. Features. Application. Description

Part numbers Order codes Packages Temperature range. LM137 LM137K TO-3-55 C to 150 C LM337 LM337K TO-3 0 C to 125 C LM337 LM337SP TO C to 125 C

KF25B, KF33B KF50B, KF80B

Part Number Marking Package Packing. STC03DE220HV C03DE220HV TO247-4L HV Tube. November 2006 Rev 1 1/8

2STD1665. Low voltage fast-switching NPN power transistor. Features. Applications. Description

Very high voltage NPN power transistor for high definition and slim CRT display. Part number Marking Package Packaging HD1750JL HD1750JL TO-264 Tube

Obsolete Product(s) - Obsolete Product(s)

1. Drain 2. Gate. Order code Marking Package Packaging. STAC4932F STAC4932F STAC244F Plastic tray. September 2010 Doc ID Rev 3 1/12

BUX98A. High power NPN transistor. Features. Applications. Description. High voltage capability High current capability Fast switching speed

High voltage NPN Power transistor for standard definition CRT display. R BE =60Ω typ. Order code Marking Package Packing

STN2580. High voltage fast switching NPN power transistor. Features. Applications. Description. High voltage capability Fast switching speed

STPSC V power Schottky silicon carbide diode. Features. Description

ST1510FX. High voltage fast-switching NPN Power transistor. General features. Applications. Internal schematic diagram. Description.

STN9360. High voltage fast-switching PNP power transistor. Features. Applications. Description. High voltage capability Fast switching speed

BUL743. High voltage fast-switching NPN power transistor. Features. Applications. Description

ESDALCL6-4P6A. Multi-line low capacitance and low leakage current ESD protection. Features. Applications. Description

TDA7233D 1W AUDIO AMPLIFIER WITH MUTE

MD2009DFX. High voltage NPN power transistor for CRT TV. Features. Application. Description

MJD122 MJD127 Complementary power Darlington transistors Features Applications Description

Obsolete Product(s) - Obsolete Product(s)

AN1229 Application note

STL128D. High voltage fast-switching NPN power transistor. Features. Applications. Description

Transcription:

AN2581 Application note STM32F10xxx TIM application examples Introduction This application note is intended to provide practical application examples of the STM32F10xxx TIMx peripheral use. This document, its associated firmware, and other such application notes are written to accompany the STM32F10xxx firmware library. These are available for download from the STMicroelectronics website: www.st.com. June 2007 Rev 1 1/24 www.st.com

Contents AN2581 - Application note Contents 1 STM32F10xxx TIMx output compare mode....................... 4 1.1 Overview.................................................. 4 1.2 Firmware description......................................... 4 1.3 TIMx output signal behavior.................................... 5 2 Delay generation in TIMx output compare active mode............ 6 2.1 Overview.................................................. 6 2.2 Firmware description......................................... 6 2.3 TIMx output signal behavior.................................... 7 3 STM32F10xxx TIMx output compare inactive mode............... 8 3.1 Overview.................................................. 8 3.2 Firmware description......................................... 8 3.3 TIMx output signal behavior.................................... 9 4 STM32F10xxx TIMx pulse width modulation mode............... 10 4.1 Overview................................................. 10 4.2 Firmware description........................................ 10 4.3 TIMx output signal behavior................................... 11 5 TIMx output compare timing mode: time-base generation......... 12 5.1 Overview................................................. 12 5.2 Firmware description........................................ 12 5.3 TIMx output signal behavior................................... 13 6 STM32F10xxx TIMx PWM input mode.......................... 14 6.1 Overview................................................. 14 6.2 Firmware description........................................ 14 7 Generating an OPM waveform after an edge on TIMx TIx input..... 15 7.1 Overview................................................. 15 7.2 Firmware description........................................ 15 7.3 TIMx output signal behavior................................... 16 2/24

AN2581 - Application note Contents 8 Synchronizing TIMx peripherals in parallel mode................ 17 8.1 Overview................................................. 17 8.2 Firmware description........................................ 17 8.3 TIMx output signal behavior................................... 18 9 Synchronizing TIMx peripherals in cascade mode............... 19 9.1 Overview................................................. 19 9.2 Firmware description........................................ 19 9.3 TIMx output signal behavior................................... 20 10 Synchronizing several timers TIMx to an external trigger.......... 21 10.1 Overview................................................. 21 10.2 Firmware description........................................ 21 10.3 TIMx output signal behavior................................... 22 11 Revision history........................................... 23 3/24

STM32F10xxx TIMx output compare mode AN2581 - Application note 1 STM32F10xxx TIMx output compare mode 1.1 Overview This section provides a description of how to configure the TIM peripheral in output compare mode to generate four different signals with four different frequencies. 1.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. The TIMxCLK frequency is set to 36 MHz, the prescaler is set to 0x2 and used in the output compare toggle mode. TIM2 counter clock = TIMxCLK / (Prescaler +1) = 12 MHz The TIM2_CCR1 register value is equal to 0x8000: CC1 update rate = TIM2 counter clock / CCR1_Val = 366.2 Hz, so TIM2_CH1 generates a periodic signal with a frequency equal to 183.1 Hz. The TIM2_CCR2 register is equal to 0x4000: CC2 update rate = TIM2 counter clock / CCR2_Val = 732.4 Hz so TIM2_CH2 generates a periodic signal with a frequency equal to 366.3 Hz. The TIM2_CCR3 register is equal to 0x2000: CC3 update rate = TIM2 counter clock / CCR3_Val = 1464.8 Hz so the TIM2_CH3 generates a periodic signal with a frequency equal to 732.4 Hz. The TIM2_CCR4 register is equal to 0x1000: CC4 update rate = TIM2 counter clock / CCR4_Val = 2929.6 Hz so the TIM2_CH4 generates a periodic signal with a frequency equal to 1464.8 Hz. This firmware is provided as TIM example 1 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 4/24

AN2581 - Application note STM32F10xxx TIMx output compare mode 1.3 TIMx output signal behavior To display the four signals (see Figure 1), connect an oscilloscope to the following pins: PA0 (TIM2_CH1) PA1 (TIM2_CH2) PA2 (TIM2_CH3) PA3 (TIM2_CH4) Figure 1. TIM2 output signals 5/24

Delay generation in TIMx output compare active mode AN2581 - Application note 2 Delay generation in TIMx output compare active mode 2.1 Overview This section provides a description of how to configure the TIM peripheral to generate four different signals with four different delays. 2.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. The TIMxCLK frequency is set to 36 MHz, the prescaler is set to 35999 and used in the output compare active mode. TIM2 counter clock = TIMxCLK / (Prescaler +1) = 1 khz The TIM2_CCR1 register value is equal to 1000: TIM2_CH1 delay = CCR1_Val/TIM2 counter clock = 1000 ms so the TIM2_CH1 generates a signal with a delay equal to 1000 ms. The TIM2_CCR2 register value is equal to 500: TIM2_CH2 delay = CCR2_Val/TIM2 counter clock = 500 ms so the TIM2_CH2 generates a signal with a delay equal to 500 ms. The TIM2_CCR3 register value is equal to 250: TIM2_CH3 delay = CCR3_Val/TIM2 counter clock = 250 ms so the TIM2_CH3 generates a signal with a delay equal to 250 ms. The TIM2_CCR4 register value is equal to 125: TIM2_CH4 delay = CCR4_Val/TIM2 counter clock = 125 ms so the TIM2_CH4 generates a signal with a delay equal to 125 ms. The delay corresponds to the time difference between the rising edge of the PC6 signal and the rising edge of the TIM2_CHx signal. This firmware is provided as TIM example 2 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 6/24

AN2581 - Application note Delay generation in TIMx output compare active mode 2.3 TIMx output signal behavior To display the four different signals (see Figure 2), connect an oscilloscope to: PC6 PA0 (TIM2_CH1) PA1 (TIM2_CH2) PA2 (TIM2_CH3) PA3 (TIM2_CH4) Figure 2. TIM2 output signals 7/24

STM32F10xxx TIMx output compare inactive mode AN2581 - Application note 3 STM32F10xxx TIMx output compare inactive mode 3.1 Overview This section provides a description of how to configure the TIM peripheral in the output compare inactive mode with the corresponding Interrupt requests for each channel. 3.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. The TIMxCLK frequency is set to 36 MHz, the prescaler is set to 35999 and used in output compare inactive mode. TIM2 counter clock = TIMxCLK / (Prescaler +1) = 1 khz The TIM2_CCR1 register value is equal to 1000: TIM2_CC1 delay = CCR1_Val/TIM2 counter clock = 1000 ms so PC6 is reset after a delay equal to 1000 ms. The TIM2_CCR2 register value is equal to 500: TIM2_CC2 delay = CCR2_Val/TIM2 counter clock = 500 ms so PC7 is reset after a delay equal to 500 ms. The TIM2_CCR3 register value is equal to 250: TIM2_CC3 delay = CCR3_Val/TIM2 counter clock = 250 ms so PC8 is reset after a delay equal to 250 ms. The TIM2_CCR4 register value is equal to 125: TIM2_CC4 delay = CCR4_Val/TIM2 counter clock = 125 ms so PC9 is reset after a delay equal to 125 ms. While the counter is lower than the Output compare register values that determine the output delay, the PC6, PC7, PC8 and PC9 pins are driven High. When the counter value reaches the Output compare register values, the Output Compare interrupts are generated and, in the handler routine, these pins are driven Low. This firmware is provided as TIM example 3 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 8/24

AN2581 - Application note STM32F10xxx TIMx output compare inactive mode 3.3 TIMx output signal behavior To display the different signals (see Figure 3), connect an oscilloscope to: PC6 (CH1) PC7 (CH2) PC8 (CH3) PC9 (CH4) Figure 3. GPIOC: PC6, PC7, PC7 and PC9 signals 9/24

STM32F10xxx TIMx pulse width modulation mode AN2581 - Application note 4 STM32F10xxx TIMx pulse width modulation mode 4.1 Overview This section provides a description of how to configure the TIM peripheral in PWM (pulse width modulation) mode. 4.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. The TIMxCLK frequency is set to 36 MHz, the prescaler is 0 so the TIM3 counter clock frequency is 36 MHz. TIM3 is running at 36 khz: TIM3 frequency = TIM3 counter clock/(tim3_arr + 1) The TIM3_CCR1 register value is equal to 0x1F4, so TIM3_CH1 generates a PWM signal with a frequency equal to 36 khz and a duty cycle equal to 50%: TIM3_CH1 duty cycle = TIM3_CCR1/ (TIM3_ARR + 1) 100 = 50% The TIM3_CCR2 register value is equal to 0x177, so the TIM3_CH2 generates a PWM signal with a frequency equal to 36 khz and a duty cycle equal to 37.5%: TIM3_CH2 duty cycle = TIM3_CCR2/ (TIM3_ARR + 1) 100 = 37.5% The TIM3_CCR3 register value is equal to 0xFA, so the TIM3_CH3 generates a PWM signal with a frequency equal to 36 khz and a duty cycle equal to 25%: TIM3_CH3 duty cycle = TIM3_CCR3/ (TIM3_ARR + 1) 100 = 25% The TIM3_CCR4 register value is equal to 0x7D, so the TIM3_CH4 generates a PWM signal with a frequency equal to 36 khz and a duty cycle equal to 12.5%: TIM3_CH4 duty cycle = TIM3_CCR4/ (TIM3_ARR + 1) 100 = 12.5% The PWM waveform can be displayed using an oscilloscope. This firmware is provided as TIM example 4 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 10/24

AN2581 - Application note STM32F10xxx TIMx pulse width modulation mode 4.3 TIMx output signal behavior To display the four different signals (see Figure 4), connect an oscilloscope to: PA6: (TIM3_CH1) PA7: (TIM3_CH2) PB0: (TIM3_CH3) PB1: (TIM3_CH4) Figure 4. TIM3 output signals 11/24

TIMx output compare timing mode: time-base generation AN2581 - Application note 5 TIMx output compare timing mode: time-base generation 5.1 Overview This section provides a description of how to configure the TIM peripheral in output compare timing mode with the corresponding interrupt requests for each channel in order to generate four different time bases. 5.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. The TIMxCLK frequency is set to 36 MHz, the prescaler is 0x4 so the TIM2 counter clock frequency is 7.2 MHz. The TIM2_CCR1 register value is equal to 0xC000 CC1 update rate = TIM2 counter clock / CCR1_Val = 146.48 Hz, so TIM2_CH1 generates an interrupt every 6.8 ms The TIM2_CCR2 register is equal to 0x8000, CC2 update rate = TIM2 counter clock / CCR2_Val = 219.7 Hz, so TIM2_CH2 generates an interrupt every 4.55 ms The TIM2_CCR3 register is equal to 0x4000, CC3 update rate = TIM2 counter clock / CCR3_Val = 439.4Hz, so TIM2_CH3 generates an interrupt every 2.27 ms The TIM2_CCR4 register is equal to 0x2000, CC4 update rate = TIM2 counter clock / CCR4_Val = 878.9 Hz, so TIM2_CH4 generates an interrupt every 1.13 ms. When the counter value reaches the Output compare register values, the Output Compare interrupts are generated and, in the handler routine, 4 pins (PC6, PC7, PC8 and PC9) are toggled at the following frequencies: PC6: 73.24 Hz (CC1) PC7: 109.8 Hz (CC2) PC8: 219.7 Hz (CC3) PC9: 439.4 Hz (CC4) This firmware is provided as TIM example 5 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 12/24

AN2581 - Application note TIMx output compare timing mode: time-base generation 5.3 TIMx output signal behavior Connect an oscilloscope to PC6, PC7, PC8 and PC9 to display the different time-base signals as shown in Figure 5. Figure 5. GPIOD signals: PC6, PC7, PC8 and PC9 13/24

STM32F10xxx TIMx PWM input mode AN2581 - Application note 6 STM32F10xxx TIMx PWM input mode 6.1 Overview This section provides a description of how to use the TIM peripheral to measure the frequency and duty cycle of an external signal. 6.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. The TIMxCLK frequency is set to 72 MHz, the prescaler is 0x0 so the TIM2 counter clock frequency is 72 MHz. So the minimum frequency value to measure is 1100 Hz. TIM2 is configured in PWM input mode: the external signal is connected to TIM2_CH2 (PA1) used as the input pin. To measure the frequency and duty cycle, the TIM2 CC2 interrupt request is used, so in the TIM2_IRQ handler routine, the frequency and duty cycle of the external signal are computed. The "Frequency" variable contains the external signal frequency: Frequency = TIM2 counter clock / TIM2_CCR2 in Hz, The "Duty_Cycle" variable contains the external signal duty cycle: Duty_Cycle = (TIM2_CCR1*100)/(TIM2_CCR2) in %. This firmware is provided as TIM example 6 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 14/24

AN2581 - Application note Generating an OPM waveform after an edge on TIMx TIx input 7 Generating an OPM waveform after an edge on TIMx TIx input 7.1 Overview This section provides a description of how to use the TIM peripheral to generate an OPM (one pulse mode) waveform after the rising edge of an external signal is received on the timer input pin (TI). 7.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. The TIMxCLK frequency is set to 72 MHz, the prescaler is 0x1 so the TIM2 counter clock frequency is 36 MHz. The autoreload value is 0xFFFF (TIM2_ARR), so the maximum frequency value to trigger the TIM2 input is 500 Hz. TIM2 is configured as follows: the one pulse mode is used, the external signal is connected to the TIM2_CH2 pin (PA1), the rising edge is used as the active edge, the one-pulse signal is output on TIM2_CH1 (PA0). TIM_Pulse defines the delay value that is fixed to 455.08 µs: delay = CCR1/TIM2 counter clock = 455.08 µs (TIM_Period - TIM_Pulse) defines the one-pulse value, the pulse value is fixed to 1.365 ms: One-pulse value = (TIM_Period - TIM_Pulse)/TIM2 counter clock = 1.365 ms This firmware is provided as TIM example 7 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 15/24

Generating an OPM waveform after an edge on TIMx TIx input AN2581 - Application note 7.3 TIMx output signal behavior Connect the external signal to measure to the TIM2 CH2 pin (PA1). Connect the TIM2_CH1 (PA0) pin to an oscilloscope to show the waveform. In Figure 6, the Ch1 presents the input signal triggering TIM2 and Ch2 is connected to TIM2_CH2 and presents the TIM2 one-pulse signal. Figure 6. TIM2 output signal 16/24

AN2581 - Application note Synchronizing TIMx peripherals in parallel mode 8 Synchronizing TIMx peripherals in parallel mode 8.1 Overview This section provides a description of how to synchronize TIMx peripherals in parallel mode. 8.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. Timer synchronization in parallel mode: 1. TIM2 is configured as the master timer: PWM mode is used The TIM2 update event is used as the trigger output 2. TIM3 and TIM4 are slaves for TIM2 PWM mode is used ITR1 (TIM2) is used as the input trigger for both slaves Gated mode is used, so starts and stops of slave counters are controlled by the master trigger output signal (update event) The master timer, TIM2, is running at 281.250 khz and the duty cycle is equal to 25%. The TIM3 is running at: (TIM2 frequency) / (TIM3 Period + 1) = 28.1250 khz and its duty cycle is equal to: TIM3_CCR1/(TIM3_ARR + 1) = 30% The TIM4 is running at: at (TIM2 frequency) / (TIM4 Period + 1) = 56.250 khz and its duty cycle is equal to: TIM4_CCR1/(TIM4_ARR + 1) = 60% This firmware is provided as TIM example 8 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 17/24

Synchronizing TIMx peripherals in parallel mode AN2581 - Application note 8.3 TIMx output signal behavior Connect the TIM2_CH1 (PA0), TIM3_CH1 (PA6) and TIM4_CH1 (PB6) pins to an oscilloscope to display the waveforms (see Figure 7). Figure 7. TIM2_CH1 (PA0), TIM3_CH1 (PA6) and TIM4_CH1 (PB6) output signals 18/24

AN2581 - Application note Synchronizing TIMx peripherals in cascade mode 9 Synchronizing TIMx peripherals in cascade mode 9.1 Overview This section provides a description of how to synchronize TIM peripherals in cascade mode. 9.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. Timer synchronization in cascade mode: 1. TIM2 is configured as the master timer: PWM mode is used the TIM2 update event is used as the trigger output 2. TIM3 is a slave for TIM2 and the master for TIM4: PWM mode is used ITR1 (TIM2) is used as the input trigger Gated mode is used, so starts and stops of the slave counter are controlled by the master trigger output signal (TIM2 update event) The TIM3 update event is used as the trigger output. 3. TIM4 is a slave for TIM3: PWM mode is used ITR2 (TIM3) is used as the input trigger Gated mode is used, so starts and stops of the slave counter are controlled by the master trigger output signal (TIM3 update event) The TIMxCLK is fixed to 72 MHz, the TIM2 counter clock frequency is 72 MHz. The master timer, TIM2, is running at the TIM2 frequency: TIM2 frequency = (TIM2 counter clock)/ (TIM2 Period + 1) = 281.250 khz and duty cycle = TIM2_CCR1/(TIM2_ARR + 1) = 25%. The TIM3 is running at: (TIM2 frequency)/ (TIM3 Period + 1) = 70.312 khz and duty cycle = TIM3_CCR1/(TIM3_ARR + 1) = 25% The TIM4 is running at: (TIM3 frequency)/ (TIM4 Period + 1) = 17.578 Hz and duty cycle = TIM4_CCR1/(TIM4_ARR + 1) = 25% This firmware is provided as TIM example 9 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 19/24

Synchronizing TIMx peripherals in cascade mode AN2581 - Application note 9.3 TIMx output signal behavior Connect the TIM2_CH1 (PA0), TIM3_CH1 (PA6) and TIM4_CH1 (PB6) pins to an oscilloscope to display the waveforms (see Figure 8). Figure 8. TIM2_CH1 (PA0), TIM3_CH1 (PA6) and TIM4_CH1 (PB6) signals 20/24

AN2581 - Application note Synchronizing several timers TIMx to an external trigger 10 Synchronizing several timers TIMx to an external trigger 10.1 Overview This section provides a description of how to synchronize TIMx peripherals in cascade mode to an external trigger. 10.2 Firmware description The provided firmware includes the TIMx driver that supports all TIMx functionalities through a set of functions. An example of use for most of these functions is provided. Timer synchronization in cascade mode with an external trigger: 1. TIM2 is configured as the master timer: Toggle mode is used the TIM2 enable event is used as the trigger output 2. TIM2 is configured as a slave timer for an external trigger connected to the TIM2 TI2 pin (TIM2_CH2 configured as an input pin): TIM2 TI2FP2 is used as the trigger input rising edge is used to enable and stop TIM2: gated mode 3. TIM3 is a slave for TIM2 and the master for TIM4, Toggle mode is used ITR1 (TIM2) is used as the input trigger Gated mode is used, so starts and stops of the slave counter are controlled by the master trigger output signal (TIM2 enable event) the TIM3 enable event is used as the trigger output 4. TIM4 is a slave for TIM3 Toggle mode is used ITR2 (TIM3) is used as the input trigger Gated mode is used, so starts and stops of the slave counter are controlled by the master trigger output signal (TIM3 enable event) TIMxCLK is fixed to 72 MHZ, the prescaler is equal to 0x2 so the TIMx clock counter frequency is 24 MHz. The three timers are running at: TIMx frequency = TIMx clock counter/ 2 (TIMx_Period + 1) = 162.1 khz The starts and stops of the TIM2 counter are controlled by the external trigger. TIM3 starts and stops are controlled by TIM2, and TIM4 starts and stops are controlled by TIM3. This firmware is provided as TIM example 10 in the STM32F10xxx firmware library, available from the STMicroelectronics microcontrollers website. 21/24

Synchronizing several timers TIMx to an external trigger AN2581 - Application note 10.3 TIMx output signal behavior Connect an external trigger with a frequency lower than or equal to 40 khz, to the TIM2_CH2 pin. In this example the frequency is equal to 5 khz. Connect the TIM2_CH1 (PA0), TIM3_CH1 (PA6) and TIM4_CH1 (PB6) pins to an oscilloscope to display the waveforms (see Figure 9). Figure 9. TIM2_CH1 (PA0), TIM3_CH1 (PA6) and TIM4_CH1 (PB6) signals 22/24

AN2581 - Application note Revision history 11 Revision history Table 1. Document revision history Date Revision Changes 26-Jun-2007 1 Initial release. 23/24

AN2581 - Application note Please Read Carefully: Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries ( ST ) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice. All ST products are sold pursuant to ST s terms and conditions of sale. Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein. UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK. Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST. ST and the ST logo are trademarks or registered trademarks of ST in various countries. Information in this document supersedes and replaces all information previously supplied. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners. 2007 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com 24/24