智能车制作
标题:
不知冷火时钟还是PWM出现了问题????、
[打印本页]
作者:
admingj
时间:
2014-4-7 09:57
标题:
不知冷火时钟还是PWM出现了问题????、
刚刚入手MCF52255资料太少了,昨天在调PWM是调了出来,可是频率不对啊,pwm_init();里没咋设置 MCF_PWM_PWMPER(0)=100;MCF_PWM_PWMDTY(0)=10;
但是输出的都是66.67khz;(pll设置里 MCF_CLOCK_SYNCR = MCF_CLOCK_SYNCR_MFD(3) | MCF_CLOCK_SYNCR_CLKSRC| MCF_CLOCK_SYNCR_PLLMODE | MCF_CLOCK_SYNCR_PLLEN ;)
pll是器作用了当 MCF_CLOCK_SYNCR_MFD(4)是输出变成了79kHZ左右,详细代码在二楼;
还有就说它频率80M是指fsys吗还是别的,在参考手册572页说fsys是PWM的基频;
但是在130图示中fsys/2才是PWM的基频,到底那个是?
作者:
admingj
时间:
2014-4-7 09:58
代码
void PWM_init(void)
{
MCF_GPIO_PTCPAR=MCF_GPIO_PTCPAR_DTIN0_PWM0
|MCF_GPIO_PTCPAR_DTIN1_PWM2
|MCF_GPIO_PTCPAR_DTIN2_PWM4
|MCF_GPIO_PTCPAR_DTIN3_PWM6;
MCF_GPIO_PTAPAR=MCF_GPIO_PTAPAR_ICOC0_PWM1
|MCF_GPIO_PTAPAR_ICOC1_PWM3
|MCF_GPIO_PTAPAR_ICOC2_PWM5
|MCF_GPIO_PTAPAR_ICOC3_PWM7;
//pwm Polarity Register
//PWM 极性寄存器 1:高,0:低
MCF_PWM_PWMPOL=0xff;
//pwm Clock select register:1-SA or SB 0-A or B
//PWM 时钟选择寄存器 1:SA / SB , 0:A / B
MCF_PWM_PWMCLK=0x00;
//pwm prescale clock select register bit[6:4]PCKB bit[2:0]PCKA
//PWM 预分频寄存器 fA=fBUS/2^PCKA,fB=fBUS/2^PCKB
MCF_PWM_PWMPRCLK=MCF_PWM_PWMPRCLK_PCKA(0)
|MCF_PWM_PWMPRCLK_PCKB(0);
//pwm center align enable register:1-center-aligned 0-left-aligned
//PWM 中心对齐使能寄存器 1:中心对齐,0:左对齐
MCF_PWM_PWMCAE=0x00;
//pwm control register:0-separate
//PWM 控制寄存器
MCF_PWM_PWMCTL=0;
//pwm scale A&B register Clock SA=Clock A/2*PWMSCLA
//PWM 分频寄存器 A/B fSA=fA/(2*PWMSCLA)
MCF_PWM_PWMSCLA=0;
MCF_PWM_PWMSCLB=0;
//pwm channel counter register
//PWM 通道计数寄存器
MCF_PWM_PWMCNT0=0;
MCF_PWM_PWMCNT1=0;
MCF_PWM_PWMCNT2=0;
MCF_PWM_PWMCNT3=0;
MCF_PWM_PWMCNT4=0;
MCF_PWM_PWMCNT5=0;
MCF_PWM_PWMCNT6=0;
MCF_PWM_PWMCNT7=0;
//pwm channel period register
//PWM 通道周期寄存器
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
//PWM 通道占空比寄存器
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
//PWM 关闭寄存器
MCF_PWM_PWMSDN=MCF_PWM_PWMSDN_IF;
//PWM 使能寄存器
MCF_PWM_PWME=0xff;
}
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2