智能车制作
标题:
电机测速,搞不懂ECT输入捕捉周期和AD采样周期的区别和联系,另外这里TC0寄存未设置,
[打印本页]
作者:
凌轩翼
时间:
2014-12-4 20:07
标题:
电机测速,搞不懂ECT输入捕捉周期和AD采样周期的区别和联系,另外这里TC0寄存未设置,
void ECT0_Init(void)
{
TIOS=0xFE; //通道0设置为输入捕捉
TCTL3=0x00;
TCTL4=0x01; //上升沿捕捉
TSCR2=0x87; //溢出中断允许,128分频,125KHz,相当于计数器数一下耗时1/125000 s,约0.524s溢出一次
TSCR1=0x80; //主定时器开启 TSCR1_TEN=1
TIE_C0I=1; //中断允许
}
unsigned int ABS(unsigned int x,unsigned int y)
{
if(x>y)
return x-y;
else
return y-x;
}
//******************溢出中断函数*********************
#pragma CODE_SEG NON_BANKED
void interrupt 16 over_flow(void)
{
TFLG2_TOF=1;
counter ++; // T0C???
if( counter>=2)
{
counter=0;
moter_speed=0;
}
}
//*************中断子函数****************************
//当检测到下降沿,向CPU发出请求,进入中断函数
#pragma CODE_SEG NON_BANKED
void interrupt 8 timer0_ISR(void)
{
static unsigned long int m=0;
static unsigned long int n=0;
static unsigned long int a=0,k=0;
TFLG1_C0F=1; //清中断标志位
m=TC0;
k=65535*counter+m;
counter=0;
a=62500/(k-n)*5; //104166,r/s //放大5倍
n=m;
if(ABS(a, moter_speed)>=50)
a= moter_speed;
if(ABS(a, moter_speed)>=30&&ABS(a, moter_speed)<50)
a=( moter_speed*2+a*8)/10;
moter_speed=a;
}
//*********************main主函数*********************
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2