?? pwm.c
字號:
/*********************************************************************/
/* PWM_Init.c ------------ Hardware related functions
PWM_Init();
PWM Initialization rounte
**********************************************************************/
void PWM_Init(void) {
PWME=0xFA; // PWM Enable Register each bit figure the each channels to enable PWM
/**The function of PWME is enable that eight channel of PWM,if the relative bit is seted,the relative channel will enable to PWM function**/
/**PWME功能為使能8個PWM通道,PWME的每個位對應一個通道,相對位置一的時候就使能相對通道**/
PWMPOL=0x00; // PWM Polarity Register polarity will start with high level in a cycle when the relevant bit set
/**The function of PWMPOL is to select the polarity with relative PWM channel,if the relative bit is seted,the relative channel will be output PWM shart with High level, else output with Low level in shart **/
/**PWMPOL功能為選擇PWM輸出的極性,如果相對位置的位置1則相對通道的PWM先輸出高電平,否則先輸出低電平**/
PWMCLK=0xff; // PWM Clock Select Register X channel select clock SB(or SA) with PWMCLK.X equal one,else select clock B(or A)
/**The function of PWMCLK is to select a CLOCK(SB,B,SA or A) source work for it ,Channel 0,1,4,5 will select CLOCK SA if the reletive bit set 1,else select CLOCK A;similar,Channel 2,3,6,7 will select CLOCK SB or CLOCK B **/
/**PWMCLK功能為選擇通道的使用時鐘源,通道0,1,4,5在相對位置1的時候選擇時鐘SA,否則使用時鐘A作為時鐘源;同樣的,通道2,3,6,7將選擇時鐘SB或者時鐘B**/
PWMCAE=0xff; // PWM Center Align Enable Register PWMCAE.X set will case the channel X run for center align output mode,reset case right align output mode.
/**The function of PWMCAE is to determine the Center Align or the Right Align output mode will be use,if reletive bit set 1,that channel's waveform be Center Align ,else output right align waveform**/
/**PWMCAE功能為選擇輸出波形中間對齊還是右對齊排列形式,如果相對的位置1,則選擇中間對齊方式,否則選擇右對齊方式**/
PWMCTL=0x30;
PWMSCLA=0x06; // PWM Scale A Register Clock SA = Clock A / (2 * PWMSCLA) ,when PWMSCLA=0x00,PWMSCLA value is consider a full scale value of 256
/**The function of PWMSCLA is to setting the clock frequency of CLOCK SA according as CLOCK A frequency :Clock SA = Clock A / (2 * PWMSCLA)
if the PWMSCLA equal zero ,PWMSCLA value is consider a full value of 256,in this time ,Clock SA = Clock A/512,so when you setting PWMSCLA you must carefull enough**/
/** PWMSCLA功能為設置時鐘SA 的工作頻率,這是基于時鐘A的,公式如:Clock SA = Clock A / (2 * PWMSCLA) ,當PWMSCLA=0X00 的時候,PWMSCLA的值會
被認為256,那么Clock SA=Clock A/512,所以需要注意**/
PWMSCLB=0x06; // PWM Scale B Register similar as PWMSCLA
/**The function of PWMSCLB is similar as PWMSCLA ,the different is that setting Clock SB according as Clock A ,the detail see the previous note about PWMSCLA**/
/**PWMSCLB功能和PWMSCLA的功能使一致的,只是控制的基于時鐘B確定時鐘SB頻率,詳細見上一注釋**/
// PWMPER0=0xFF; //PWM Channel Period Registers PWMx Period = Channel Clock Period * (2 * PWMPERx)
/**The function of PWMPERx is setting the x channel PWM Period according following equation :PWMx Period = Channel Clock Period * (2 * PWMPERx).**/
/**NOTE :The x figure one of the PWM channel 0 to 7 **/
/**PWMPERx功能為設定x通道的PWM波周期。公式為:PWMx Period = Channel Clock Period * (2 * PWMPERx)**/
/**注意:這里的x表示0到7PWM通道之一**/
// PWMDTY0=0x80; //PWM Channel Duty Registers ,Polarity = 0 (PPOLx=0) :Duty Cycle = [(PWMPERx-PWMDTYx)/PWMPERx] * 100% ; Polarity = 1 (PPOLx=1) : Duty Cycle = [PWMDTYx / PWMPERx] * 100% .This Register value need to sure in the future
/**The function of PWMDTYx is ensuring the duty of PWM waveform ,if Polarity equal zero(PPOLx equal zero) ,the duty equation as following:
Duty Cycle = [(PWMPERx-PWMDTYx)/PWMPERx] * 100% ;if Polarity equal one(PPOLx euqal one),the duty equation as following: Duty Cycle = [PWMDTYx / PWMPERx] * 100% ;
This register will be change to agreement your actual requirement.**/
/**PWMDTYx功能為確定PWM波形占空比的比較值,如果采用極性控制位等于0的方式則占空比的表達式為:Duty Cycle = [(PWMPERx-PWMDTYx)/PWMPERx] * 100%
否則公式為Duty Cycle = [PWMDTYx / PWMPERx] * 100%,這個寄存器是根據(jù)你的實際需要用戶在程序運行中自己進行改變的**/
// PWMPER1=0xFF;
// PWMPER2=0xFF;
// PWMPER3=0xFF;
PWMPER01=0x682E; //50Hz
PWMPER23=0x682E;
PWMPER4=0xFF; //4.7KHz
PWMPER5=0xFF;
PWMPER6=0xFF;
PWMPER7=0xFF;
// PWMDTY1=0x30;
// PWMDTY2=0x50;
// PWMDTY3=0x70;
PWMDTY01=0x05D4;
PWMDTY23=0x05D4;
PWMDTY4=0x00;
PWMDTY5=0x00;
PWMDTY6=0x00;
PWMDTY7=0x00;
PWMSDN=0x00; //PWM Shutdown Register The register above shutdown PWM and restart PWM and PWM interrupt enable and so on.In general,PWMSDN equal zero.
/**The function of PWMSDN is to shutdown and restart the PWM waveform output or enable the PWM interrupt and so on,In general,the PWMSDN equal zero **/
/**PWMSDN的功能為關閉和重啟PWM波輸出或者使能PWM中斷等,一般的時候PWMSDN應該保持為0**/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -