AN3332 Application note



Similar documents
EVL185W-LEDTV. 185 W power supply with PFC and standby supply for LED TV based on the L6564, L6599A and Viper27L. Features.

AN3265 Application note

AN3998 Application note

AN4108 Application note

AN2389 Application note

2STBN15D100. Low voltage NPN power Darlington transistor. Features. Application. Description

Single LNB supply and control IC DiSEqC 1.X compliant with EXTM based on the LNBH29 in a QFN16 (4x4) Description

AN3354 Application note

TN0023 Technical note

DDSL01. Secondary protection for DSL lines. Features. Description

AN2604 Application note

BD238. Low voltage PNP power transistor. Features. Applications. Description. Low saturation voltage PNP transistor

SPC5-FLASHER. Flash management tool for SPC56xx family. Description. Features

AN2824 Application note

UM1676 User manual. Getting started with.net Micro Framework on the STM32F429 Discovery kit. Introduction

AN3252 Application note

AN2680 Application note

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

UM0985 User manual. Developing your STM32VLDISCOVERY application using the IAR Embedded Workbench software. Introduction

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

BD135 - BD136 BD139 - BD140

AN3353 Application note

AN4156 Application note

ULN2801A, ULN2802A, ULN2803A, ULN2804A

ESDLIN1524BJ. Transil, transient voltage surge suppressor diode for ESD protection. Features. Description SOD323

ETP01-xx21. Protection for Ethernet lines. Features. Description. Applications. Benefits. Complies with the following standards

AN3110 Application note

ULN2001, ULN2002 ULN2003, ULN2004

UM1613 User manual. 16-pin smartcard interface ST8034P demonstration board. Introduction

AN2557 Application note

MC Low noise quad operational amplifier. Features. Description

DSL01-xxxSC5. Secondary protection for DSL lines. Features. Description. Applications. Benefits. Complies with the following standards

AN3990 Application note

Description. Table 1. Device summary. Order code Temperature range Package Packaging Marking

LM135-LM235-LM335. Precision temperature sensors. Features. Description

Description. IO and RF AGC. ASIC controller and power management. Carrier recovery loop. GPIO switch matrix. Lock indicator and monitoring DVBS2 FEC

AN2866 Application note

ST19NP18-TPM-I2C. Trusted Platform Module (TPM) with I²C Interface. Features

LM337. Three-terminal adjustable negative voltage regulators. Features. Description

M24LRxx/CR95HF application software installation guide

BZW50. Transil, transient voltage surge suppressor (TVS) Features. Description

STEVAL-IEG001V2. Smart real-time vehicle tracking system. Features

AN3359 Application note

Order code Temperature range Package Packaging

UM1727 User manual. Getting started with STM32 Nucleo board software development tools. Introduction

How To Write To An Eeprom Memory On A Flash Memory On An Iphone Or Ipro Memory On Microsoft Flash Memory (Eeprom) On A Microsoft Microsoft Powerbook (Ai) 2.2.2

STTH2R06. High efficiency ultrafast diode. Features. Description

EN: This Datasheet is presented by the m anufacturer. Please v isit our website for pricing and availability at ore.hu.

Getting started with DfuSe USB device firmware upgrade STMicroelectronics extension

L78MxxAB L78MxxAC. Precision 500 ma regulators. Features. Description

UM1790 User manual. Getting started with STM32L053 discovery kit software development tools. Introduction

L6234. Three phase motor driver. Features. Description

STP60NF06. N-channel 60V Ω - 60A TO-220 STripFET II Power MOSFET. General features. Description. Internal schematic diagram.

SPC5-CRYP-LIB. SPC5 Software Cryptography Library. Description. Features. SHA-512 Random engine based on DRBG-AES-128

Description. Table 1. Device summary

UM1680 User manual. Getting started with STM32F429 Discovery software development tools. Introduction

STP60NF06FP. N-channel 60V Ω - 30A TO-220FP STripFET II Power MOSFET. General features. Description. Internal schematic diagram.

LM134-LM234-LM334. Three terminal adjustable current sources. Features. Description

STN3NF06L. N-channel 60 V, 0.07 Ω, 4 A, SOT-223 STripFET II Power MOSFET. Features. Application. Description

AN4128 Application note

TDA W CAR RADIO AUDIO AMPLIFIER

AN3270 Application note

UA741. General-purpose single operational amplifier. Features. Applications. Description. N DIP8 (plastic package)

AN974 APPLICATION NOTE

AN2760 Application note

Table 1. Absolute maximum ratings (T amb = 25 C) Symbol Parameter Value Unit. ISO C = 330 pf, R = 330 Ω : Contact discharge Air discharge

Description. Table 1. Device summary. Order codes. TO-220 (single gauge) TO-220 (double gauge) D²PAK (tape and reel) TO-220FP

STTH1R04-Y. Automotive ultrafast recovery diode. Features. Description

AN3155 Application note

P6KE. Transil, transient voltage surge suppressor (TVS) Features. Description. Complies with the following standards

STDP2690. Advanced DisplayPort to DisplayPort (dual mode) converter. Features. Applications

STP55NF06L STB55NF06L - STB55NF06L-1

TDA2004R W stereo amplifier for car radio. Features. Description

STGB10NB37LZ STGP10NB37LZ

AN4032 Application note

Description SO-8. series. Furthermore, in the 8-pin configuration Very low-dropout voltage (0.2 V typ.)

AN2703 Application note

AN4368 Application note

