msp430 ti套件lm3slib pwm第1章脈沖寬度調(diào)制_第1頁
msp430 ti套件lm3slib pwm第1章脈沖寬度調(diào)制_第2頁
msp430 ti套件lm3slib pwm第1章脈沖寬度調(diào)制_第3頁
msp430 ti套件lm3slib pwm第1章脈沖寬度調(diào)制_第4頁
msp430 ti套件lm3slib pwm第1章脈沖寬度調(diào)制_第5頁
已閱讀5頁,還剩22頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

( 函數(shù)voidPWMGenConfigure(nsigedlongulBase,nsigedlonulGen,nsigedlonguC5voidPWMGenPeriodSet(nsigedlongulBase,nsigedlonulGen,nsigedlonguP6nsigedlongPWMGenPeriodGet(nsigedlongulBase,nsiged 7voidPWMPulseWidthSet(nsigedlongulBase,nsigedlonguPWMOut,nsigedlongl7nsigedlongPWMPulseWidthGet(nsigedlongulBase,nsigedlonguP7voidPWMGenEnable(nsigedlongulBase,nsiged 8voidPWMGenDisable(nsigedlongulBase,nsiged 8voidPWMDeadBandEnable(nsiged nsiged nsigndshort nsigndshortuFall8voidPWMDeadBandDisable(nsigedlongulBase,nsiged 9voidPWMSyncUpdate(nsigedlongulBase,nsigedlongule9voidPWMSyncTimeBase(nsigedlongulBase,nsigedlongulenvoidPWMOutputState(nsigedlongulBase,nsigedlongulPWMutBits,BooleanEnvoidPWMOutputInvert(nsigedlongulBase,nsigedlongulPWMutBits,BooleanInvoidPWMOutputFaultLevel(nsiged nsigedlongulPWM BooleanbDrveigh)voidPWMOutputFault(nsiged nsigedlongulPWM BooleanbFaultSppess)voidPWMGenIntRegister(nsigedlongulBase,nsigedlonulGn,void(*pfnIntHandler(vvoidPWMGenIntUnregister(nsigedlongulBase,nsigedlonuvoidPWMGenIntTrigEnable(nsigedlongulBase,nsigedlonulGen,nsigedlongulntvoidPWMGenIntTrigDisable(nsigedlongulBase,nsigedlonulGen,nsigedlongulntnsigedlongPWMGenIntStatus(nsigedlongulBase,nsigedlonulGen,BooleanMavoidPWMGenIntClear(nsigedlongulBase,nsigedlonulGen,nsigedlongulvoidPWMGenFaultConfigure(nsigednsigednsigedlongulMinFaulnsigedlongulFaulSeses)voidPWMGenFaultTriggerSet(nsigednsigedlonnsigedlongnsigedlongulFaultTignsigedlongPWMGenFaultTriggerGet(nsigednsigednsigedlonglGunsignedlongPWMGenFaultStatus(unsignedlongunsignedlongulGen,voidPWMGenFaultClear(unsignedlongunsignedlongunsignedlongulGroup,voidPWMFaultIntRegister(unsignedlongulBase,voidvoidPWMFaultIntUnregister(unsignedlongvoidPWMFaultIntClear(unsignedlongvoidPWMFaultIntClearExt(unsignedlongulBase,unsignedlongvoidPWMIntEnable(unsignedlongulBase,unsignedlongvoidPWMIntDisable(unsignedlongulBase,unsignedlongunsignedlongPWMIntStatus(unsignedlongulBase,tBooleanPWMPWMModulation器來產(chǎn)生方波,并且可以通過調(diào)整方波的占空比來對模擬信號電平進行編碼。PWM通常使StellarisARM4PWMPWM發(fā)生器模1個定時器(16位遞減或先遞增后遞減計數(shù)器、2個比較器、1PWM信號發(fā)生器、1個死區(qū)發(fā)生器,以及一個中斷/ADCPWM信號的極PWMPWMPWM信號可以是獨立的信號(基于同一定時器因而頻率相同的獨立信號除外),也可以是一對插入了死區(qū)延遲的互補StellarisPWMPWM信號,如簡易充電泵需要的信號;也可以產(chǎn)生帶死區(qū)延遲的成對PWM信號,如半-H橋(half-HStellarisARMPWMPWM發(fā)生器運作時,定時器在不斷計數(shù)并和兩個比較器的值進行比較,可以在和比較器16PWM1.11.1PWMD/A1.2PWMPWM定時器有兩種工作模式:遞減計數(shù)模式或先遞增后遞減計數(shù)模式。在遞減計數(shù)模PWM信號,而先遞增后遞減計數(shù)模式是用來產(chǎn)生中心對齊的PWM信號。PWM3PWM信號的過程中使用。一個是方向信平之間切換0時,零脈沖信號發(fā)PWMPWM信號的過程中使用。如果任一比較器的值大于計數(shù)器的裝載值,則該比較器永遠不會左對齊的一對PWM波形。1.3左對齊PWM1.4中心對齊PWMbridge1.5PWM運行(即令PWM輸出無效,以避免其長時間處于危險的運行狀態(tài)。FaultPWM信號輸PWM5種信號:zero、load、dir、cmpA、cmpB都可以觸發(fā)中斷,或者觸發(fā)ADC轉(zhuǎn)換。使控制非常靈活。PWMGenConfigure()PWM發(fā)生器模式進行設置,包括定時器的計數(shù)模()PWMPulseWidthSet(PWMPWMPWMGenPeriodSet()里設置的值,也就是占空比不能大于100%。調(diào)用函數(shù)PWMGenEnablePWMPWM發(fā)送器的定時器開始運作。反之函數(shù)PWMGenDisable()則禁止PWM定時器運作。1.1PWMGenConfigure(voidPWMGenConfigure(unsignedlongulBase,unsignedlongulGen,unsignedlongulBase:PWMulGen:PWM // //發(fā)生器不同步模式PWM_GEN_MODE_GEN_SYNC_LOCAL//發(fā)生器局部同步模式PWM_GEN_MODE_GEN_SYNC_GLOBAL//全局發(fā)生器同步模式 //不同步 //局部同步PWM_GEN_MODE_DB_SYNC_GLOBAL//全局發(fā)生器同步模式 PWM_GEN_MODE_FAULT_UNLATCHED// //PWM_GEN_MODE_FAULT_NO_MINPER// //Fault0 //PWMnFLTSRC0無1.2PWMGenPeriodSetvoidPWMGenPeriodSet(unsignedlongulBase,unsignedlongulGen,unsignedlongulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:無1.3PWMGenPeriodGetunsignedlongPWMGenPeriodGet(unsignedlongulBase,unsignedlongulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:1.4PWMPulseWidthSet(voidPWMPulseWidthSet(unsignedlongulBase,unsignedlongulPWMOut,unsignedlongulBase:PWM端口的基址,取值PWM_Base PWM的高電平寬度,寬度值是PWM無1.5PWMPulseWidthGet(unsignedlongPWMPulseWidthGet(unsignedlongulBase,unsignedlongulBase:PWM端口的基址,取值PWM_Base PWM的高電平寬度,寬度值是PWM計數(shù)器的計時時鐘數(shù),類型為unsignedlong1.6PWMGenEnable(voidPWMGenEnable(unsignedlongulBase,unsignedlongulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:無1.7PWMGenDisable(voidPWMGenDisable(unsignedlongulBase,unsignedlongulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:無PWMDeadBandEnablePWM發(fā)生器的死區(qū)時間,并打開死區(qū)功能,脈沖個數(shù)。調(diào)用該函數(shù)配置好后,PWMPWM就是一對帶死區(qū)的反相的1.8PWMDeadBandEnable(voidPWMDeadBandEnable(unsignedlongunsignedlongulGen,unsignedshortunsignedshortulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:無1.9PWMDeadBandDisable(voidPWMDeadBandDisable(unsignedlongulBase,unsignedlongulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:無PWMSyncUpdate(PWM發(fā)生器所掛起的PWMSyncTimeBasePWMPWM發(fā)生器1.10PWMSyncUpdate(voidPWMSyncUpdate(unsignedlongulBase,unsignedlong 無1.11PWMSyncTimeBase(voidPWMSyncTimeBase(unsignedlongulBase,unsignedlong 無PWMOutputState()8PWMPWM發(fā)生器產(chǎn)生的PWM信號是否輸出到管腳的最后一個開關(guān)。果bInvert為1,則反相PWM信號。PWMOutputFaultLevel()PWM的故障狀態(tài)時,PWM管腳的默認輸出1.12PWMOutputState(voidPWMOutputState(unsignedlongulBase,unsignedlongulPWMOutBits,tBoolean PWM端口的基址,取值PWM_Base 無1.13PWMOutputInvert(voidPWMOutputInvert(unsignedlongulBase,unsignedlongulPWMOutBits,tBoolean PWM端口的基址,取值PWM_Base 無1.14PWMOutputFaultLevelvoidPWMOutputFaultLevel(unsignedlongtBooleanbDriveHigh) PWM端口的基址,取值PWM_Base 無1.15PWMOutputFault(voidPWMOutputFault(unsignedlongtBooleanbFaultSuppress) PWM端口的基址,取值PWM_Base //故障時輸出PWMOutputFaultLevel() 無PWM發(fā)生器有豐富的中斷和觸發(fā)源,能在很多時刻產(chǎn)生中斷,使中斷變得非常靈活。對應的函數(shù)PWMGenIntUnregister()對已注冊的PWM發(fā)生器中斷函數(shù)注銷。PWMGenIntTrigEnableADC的事件進行使能,通過使能的ADCulIntTrig126個是中斷的時間,6個是ADC觸發(fā)時間。在遞減計數(shù)時,只有8個事件是有效的。PWMGenIntTrigDisable()對觸發(fā)事件進行禁能。起作用和上面的函數(shù)PWMGenIntTrigEnable()相反。PWMGenIntClear用來清除指定的中斷狀態(tài),應該在進入中斷服務函數(shù)中,在獲1.16PWMGenIntRegister(注冊一個指定PWMvoidPWMGenIntRegister(unsignedlongulBase,unsignedlongulGen,voidulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:無1.17PWMGenIntUnregister(voidPWMGenIntUnregister(unsignedlongulBase,unsignedlongulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:無1.18PWMGenIntTrigEnable(voidPWMGenIntTrigEnable(unsignedlongulBase,unsignedlongulGen,unsignedlongulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:ulIntTrig:PWM發(fā)生器的中斷和觸發(fā)事件選擇,取下列值的邏輯或: //計數(shù)器為0時,觸發(fā)中斷 //計數(shù)器為裝載值時,觸發(fā)中斷 //比較器A遞增匹配時,觸發(fā)中斷 //比較器A遞減匹配時,觸發(fā)中斷 //比較器B遞增匹配時,觸發(fā)中斷 //比較器B遞減匹配時,觸發(fā)中斷 //計數(shù)器為0時,觸發(fā)ADC //計數(shù)器為裝載值時,觸發(fā)ADC //比較器A遞增匹配時,觸發(fā)ADC //比較器A遞減匹配時,觸發(fā)ADC //比較器B遞增匹配時,觸發(fā) 比較器B無1.19PWMGenIntTrigDisable(voidPWMGenIntTrigDisable(unsignedlongulBase,unsignedlongulGen,unsignedlongulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:ulIntTrig:PWM發(fā)生器的中斷和觸發(fā)事件選擇,取下列值的邏輯或: //計數(shù)器為0時,觸發(fā)中斷 //計數(shù)器為裝載值時,觸發(fā)中斷 //比較器A遞增匹配時,觸發(fā)中斷 //比較器A遞減匹配時,觸發(fā)中斷 //比較器B遞增匹配時,觸發(fā)中斷 //比較器B遞減匹配時,觸發(fā)中斷 //計數(shù)器為0時,觸發(fā)ADC //計數(shù)器為裝載值時,觸發(fā)ADC //比較器A遞增匹配時,觸發(fā)ADC //比較器A遞減匹配時,觸發(fā)ADC //比較器B遞增匹配時,觸發(fā) 比較器B無1.20PWMGenIntStatus(unsignedlongPWMGenIntStatus(unsignedlongulBase,unsignedlongulGen,tBooleanulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一: 1.21PWMGenIntClear(voidPWMGenIntClear(unsignedlongulBase,unsignedlongulGen,unsignedlongulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一: //計數(shù)器為0觸發(fā)的中斷 //計數(shù)器為裝載值觸發(fā)的中斷 //比較器A遞增匹配觸發(fā)的中斷 //比較器A遞減匹配觸發(fā)的中斷 //比較器B遞增匹配觸發(fā)的中 比較器B無PWMGenFaultConfigure(PWM發(fā)生器的故障檢測管腳電平和最小故障PWMGenConfigure()PWM_GEN_MODE_FAULT_函數(shù)PWMGenFaultTriggerSet()用來選擇用哪些Fault引腳作為指定的PWM發(fā)生器的錯PWMGenFaultTriggerGet(Fault1.22PWMGenFaultConfigure(voidPWMGenFaultConfigure(unsignedlongunsignedlongunsignedlongulFaultSenses)ulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:ulMinFaultPeriod:最小故障激活保持時長,PWM 無1.23PWMGenFaultTriggerSet(voidPWMGenFaultTriggerSet(unsignedlongunsignedlongunsignedlongulGroup,ulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:ulFaultTriggers:定義指定的PWM發(fā)生器使用哪個故障輸入作為觸發(fā)端,對于無1.24PWMGenFaultTriggerGetnsignedlongPWMGenFaultTriggerGet(unsignedlongunsignedlongulGen,ulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:1.25PWMGenFaultStatus(unsignedlongPWMGenFaultStatus(unsignedlongunsignedlongulGen,ulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:1.26PWMGenFaultClear(voidPWMGenFaultClear(unsignedlongunsignedlongunsignedlongulGroup,ulBase:PWM端口的基址,取值PWM_BaseulGen:PWM發(fā)生器的編號,取下列值之一:無)建議使用PWMFaultIntClearExt()。)1.27PWMFaultIntRegistervoidPWMFaultIntRegister(unsignedlongulBase,void 無1.28PWMFaultIntUnregistervoidPWMFaultIntUnregister(unsignedlongulBase:PWM無1.29PWMFaultIntClearvoidPWMFaultIntClear(unsignedlongulBase:PWM無1.30PWMFaultIntClearExt(voidPWMFaultIntClearExt(unsignedlongulBase,unsignedlongulBase:PWM端口的基址,取值PWM_Base無PWMIntEnable(PWM發(fā)生器的中斷和故障中斷。PWMIntDisable()1.31PWMIntEnable(voidPWMIntEnable(unsignedlongulBase,unsignedlongulBase:PWM端口的基址,取值PWM_Base無1.32PWMIntDisable(voidPWMIntDisable(unsignedlongulBase,unsignedlongulBase:PWM端口的基址,取值PWM_Base1.33PWMIntStatus(unsignedlongPWMIntStatus(unsignedlongulBase,tBoolean 端口的基址,取值 PWM1.1產(chǎn)生兩路簡單#include"hw_types.h"#include"sysctl.h"#include"gpioh"#include"pwm#define#definePH1_PWM3#defineKEY_PERIPH#defineKEY_PORT#defineintmain{SYSCTL_USE_OSC|SYSCTL_OSC_MAIN/*8MHz外部晶振作為主時鐘SysCtlPeripheralEnable/*使能KEYGPIO/*設置KEYif(GPIOPinRead(KEY_PORT,KEY_PIN)=={for}/*若復位時按下KEY/*PWM/*PWMPWM_GEN_MODE_UP_DOWNPWM_GEN_MODE_UP_DOWN|PWMGenPeriodSet(PWM_BASE,PWM_GEN_1,PWMPulseWidthSet(PWM_BASE,PWM_OUT_2,PWMPulseWidthSet(PWM_BASE,PWM_OUT_3,/*設置PWM發(fā)生器1/*PWM2/*PWM3PWMOutputState(PWM_BASE,(PWM_OUT_2_BIT|PWM_OUT_3_BIT),/*PWM2和PWM3PWMGenEnable(PWM_BASE,/*PWM/*開始產(chǎn)生PWM沿延時10μs。1.2帶死區(qū)PWMSysCtlPeripheralEnable使能KEYGPIO設置KEY/*設置PWM2輸出的脈沖寬 /*使能PWM死區(qū),并設置死區(qū)延 設置上升沿延時設置下降沿延時PWM_OUT_2_BIT|PWM2和PWM3開始產(chǎn)生PWMfor(;;)}1.3PWM#include"hw_types.h"#include"hw_ints.h"#include"interrupth"#include"sysctl.h"#include"gpioh"#include"pwmintmain{SysCtlClockSet(SYSCTL_SYSDIV_1| /*8MHz外部晶振作為主時鐘*/SYSCTL_USE_OSC|SYSCTL_OSC_MAIN|SysCtlPeripheralEnable /*使能KEY所在的GPIO端 /*設置KEY所在管腳為輸 if(GPIOPinRead(KEY_PORT,KEY_PIN)== /*若復位時按下KEY,則進 {for /*死循環(huán),以等待JTAG連 } /*使能PWM2和PWM3輸出所在GPIO*/ /*使能PWM模塊 /*PWM時鐘配置:不分頻GPIOPinTypePWM(GPIO_PORTH_BASE,GPIO_PIN_0);/*PH0和PH1配置為PWM功能*/PWM

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論