AN1504 APPLICATION NOTE

Similar documents
AN974 APPLICATION NOTE

AN3332 Application note

HANDLING SUSPEND MODE ON A USB MOUSE

AN1754 APPLICATION NOTE

AN438 APPLICATION NOTE SAFETY PRECAUTIONS FOR DEVELOPMENT TOOL TRIAC + MICROCONTROLLER

AN2680 Application note

AN2604 Application note

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

AN3265 Application note

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

L297 STEPPER MOTOR CONTROLLERS

AN3252 Application note

Obsolete Product(s) - Obsolete Product(s)

AN820 APPLICATION NOTE INPUT/OUTPUT PROTECTION FOR AUTOMOTIVE COMPUTER

AN886 APPLICATION NOTE

AN2389 Application note

AN2146 APPLICATION NOTE

LM833 LOW NOISE DUAL OPERATIONAL AMPLIFIER

AN3998 Application note

L4940 series VERY LOW DROP 1.5 A REGULATORS

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

TN0023 Technical note

UM0109 USER MANUAL. Public Transport Ticketing Demo

HCF4028B BCD TO DECIMAL DECODER

TDA2822 DUAL POWER AMPLIFIER SUPPLY VOLTAGE DOWN TO 3 V LOW CROSSOVER DISTORSION LOW QUIESCENT CURRENT BRIDGE OR STEREO CONFIGURATION

TDA4605 CONTROL CIRCUIT FOR SWITCH MODE POWER SUPPLIES USING MOS TRANSISTORS

HCF4056B BCD TO 7 SEGMENT DECODER /DRIVER WITH STROBED LATCH FUNCTION

HCF4001B QUAD 2-INPUT NOR GATE

STGW40NC60V N-CHANNEL 50A - 600V - TO-247 Very Fast PowerMESH IGBT

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

HCF4081B QUAD 2 INPUT AND GATE

DRIVE CIRCUITS FOR POWER MOSFETs AND IGBTs

AN3155 Application note

DDSL01. Secondary protection for DSL lines. Features. Description

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

AN2866 Application note

TDA CHANNEL VOLUME CONTROLLER 1 FEATURES 2 DESCRIPTION. Figure 1. Package

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

AN ISOLATED GATE DRIVE FOR POWER MOSFETs AND IGBTs

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

AN3270 Application note

HCF4010B HEX BUFFER/CONVERTER (NON INVERTING)

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

HCF4070B QUAD EXCLUSIVE OR GATE

AN1826 APPLICATION NOTE TRANSIENT PROTECTION SOLUTIONS: Transil diode versus Varistor

AN3353 Application note

AN2824 Application note

STW34NB20 N-CHANNEL 200V Ω - 34A TO-247 PowerMESH MOSFET

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

LF00AB/C SERIES VERY LOW DROP VOLTAGE REGULATORS WITH INHIBIT

AN2760 Application note

AN3354 Application note

STP80NF55-08 STB80NF55-08 STB80NF N-CHANNEL 55V Ω - 80A D2PAK/I2PAK/TO-220 STripFET II POWER MOSFET

ADJUSTABLE VOLTAGE AND CURRENT REGULATOR

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

STW20NM50 N-CHANNEL Tjmax Ω - 20ATO-247 MDmesh MOSFET

CLASS-D VERTICAL DEFLECTION AMPLIFIER FOR TV AND MONITOR APPLICATION OUT CFLY + CFLY - BOOT VREG FEEDCAP FREQ. July /8

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

ST202 5V POWERED MULTI-CHANNEL RS-232 DRIVERS AND RECEIVERS

HCC4541B HCF4541B PROGRAMMABLE TIMER

TL074 TL074A - TL074B

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

ULN2801A, ULN2802A, ULN2803A, ULN2804A

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

Description. Table 1. Device summary

TOPOLOGIES FOR SWITCHED MODE POWER SUPPLIES

SG2525A SG3525A REGULATING PULSE WIDTH MODULATORS

IRF740 N-CHANNEL 400V Ω - 10A TO-220 PowerMESH II MOSFET

.OPERATING SUPPLY VOLTAGE UP TO 46 V

Symbol Parameter Value Unit V DS Drain-source Voltage (V GS =0) 50 V V DGR Drain- gate Voltage (R GS =20kΩ) 50 V

AN4108 Application note

VNP5N07 "OMNIFET": FULLY AUTOPROTECTED POWER MOSFET

BTB04-600SL STANDARD 4A TRIAC MAIN FEATURES

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

STP62NS04Z N-CHANNEL CLAMPED 12.5mΩ - 62A TO-220 FULLY PROTECTED MESH OVERLAY MOSFET

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

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

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

SWITCH-MODE POWER SUPPLY CONTROLLER PULSE OUTPUT DC OUTPUT GROUND EXTERNAL FUNCTION SIMULATION ZERO CROSSING INPUT CONTROL EXTERNAL FUNCTION

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

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

AN4646 Application note

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

TL084 TL084A - TL084B

BD135 - BD136 BD139 - BD140

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

What is the difference between an equivalent time sampling oscilloscope and a real-time oscilloscope?

BUX48/48A BUV48A/V48AFI

TDA W CAR RADIO AUDIO AMPLIFIER

M24LRxx/CR95HF application software installation guide

MC Low noise quad operational amplifier. Features. Description

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

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

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

Symbol Parameter Value Unit V i-o Input-output Differential Voltage 40 V I O Output Current Intenrally Limited Top

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

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

AN2557 Application note

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

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

Transcription:

AN1504 APPLICATION NOTE STARTING A PWM SIGNAL DIRECTLY AT HIGH LEVEL USING THE ST7 16-BIT TIMER by Microcontroller Division Applications INTRODUCTION The 16-bit timer is a standard peripheral of the ST7 microcontroller family. This peripheral can be used for a variety of purposes, including pulse length measurement of up to two input signals (input capture feature) or generation of up to two output waveforms (output compare and PWM mode). This application note is about using the PWM mode of the standard 16 bit timer. It explains how to synchronize the PWM signal output. In other words, how to make sure it outputs a high state when the counter restarts after it has been stopped (for any reason) or simply when it starts at the beginning of the application. In some applications, like motor control, it may be essential to output the high level part of the signal duty cycle when the counter is started. AN1504/0302 1/9 1

1 16-BIT TIMER PWM MODE 1.1 DESCRIPTION In pulse width modulation mode, the frequency of the signal is determined by the value in Output Compare 2 register (OC2R) and the pulse length by the value in the Output Compare 1 register (OCR1) or duty cycle value. The OLVL2 bit selects the level to be applied to the output pin after a successful comparison between the counter and the OC2R register and the OLVL1 bit selects the level to be applied on the output after a successful comparison between the counter and the OC1R register 1.2 NORMAL BEHAVIOUR Figure 1 shows the normal behaviour of output compare 1 (OCMP1) pin when a PWM signal is output with OLVL2=1 and OLVL1=0. Figure 1. PWM output when OLVL2=1 and OLVL1=0 FREE RUNNING COUNTER VALUE Tmax = Ttimer 65535 FFFFh FFFCh OC2R OC1R 0000h time OCMP1 Ouput Compare pin Timer output OLVL1=0 OLVL2= 1 time When the counter reaches the OC2R register value, the value of OLVL2 is applied on the OCMP1 pin (=1 in this case). When the counter reaches the value of the OC1R register, the value of OLVL1 is applied on the OCMP1 pin (=0). The formulas needed to compute the values to be put in OC2R and OC1R registers are in the 16-bit Timer chapter of the ST7 datasheets. As the 16-bit Timer is reset at FFFC, the formulas are: OCiR=((t*Fcpu)/presc)-5 where: t= period of the signal 2/9 2

