注册会员
- 积分
- 18
- 威望
- 14
- 贡献
- 4
- 兑换币
- 2
- 注册时间
- 2014-12-2
- 在线时间
- 0 小时
- 毕业学校
- 渠县中学
|
电机测速,溢出中断函数中没有TCO,那么它的溢出是怎样实现的?AD采样中采样周期和信号输入周期的关系在这个程序中是怎样体现的?
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主函数**************************
void main(void)
{
//unsigned char moter_dirve=5;
unsigned char spiDATA,spiLENGTH;
spiDATA = 0xFC ;
spiLENGTH = 8;
ATD_int();
PLL_int();
PWM_int1();
shumaguang_int();
ECT0_Init();
DDRA_BIT7=1;
PORTA_BIT7=1; //1号灯亮
EnableInterrupts;
for(;;)
{
if (ATD0STAT0_SCF)
{
PWMDTY5 =ATD0DR0L; //AD2
ATD0STAT0=0x80;
//moter_speed=PWMDTY5;
}
// PWMDTY5 =80; //AD2
ledCONTROL(moter_speed); //显示读取到的值
delay_1();
delay_1(); //延迟
if(moter_speed>=500)
{
PWM_int2();
PORTA_BIT7=0;
}
}
}
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;
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主函数**************************
void main(void)
{
//unsigned char moter_dirve=5;
unsigned char spiDATA,spiLENGTH;
spiDATA = 0xFC ;
spiLENGTH = 8;
ATD_int();
PLL_int();
PWM_int1();
shumaguang_int();
ECT0_Init();
DDRA_BIT7=1;
PORTA_BIT7=1; //1号灯亮
EnableInterrupts;
for(;;)
{
if (ATD0STAT0_SCF)
{
PWMDTY5 =ATD0DR0L; //AD2
ATD0STAT0=0x80;
//moter_speed=PWMDTY5;
}
// PWMDTY5 =80; //AD2
ledCONTROL(moter_speed); //显示读取到的值
delay_1();
delay_1(); //延迟
if(moter_speed>=500)
{
PWM_int2();
PORTA_BIT7=0;
}
}
}
|
|