中级会员
- 积分
- 434
- 威望
- 271
- 贡献
- 91
- 兑换币
- 0
- 注册时间
- 2012-2-6
- 在线时间
- 36 小时
- 毕业学校
- 江阴市第二中学
|
寻求高人指点,调试舵机我选用20ms为周期,用示波器检测PWM端口波形一切正常。我不管怎么改变PWMDTY01的值,舵机老是只往右转,随后就乱转,与我的初衷完全不一样,请求高人指点迷津
/*********************************************************
**** 函数名:脉宽调制模块初始化
*
*** 说明 :用于舵机和电机
**********************************************************/
void PWM_init(void) //脉宽调制模块的初始化
{
/*//SB,B for ch2367
//SA,A for ch0145
PWME=0x00;
PWMPRCLK=0x44; // 0100 0100 A=B=48M/16= 3M
PWMSCLA=150;
PWMSCLB=150; // SB=B/2/150=10K
PWMCLK_PCLK0=1; // PWM0---SB
PWMPOL_PPOL0=1; // duty = high time
PWMCAE_CAE0=0; // left-aligned
PWMCTL=0x00;
PWMPER0=200; // frequency = SB/200 = 100Hz 20ms
PWMDTY0=16; // duty cycle =
PWME=0x01; */
// 0.1.4.5 A SA
// 2.3.6.7 B SB
//舵机摇头
//SB,B for ch2367
//SA,A for ch0145
PWMPRCLK=0x44; // 0100 0100 A=B=48M/16= 3M
//PWMSCLA = 0x03; //对clock SA 进行2*PWMSCLA=6分频;pwm clock=clockA/6=500k;
//PWMSCLB = 0x03; //clk SB=clk B/(2*pwmsclb)=500k
PWMSCLA=150; //SA=A/2/150=10K
PWMSCLB = 0x03; //clk SB=clk B/(2*pwmsclb)=500k
//pwm01
PWMCTL_CON01=1;
PWMCNT01 = 0;
PWMCAE_CAE1=0;
PWMPOL_PPOL1=1;
PWMCLK_PCLK1=1;
PWME_PWME1 = 0;
PWMPER01 =100; // frequency = SB/100 = 100Hz 10ms
PWMDTY01 =16; // duty cycle = 16%
PWME_PWME1 = 1;
/* //pwm23
PWMCTL_CON23=1;
PWMCNT23 = 0;
PWMCAE_CAE3=0;
PWMPOL_PPOL3=1;
PWMCLK_PCLK3=1;
PWME_PWME3 = 0;
PWMPER23 =10000; //50hz
PWMDTY23 =750;//参数可调 PWMDTY0 =750,1.5ms 方波
PWME_PWME3 = 1; */
//电机
PWME_PWME3 = 0; //关闭通道
PWMCTL_CON23= 1; //4.5通道级联
PWMCAE_CAE2 = 0; //选择左对齐输出模式
PWMCNT23 = 0; //计数器清零
PWMPOL_PPOL3 = 1; //极性设置为正
PWMCLK_PCLK3 = 1; //选择SA作为时钟源
PWMPER23 = 1000; // 500HZ
PWMDTY23 = 200;
PWME_PWME3 = 1; //使能通道
}
|
|