Fcpu= CPU frequency presc= Timer 16 presc Figure 2 shows the waveforms we see on an oscilloscope if the PWM signal is initialized at 10KHz with a 50% duty cycle (OLVL2=1 and OLVL1=0) and if a flag is set as soon as the counter is started. Figure 2. OCMP1 waveform with 50% Duty Cycle PWM OUTPUT Timer 16 start output enabled flag We can see from this figure that we have to wait until the counter reaches the OC2R register value to get the first high state on the OCMP1 pin. So we have lost one PWM cycle before getting the first high level and in some applications, like energizing motor windings, this is not acceptable. After a motor demagnetization phase, if the windings are not energized immediately when the PWM is started, the motor can stall. The purpose of the following sections is to explain how to get a high level on OCMP1 pin immediately. To solve the problem, we have to handle two cases. 1. The PWM signal is high when the timer is between FFFC (its reset value) and the OC1R register value. This means OLVL1=0 and OLVL2=1. 2. The PWM signal is high when the timer is between the OC1R register value and the OC2R register value. This means OLVL1=1 and OLVL2=0. 3/9

2 FIRST CASE: OLVL2=1 AND OLVL1=0 In this case, to force a high state on the OCMP1 pin when the timer is started: Initialize the timer in PWM mode and set the PWM frequency with a 0% duty cycle Reset the timer (at FFFC) Load the OC1R register with a value close to FFFC (FFFD for example) and configure OLVL1=1 and OLVL2=0. Start the timer. It immediately reaches the value of the OC1R register and OCMP1 pin goes into the state defined by the OLVL1 bit, which is high. Then, write the correct duty cycle value in the OC1R register and the correct state in the OLVL2 and OLVL1 bits (OLVL2=1 and OLVL1=0). The following code gives an example of how to restart (or start) the 16-bit timer this way. This is for Timer A already initialized in PWM mode at 10KHz with the 16-bit timer clocked at 1MHz (TACR2=10011000, TAOC2HR=$00 and TAOC2LR=$5F for 10KHz at 1MHz clock. This is how to calculate the values to be put in the registers: OC2R represents the signal period. The frequency is 10KHz, so the period is t=100µs. f CPU is 8MHz and the Timer prescaler is 8 because the Timer is at 1MHz. OC2R=((t*Fcpu)/presc)-5=((100.10-6*8.10+6)/8)-5=95 (005F in hexadecimal). OC1R represents the pulse length, the duty cycle is 50% so the pulse length is 100µs*50%=50µs. So the value to be put in OC1R is: OC1R=((50.10-6*8.10+6)/8)-5=45 (002D in hexadecimal). Note: This method can be applied when the counter is first started as the starting value is 0000. Initialization: In this example the duty cycle is first set to 0% with OLVL1=0 and OLVL2=0 ld A,#%00000000; set OLVL1=0 and OLVL2=0 ld TACR1,A ld A,#%10011000; clock in/8=1mhz with 16 MHz quartz ld TACR2,A ld TAOC2HR,A ;10KHz frequency for the PWM signal (see formulas) ld A,#$5F ld TAOC2LR,A Synchronization ld A,#%00000001;Set OLVL1=1 and OLVL2=0 ld TACR1,A ;load corresponding control register 1 ld A,#$FF ld TAOC1HR,A ;fix compare 1 to FFFD to force PWM high as soon as possible ld A,#$FD 4/9

ld TAOC1LR,A clr TACLR ;reset timer B to FFFC bset PADR,#2 ;set flag synchronisation of timer B.wait_TA_C2 ld A,TACHR jrne wait_ta_c2;wait timer A=0000 to restore duty cycle ld A,#%00000100 ld TACR1,A ;set OLVL1=0 and OLVL2=1 ld TAOC1HR,A ld A,#$2D ;restore duty cycle to 50% ld TAOC1LR,A bres PADR,#2 ;reset synchronisation flag Figure 3 shows the waveforms seen on an oscilloscope for OCMP1 pin and the synchronization flag using the above software example when the 16-bit timer is started or restarted. Figure 3. OCMP1 and synchronization flag : OLVL2=1 and OLVL1=0 PWM OUTPUT Timer 16 start output enabled flag We can see in Figure 3 that the OCMP1 pin outputs a high state directly after starting the PWM signal. This avoids losing a PWM cycle in applications where an immediate high state is required. 5/9

3 SECOND CASE: AND OLVL1=1 AND OLVL2=0 Figure 4. PWM output when OLVL2=0 OLVL1=1 FREE RUNNING COUNTER VALUE Tmax = Ttimer 65535 FFFFh FFFCh OC2R OC1R 0000h time OCMP1 Ouput Compare pin Timer output OLVL1=1 OLVL2= 0 time In this case, the timer A is also initialized at 10KHz with a 1MHz timer clock. We can see that when OLVL2=0 and OLVL1=1, to set the duty cycle value, the OC1R register has to be loaded with the complementary value= compare 2-(the normal value of Compare 1 in the Case 1 example). So for example, with a 10KHz PWM signal with a 1MHz timer clock, we have OC2R register =005F (see formulas) and so for 20% duty cycle, the normal value of the OC1R register is: OC1R=((20.10-6*8.10+6)/8))-5=15 (000F in hexadecimal) The complementary value is then OC1R=005F-000F=0050 in hexadecimal. For the initialization phase, we need to set a 0% duty cycle and in this case, instead of configuring OLVL2=OLVL1=0 we can simply put a higher value in the OC1R register than in the OC2R register. This following code example is for a 20% duty cycle signal. Initialization: Set up 10KHz PWM signal with OLVL2=0 and OLVL1=1 and 0% duty cycle ld A,#%00000001; set OLVL1=1 and OLVL2=0 ld TACR1,A ld A,#%10011000;Clock in/8: 1MHz with 16 MHz quartz ld TACR2,A ld A,TAOC2HR ;compare 2 of timer A set 005F=100-5=95 ld A,#$5F ld TAOC2LR,A ;frequency set to 10KHz 6/9

ld TAOC1HR,A ld A,#$60 ld TAOC1LR,A ; set 0% duty cycle by compare 1 value > compare 2 value After this initialization, the PWM synchronization at start is done by putting a value into the compare register that is just higher than the timer restart value. Synchronization: ld X,#$FF ;set compare 1 to FFFD just after the timer reset value FFFC ld TAOC1HR,X ;to force the output PWM high just after restart ld A,#$FD ld TAOC1LR,A add A,#$0F ;ld compare 2 with compare 1+20% duty (000F) ld Y,A ld A,X adc A,#$00 ld TAOC2HR,A ld TAOC2LR,Y clr TACLR ;reset timer A to FFFC bset PADR,#2 ;set synchronization flag of timer A.wait_TA_C1 ld A,TACHR jrne wait_ta_c1;wait timer A counter=0000 to restore compare 1 ld TAOC1HR,A ld A,#$50 ld TAOC1LR,A ;restore compare 1 to 20% (compare 2*(1-20%)).wait_TA_C2 btjf TACHR,#7,wait_TA_C2;wait for reset of timer A before restoring compare 2 value ld TAOC2HR,A ld A,#$5F ;restore compare 2 to 10KHz=100-5=95 (see formulas) ld TAOC2LR,A bres PADR,#2 ;reset synchronization flag of timer B 7/9

Figure 5. OCMP1 and flag : timer restart between compare 1 and compare 2 PWM OUTPUT Timer 16 start output enabled flag We can see on this figure that the OCMP1 pin outputs a high state immediately after starting the PWM signal with the 16 bit timer. This will avoid wasting PWM cycle for applications where an immediate high state is needed. 8/9

THE PRESENT NOTE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH A NOTE AND/OR THE USE MADE BY CUSTOMERS OF THE INFORMATION CONTAINED HEREIN IN CONNEXION WITH THEIR PRODUCTS. Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as critical components in life support devices or systems without the express written approval of STMicroelectronics. The ST logo is a registered trademark of STMicroelectronics 2002 STMicroelectronics - All Rights Reserved. Purchase of I 2 C Components by STMicroelectronics conveys a license under the Philips I 2 C Patent. Rights to use these components in an I 2 C system is granted provided that the system conforms to the I 2 C Standard Specification as defined by Philips. STMicroelectronics Group of Companies Australia - Brazil - Canada - China - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - U.S.A. http://www.st.com 9/9