中级会员
- 积分
- 222
- 威望
- 120
- 贡献
- 70
- 兑换币
- 65
- 注册时间
- 2013-1-26
- 在线时间
- 16 小时
|
本人新手,刚开始用XS128学习配置PWM,从龙丘的流水灯工程改(避免工程配置出错)了一个周期为20ms,占空比百分之5的pwm输出,不知为什么连接舵机(普通的辉盛995),舵机就是不动,但是连接5V电源的时候舵机会有反应(是否可以排除舵机是坏的),贴上代码求大神拯救。
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
void delayms(int ms)
{
int ii,jj;
if (ms<1) ms=1;
for(ii=0;ii<ms;ii++)
for(jj=0;jj<3338;jj++); //40MHz--1ms
}
void SetBusCLK_80M(void)
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR =0xc0 | 0x09;
REFDV=0x80 | 0x01;
POSTDIV=0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=160MHz;
_asm(nop); //BUS CLOCK=80M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void PWM_INIT(void)
{
// PTTRR_PTTRR3 = 1;
PWME = 0x00;
PWMCTL = 0x00;
PWMPOL = 0xff;
PWMCAE = 0x00;
PWMPRCLK = 0x44;
PWMSCLB = 10;
PWMCLK = 0x00;
PWMPER3 = 100;
PWMDTY3 = 5;
PWME = 0xff;
}
void main(void) {
/* put your own code here */
unsigned char LedCnt=0;
SetBusCLK_80M(); // 此处选择待设定的总线频率
PWM_INIT();
DDRB=0xff;
PORTB=0XFE;
EnableInterrupts;
for(;;)
{
LedCnt=(LedCnt>0XFE?0:++LedCnt);
delayms(500);
PORTB=~LedCnt;
}
}
|
|