呵呵,我们的Freescale。终于有Freescale的版块了,现在把以前写的一些东西转过来,希望能有更多人的关注Freescale。 MCF52233_PWM—Pulse-Width Modulation Module Coldfire的PWM模块做的真傻瓜化,用起来那是相当的方便,简单设几个寄存器就行了。除了傻瓜化,也没什么好说的了。调用一下下面的初始化函数对应的引脚就可以输入需要的PWM波了:
void PWM_init(void) {
//pwm Polarity Register
MCF_PWM_PWMPOL=0XFF;
//pwm Clock select register:1-SA or SB 0-A or B
MCF_PWM_PWMCLK=0XFF;
//pwm prescale clock select register bit[6:4]PCKB bit[2:0]PCKA
MCF_PWM_PWMPRCLK=MCF_PWM_PWMPRCLK_PCKA(0)
|MCF_PWM_PWMPRCLK_PCKB(0);
//pwm center align enable register:1-center-aligned 0-left-aligned
//MCF_PWM_PWMCAE_CAEn
MCF_PWM_PWMCAE=0X00;
//pwm control register:0-separate
//MCF_PWM_PWMCTL_CON01
MCF_PWM_PWMCTL=0X00;
//pwm scale A&B register
MCF_PWM_PWMSCLA=150;
MCF_PWM_PWMSCLB=150;
//pwm channel counter register
//MCF_PWM_PWMCNT1.....MCF_PWM_PWMCNT7
//pwm channel period register
MCF_PWM_PWMPER(0)=100;
MCF_PWM_PWMPER(1)=100;
MCF_PWM_PWMPER(2)=100;
MCF_PWM_PWMPER(3)=100;
MCF_PWM_PWMPER(4)=100;
MCF_PWM_PWMPER(5)=100;
MCF_PWM_PWMPER(6)=100;
MCF_PWM_PWMPER(7)=100;
//pwm channel duty register
MCF_PWM_PWMDTY(0)=10;
MCF_PWM_PWMDTY(1)=20;
MCF_PWM_PWMDTY(2)=30;
MCF_PWM_PWMDTY(3)=40;
MCF_PWM_PWMDTY(4)=50;
MCF_PWM_PWMDTY(5)=60;
MCF_PWM_PWMDTY(6)=70;
MCF_PWM_PWMDTY(7)=80;
//pwm shutdown register
MCF_PWM_PWMSDN=MCF_PWM_PWMSDN_IF;
MCF_PWM_PWME=0XFF;
}
|