智能车制作
标题:
舵机控制问题
[打印本页]
作者:
xiaoqiu
时间:
2011-3-26 00:01
标题:
舵机控制问题
我烧入下面的程序,我舵机只能往一个方向转一定角度,最后就卡死了。不能回转?恳请高手们帮帮忙看下,我不知道是我舵机问题还是程序有问题。。。
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
void Pulse_int(void) //脉冲累加器初始化
{
//TSCR1_TEN =1;
PACTL_PAEN =0 ;
PACTL_PAMOD =0 ;
PACTL_PEDGE = 0 ;
PACTL_PAOVI = 0 ;
PACTL_PAI=1 ; m
PACNT=0 ;
PAFLG_PAOVF=1 ;
PAFLG_PAIF=1;
PACTL_PAEN=1;
}
unsigned int speed_get(void)
{ unsigned int speed;
speed = PACNT;
PACNT = 0;
return speed;
}
void crg_init(void)
{
SYNR=0x02; //Bus clock=(pllclk/2)=oscclk*(synr+1)/(refdv+1)为24MHZ
REFDV=0x01;
while(!CRGFLG_LOCK ); //频率稳定时
CLKSEL =0x80;
}
void pwm_init(void)
{
PWMCTL=0xB0; // 设置通道76、32、10级连
PWME=0x00; // 通道禁止输出;
PWMPRCLK=0x12;//预分频:A_CLK=busclk/2^2=6M B_CLK=BUSCLK/2^1=12M
PWMSCLA=0x01; //SA_CLK=A_CLK/(2*1)==3MHz
PWMSCLB=0X01; //SB_CLK=B_CLK/(2*1)==6MHz
PWMPOL=0x8A; //极性选择起始为高电平;
PWMCLK=0x8A; //PWM01 选择 SA_CLK PWM23 67选择SB_CLK
PWMCNT0=0x00;
PWMCNT1=0x00;
PWMCNT2=0x00;
PWMCNT3=0x00;
PWMCNT6=0x00;
PWMCNT7=0x00;
PWMPER01=60000; // 周期==(1/3M)*(60000)=20ms
PWMPER23=10000; // F=6M/10000==600Hz = 1.6666ms
PWMPER67=10000; // F=6M/10000==600Hz
PWMCAE=0x00; //左对齐方式
PWME=0x82; // 通道1,7输出使能;
}
void delay(unsigned int i); //声明延时函数
void delay(unsigned int i)
{
unsigned char j;
for(i; i > 0; i--)
for(j = 255; j > 0; j--);
}
void main(void) {
int i=0;
crg_init(); //锁向环初始化
pwm_init(); //初始化PWM
EnableInterrupts;
EnableInterrupts;
PWMDTY01=3000;
delay(6000);
PWMDTY01=4560;
delay(6000);
PWMDTY01=5660;
delay(6000);
PWMDTY01=3060;
delay(6000);
PWMDTY01=4560;
delay(6000);
PWMDTY01=5660;
delay(60000);
PWMDTY01=3000;
delay(9000);
PWMDTY01=5560;
delay(9000);
PWMDTY01=5960;
delay(9000);
PWMDTY01=3060;
delay(10000);
PWMDTY01=4560;
delay(6000);
PWMDTY01=5660;
delay(60000);
}
作者:
zxxi
时间:
2012-2-18 21:56
你没看舵机的相关资料吧?
占比不对!!
作者:
88251656
时间:
2012-3-9 19:33
对,真的不对
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2