You are on page 1of 4

4/5/2015

HngdnlptrnhTimerviSTM32|EmbeddedSystem

Home
AllTopics

Forum
EmbeddedFirmware

searchthissite...

EmbeddedLinux

programminglanguage

Project

Categories

HOMEEMBEDDEDFIRMWAREHNGDNLPTRNHTIMERVISTM32

HngdnlptrnhTimerviSTM32

EmbeddedFirmware
0
EmbeddedLinux

ByPhamVanDong|Published:January17,2015

I.GiithiucbnvTimertrongSTM32

KnowlegeMCU

TimertrongSTM32crtnhiuchcnngchnghnnhbmcounter,PWM,input

programminglanguage

capturengoiracnmtschcnngtbitiukhinngcnhencoder,hall

Project

sensors.
Timerlbnhthicthsdngtorathigiancbndatrnccthngs:clock,

Qt/QMLC++

prescaler,autoreload,repetitioncounter.TimercaSTM32ltimer16bitscthtoracc
skintrongkhongthigiantnanogiytiviphtgilUEV(updateevent).
Ccthnhphncbncamttimerbaogm:

Findusonfacebook

EmbeddedSystem

TIM_CLK:clockcungcpchotimer.
PSC(prescaler):lthanhghi16bitslmbchiachotimer,cthchiat1ti65535

Thch

265ngithchEmbeddedSystem.

ARR(autoreloadregister):lgitrmcatimer(16bitshoc32bits).
RCR(repetitioncounterregister):gitrmlpli16bits.
GitrUEVctnhtheocngthcsau:
UEV=TIM_CLK/((PSC+1)*(ARR+1)*(RCR+1))

PluginxhicaFacebook

Vd:TIM_CLK=72MHz,PSC=1,ARR=65535,RCR=0.
UEV=72000000/((1+1)*(65535+1)*(1))=549.3Hz

FacebookMembersWordPressPlugin

VigitrARR(autoreload)ccungcpthbnhthi(timer)thchinccch
mkhcnhau:mln,mxunghockthpc2.Khithchinmlnthgitrb
mbtut0vmtigitrARR1thbotrn.Khithchinmxungthbm
VisitToday:14

btutgitrARRmxung1thbotrn.

VisitYesterday:25

CcchhotngcaTimer:

ThisMonth:125
TotalVisit:12109

Inputcapture

TotalHits:55436

Outputcompare

Who'sOnline:1

PWMgeneration(EdgeandCenteralignedmodes)
Onepulsemodeoutput
II.nhnghastructcuhnhchotimercbn:

RecentPosts
Projectmybayquadcoptervistm32

XydngngdngsmarthomeviQt/C++

typedefstruct
HngdnlptrnhPWMviSTM32
{
uint16_tTIM_Prescaler;/*!<SpecifiestheprescalervalueusedtodividetheTIMclock.

http://hethongnhung.com/huongdanlaptrinhtimervoistm32/

1/4

4/5/2015

HngdnlptrnhTimerviSTM32|EmbeddedSystem

Thisparametercanbeanumberbetween0x0000and0xFFFF*/

HngdnlptrnhTimerviSTM32

uint16_tTIM_CounterMode;/*!<Specifiesthecountermode.
HngdnlptrnhDMAviSTM32
Thisparametercanbeavalueof@refTIM_Counter_Mode*/
uint32_tTIM_Period;/*!<Specifiestheperiodvaluetobeloadedintotheactive
RecentComments
AutoReloadRegisteratthenextupdateevent.
Thisparametermustbeanumberbetween0x0000and0xFFFF.*/

lyhaiquanonCitopensshchokit
friendlyarmmini2440,tiny6410

uint16_tTIM_ClockDivision;/*!<Specifiestheclockdivision.
Thisparametercanbeavalueof@refTIM_Clock_Division_CKD*/

PhamVanDongonHngdnlptrnhdevice
drivercbn_Phn2

uint8_tTIM_RepetitionCounter;/*!<Specifiestherepetitioncountervalue.EachtimetheRCRdowncounter
reacheszero,anupdateeventisgeneratedandcountingrestarts
mig29onHngdnlptrnhdevicedriverc
fromtheRCRvalue(N).
bn_Phn2
ThismeansinPWMmodethat(N+1)correspondsto:
thenumberofPWMperiodsinedgealignedmode
thenumberofhalfPWMperiodincenteralignedmode
Thisparametermustbeanumberbetween0x00and0xFF.
@noteThisparameterisvalidonlyforTIM1andTIM8.*/
}TIM_TimeBaseInitTypeDef;

*Phntchcutrc:
TIM_Prescaler:ThamsTIM_Prescalerhiunginnhmtbchiatns.
VdSTM32F4Tnscaonhtmclocktimer4tcl84Mhzsaukhiquabchiany
sratnsclocktimer(Fc_timer).VvdchnFc_timer=1Mhz<=>Fc_timer=
84000000/84.VTIM_Prescalerccngthcl:((SystemCoreClock/2)/1000000)1=83,do
hmbtut0chkhngphil1nhchngtavnhaydngms,btumt
0>83sl84gitr.
TIM_Prescaler=((SystemCoreClock/n)/Fc_timer)1
*Notes:Tyvotimernomchschianskhcnhau.Vdtrongstm32f4gmc
nhngtimervhschiakhcnhaunhhnhbndi:

TIM_CounterMode:Thitlpmodechotimerlmlnhaymxung.Nuchnmode
mtngcnghalmixungnhptimer,bmcountersttnglnmtgitrtheochiu
dngchonkhinobnggitrperiodsmlitu,ngitathnggitrnghp
nyltrnbm.
TIM_Period:Periodcnghalchukcatimer(khngphilchukca1xungclock
timer).Vdmtchukgm1000xungclockmmixungclock=1ustascperiodl
1ms.Titricho1lvhmbtut0nhgiithchbntrn..
Notes:Khicuhnhsdngtimertacnquantmn3yutchnhl:
http://hethongnhung.com/huongdanlaptrinhtimervoistm32/

2/4

4/5/2015

HngdnlptrnhTimerviSTM32|EmbeddedSystem

+mvixungclocktimerlbaonhiu(Fc_timerxcnhquaTIM_Prescaler).
+mlnhaymxung(TIM_CounterMode).
+mnbaonhiu(TIM_Period).
III.Vd:
1.Vdcuhnhchotimer3trongstm32f1tointerruptvi100ms
*Phntch:(lu1giy=1msx1000)
Tnscaonhtmtimer3trongstm32f1tcl72Mhz.
Yucucntimer3tointerruptmi100ms.
Giscncountercatimerm100lnc100msvphtinterruptthtac:
>TnsFc_timer3=(100msx100clock)x10=10.000clock/1giy(10Khz).
Ktqu:
+TIM_Prescaler=(72000000/10.0001)//Fc_timerl10khz
+TIM_Period=100ln1=99
Giscncountertimerm1000lnc100msvphtinterruptthtngt:
>TnsFc_timer3=(100msx1000clock)x10=100.000clock/1giy(100Khz)
Ktqu:
+TIM_Prescaler=(72000000/100.0001)//Fc_timerl100khz
+TIM_Period=1000ln1=999
//Cuhnhccthngschotimer3vitrnghpperiod=99:
TIM_TimeBaseStructure.TIM_Period=99//delay10ms
TIM_TimeBaseStructure.TIM_Prescaler=(72000000/100001)//10khz
TIM_TimeBaseStructure.TIM_ClockDivision=0
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure)
Trongvdny,chnFc_timer3=10000(10khz)nghal:
>Tnstimer10.000xung/1giy<>10xung/1ms
>Tnscho10msl:100xung/10ms
2.Vdcuhnhchotimer4trongstm32f4tointerruptvimi1ms
*Phntch:
Tnscaonhtmmtimer4trongstm32f4tcl84Mhz
Yucucntimer4tointerruptmi1ms.
Giscncountercatimerm100lnc1msvphtinterruptthtac:
>TnsFc_timer4=(1msx100clock)x1000=100.000clock/1giy(100Khz).
Ktqu:
+TIM_Prescaler=(84000000/100.0001)//Fc_timerl100khz
+TIM_Period=100ln1=99
Giscncountertimerm1000lnc1msvphtinterruptthtngt:
>TnsFc_timer4=(1msx1000clock)x1000=1000.000clock/1giy(1Mhz)
Ktqu:
+TIM_Prescaler=(72000000/1000.0001)//Fc_timerl1Mhz
http://hethongnhung.com/huongdanlaptrinhtimervoistm32/

3/4

4/5/2015

HngdnlptrnhTimerviSTM32|EmbeddedSystem

+TIM_Period=1000ln1=999
//Cuhnhccthngschotimer4vitrnghpperiod=999:
TIM_TimeBaseStructure.TIM_Prescaler=((SystemCoreClock/2)/1000000)1//f=1Mhz
TIM_TimeBaseStructure.TIM_Period=10001
TIM_TimeBaseStructure.TIM_ClockDivision=0
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up
TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure)
*Trnghptimer4trongstm32f4,period=999
Yucum1000xungcinterrupt1msth1xungstngngvi1us
HschiaTIM_Prescaler=1.000.000trongkhixunghthngcpl84.000.000domi
xungcaclocktimersbng84xungcasystemclock.
Comments
0comments
Vitbnhlun
CngnglnFacebook

ngvitcchlHoangLienSon

Bnhlun

PluginxhicaFacebook

PhamVanDong
ViewallpostsbyPhamVanDong

Nocommentsyet.

LeaveaComment
Name(Required)
Mail(willnotbepublished)(Required)
Website

SubmitComment

2015EmbeddedSystem.Allrightsreserved.

SiteAdmin

ReturntoTop

http://hethongnhung.com/huongdanlaptrinhtimervoistm32/

designedbylinhdong24

4/4