STCS A max constant current LED driver. Features. Applications. Description

AN3997 Application note

STCS1A. 1.5 A max constant current LED driver. Features. Applications. Description

STB75NF75 STP75NF75 - STP75NF75FP

STDP4328. DisplayPort 1.2a concentrator. Features. Applications

UM0834 User manual. Developing and debugging your STM8S-DISCOVERY application code. Introduction. Reference documents

UM1075 User manual. ST-LINK/V2 in-circuit debugger/programmer for STM8 and STM32. Introduction

VN05N. High side smart power solid state relay PENTAWATT. Features. Description

AN2328 Application note

LM2901. Low-power quad voltage comparator. Features. Description

STP10NK80ZFP STP10NK80Z - STW10NK80Z

STTH110. High voltage ultrafast rectifier. Description. Features

AN1819 APPLICATION NOTE Bad Block Management in Single Level Cell NAND Flash Memories

Obsolete Product(s) - Obsolete Product(s)

STDP4320. DisplayPort 1.2a splitter. Features. Applications

TN0072 Technical note

AN3969 Application note

NE555 SA555 - SE555. General-purpose single bipolar timers. Features. Description

AN2658 Application note

AN820 APPLICATION NOTE INPUT/OUTPUT PROTECTION FOR AUTOMOTIVE COMPUTER

STLM20. Ultra-low current 2.4 V precision analog temperature sensor. Features. Applications

Transcription:

Application note Generating PWM signals using STM8S-DISCOVERY Application overview This application user manual provides a short description of how to use the Timer 2 peripheral (TIM2) to generate three PWM signals. Even though the STM8S-DISCOVERY is built around an STM8S105C6T6, it allows evaluation of the main features of all the STM8S MCUs. Reference documents STM8S-DISCOVERY evaluation board user manual (UM0817). Developing and debugging STM8S-DISCOVERY application user manual (UM0834). January 2011 Doc ID 18399 Rev 1 1/7 www.st.com

Application description AN3332 1 Application description 1.1 Hardware requirement No additional hardware is required on the STM8S-DISCOVERY board. An oscilloscope is needed as an external resource. 1.2 Application schematics Figure 1. Application schematics 1.3 Application principle This application is based on the use of the STM8S TIM2 in PWM (pulse width modulation) mode to generate 3 PWM signals. The generation process is presented in Figure 2. 2/7 Doc ID 18399 Rev 1

Application description Figure 2. PWM generation principle Note: Table 1. TIM2 counts up from 0 to the Auto-reload register value (TIM2_ARR) according to the TIM2 counter clock. When the counter value equals the Compare/Capture register (TIM2_CCRxx) value channel x signal is set to 0. When the counter value reaches the TIM2_ARR value the counter is reset and channel x signal is set to 1. By configuring the TIM2_CCRxx and TIM2_ARR registers you can easily modify the duty cycle and frequency of the PWM signals generated (see Section 2: Software description). By default the application provides the 3 PWM signals as specified in Table 1. It is possible to configure the AFR option byte to get channel 3 on PD2 also. Default PWM signals Signal Duty cycle Frequency I/O pin Header connector Channel 1 PWM 50% 2 KHz PD4 CN4.9 Channel 2 PWM 25% 2 KHz PD3 CN4.8 Channel 3 PWM 75% 2 KHz PA3 CN1.9 Doc ID 18399 Rev 1 3/7

Software description AN3332 2 Software description This example uses the STM8S standard firmware library to control the general purpose functions. To generate the PWM signals the TIM2 peripheral must be configured as follows: Output state enabled for each channel Output compare active low for each channel Preload register enabled for each channel PWM output signal frequency = 2 KHz: The timer source clock frequency is 2 MHz (f CPU by default) and the prescaler is set to 1 to obtain a TIM2 counter clock of 2 MHz. PWM output signal frequency can be set according to the following equation: PWM output signal frequency = TIM2 counter clock/(tim2_arr + 1) (in our case TIM2_ARR = 999, so PWM output signal frequency is 2 KHz) PWM mode for each channel. To obtain a different PWM duty cycle value on each channel the TIM2_CCRxx register must be set according to this equation: Channel x duty cycle = [TIM2_CCRxx/(TIM2_ARR + 1)] * 100 By default we have: Channel 1: TIM2_CCR1x register value is 500, so channel 1 of TIM2 generates a PWM signal with a frequency of 2 KHz and a duty cycle of 50%. Channel 2: TIM2_CCR2x register value is 750, so channel 2 of TIM2 generates a PWM signal with a frequency of 2 KHz and a duty cycle of 75%. Channel 3: TIM2_CCR3x register value is 250, so channel 3 of TIM2 generates a PWM signal with a frequency of 2 KHz and a duty cycle of 25%. 2.1 STM8S standard firmware library configuration The stm8s_conf.h file of the STM8S standard firmware library is used to configure the library by enabling the peripheral functions used by the application. The following define statements must be present: #define _GPIO 1 enables the GPIOs #define _TIM2 1 enables the TIM2 4/7 Doc ID 18399 Rev 1

Software description 2.2 Application software flowcharts 2.2.1 Main loop flowchart Figure 3. Main loop flowchart Doc ID 18399 Rev 1 5/7

Revision history AN3332 3 Revision history Table 2. Document revision history Date Revision Changes 15-Jan-2011 1 Initial release. This document replaces UM0856. 6/7 Doc ID 18399 Rev 1

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. 2011 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 - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com Doc ID 18399 Rev 1 7/7