中级会员
- 积分
- 435
- 威望
- 229
- 贡献
- 130
- 兑换币
- 145
- 注册时间
- 2014-11-23
- 在线时间
- 38 小时
- 毕业学校
- 中国矿业大学(北京)
|
编码器如何使能呢??
gpio_Interrupt_init(PORTC,5, GPI_DOWN, RING) ;
写这个编码器还是不能传回来脉冲
这个程序用到什么算法?能解释一下吗
int16_t SpeedPID(uint16_t speedCount,uint16_t AmSpeed){
// uint8_t i;
static int16_t LastSpeedCut0,LastSpeedCut1,LastSpeedCut2 ,SpeedLastPWMK ;
int16_t SpeedPWMKP ,SpeedPWMKI ,SpeedPWMKD,SpeedPWMK ;
int16_t SpeedPWMOUT;
int16_t SpeedDifference0=0;
int16_t speedDEARE1,speedDEARE2,DSpeed ;
SpeedKP = 2;
SpeedKI = 0;
SpeedKD = 1;
LastSpeedCut0 = (int16_t) speedCount ;
DSpeed =(int16_t) AmSpeed ;
SpeedDifference0 = DSpeed - LastSpeedCut0 ;
speedDEARE1 = LastSpeedCut0 - LastSpeedCut1;
speedDEARE2 = LastSpeedCut2+LastSpeedCut0-2*LastSpeedCut1;
LastSpeedCut2 = LastSpeedCut1;
LastSpeedCut1 = LastSpeedCut0;
SpeedPWMKP = SpeedKP*SpeedDifference0;
if(SpeedPWMKP>KPPLUSMAX){
SpeedPWMKP = KPPLUSMAX;
}else if (SpeedPWMKP <KPNEGATIVEMAX){
SpeedPWMKP = KPNEGATIVEMAX;
}
// uart_putchar(UART0,SpeedDifference0);
// uart_putchar(UART0,SpeedPWMKP);
SpeedPWMKI = SpeedKI* speedDEARE1;
if(SpeedPWMKI > KIPLUSMAX){
SpeedPWMKI = KIPLUSMAX;
} else if(SpeedPWMKI < KINEGATIVEMAX){
SpeedPWMKI = KINEGATIVEMAX;
}
SpeedPWMKD = SpeedKD* speedDEARE2;
if(SpeedPWMKD > KDPLUSMAX){
SpeedPWMKD = KDPLUSMAX;
} else if(SpeedPWMKD < KDNEGATIVEMAX){
SpeedPWMKD = KDNEGATIVEMAX;
}
SpeedPWMK = SpeedPWMKD+SpeedPWMKI+SpeedPWMKP ;
if(SpeedPWMK > KWPLUSMAX){
SpeedPWMK = KWPLUSMAX;
}else if(SpeedPWMK < KWNEGATIVEMAX){
SpeedPWMK = KWNEGATIVEMAX;
}
SpeedPWMOUT = SpeedLastPWMK + SpeedPWMK ;
if(SpeedPWMOUT < 0 ){
SpeedPWMOUT = 0 ;
} else if(SpeedPWMOUT > KOUPLUSMAX){
SpeedPWMOUT = KOUPLUSMAX ;
}
SpeedLastPWMK = SpeedPWMOUT ;
// uart_putchar(UART0,SpeedPWMOUT);
// uart_putchar(UART0,SpeedPWMK);
return SpeedPWMOUT ;
}
|
|