定时器输出可变频率脉冲控制步进电机问题,定时器再装入
时间:10-02
整理:3721RD
点击:
代码:
#include "common.h"
#include "Motor.h"
void Timer0(void) interrupt 1 using 1
{
TR0 = 0;
TMOD = 0x01;
PulseT = Pulse
TH0 = PulseT >>8;
TL0 = PulseT &0xff;
ET0=1;
EA=1;
Out1 = ~Out1;
if( step > 0 )
{
step--;
}
}
void MotoU(void)
{
if ( Rise[k] < PulseMax )
{
if ( step == 0 )
{
PulseT = Rise[k];
step = 10;
k++;
PulseN--;
}
}
if ( Rise[k] >= PulseMax )
{
PulseT = PulseMax;
PulseN--;
}
}
void MotoD(void)
{
if ( k < 20 )
{
if ( step == 0 )
{
PulseT = Rise[k];
step = 10;
k++;
PulseN--;
}
}
if ( k == 20 )
{
PulseT = PulseMin;
PulseN--;
}
}
void MotoF(void)
{
TR0 = 1;
while (PulseN > 0)
{
if( PulseN >= PulseNtem - 200)
{
MotoU();
TR0 = 1;
}
if( PulseNtem - 200 > PulseN > 200)
{
TR0 = 0;
PulseT = PulseMax;
TR0 = 1;
Out1 = ~Out1;
PulseN --;
}
else if(PulseN <= 200)
{
MotoD();
TR0 = 1;
}
}
}
void MotoB(void)
{
PulseNum = MemorySys[DTime1] * 5 / 9 ;
PulseNtem = PulseNum - PulseN;
PulseMax = 50;
PulseMin = 3000;
PulseT = PulseMin;
PulseN = PulseNtem;
while (PulseN > 0)
{
if ( PulseN >= (PulseNtem - 200))
{
MotoU();
TR0 = 1;
}
else if( TF0 ==1 && (PulseNtem - 200) > PulseN > 200)
{
TF0 = 0;
PulseT = PulseMax;
Out1 = ~Out1;
PulseN --;
}
else if(PulseN <= 200)
{
MotoD();
TR0 = 1;
}
}
}
void MotoP(void)
{
TR0 = 1;
while ( k < 20 )
{
if ( step == 0 )
{
PulseT = Rise[k];
step = 10;
k++;
TR0 = 1;
PulseN--;
}
}
}
step为每档速度的步数,PulseT为当前定时,MotoU()、MotoD() 为加减速
当主程序调用MotoF()函数后就失去响应,Out1也没有输出脉冲
#include "common.h"
#include "Motor.h"
void Timer0(void) interrupt 1 using 1
{
TR0 = 0;
TMOD = 0x01;
PulseT = Pulse
TH0 = PulseT >>8;
TL0 = PulseT &0xff;
ET0=1;
EA=1;
Out1 = ~Out1;
if( step > 0 )
{
step--;
}
}
void MotoU(void)
{
if ( Rise[k] < PulseMax )
{
if ( step == 0 )
{
PulseT = Rise[k];
step = 10;
k++;
PulseN--;
}
}
if ( Rise[k] >= PulseMax )
{
PulseT = PulseMax;
PulseN--;
}
}
void MotoD(void)
{
if ( k < 20 )
{
if ( step == 0 )
{
PulseT = Rise[k];
step = 10;
k++;
PulseN--;
}
}
if ( k == 20 )
{
PulseT = PulseMin;
PulseN--;
}
}
void MotoF(void)
{
TR0 = 1;
while (PulseN > 0)
{
if( PulseN >= PulseNtem - 200)
{
MotoU();
TR0 = 1;
}
if( PulseNtem - 200 > PulseN > 200)
{
TR0 = 0;
PulseT = PulseMax;
TR0 = 1;
Out1 = ~Out1;
PulseN --;
}
else if(PulseN <= 200)
{
MotoD();
TR0 = 1;
}
}
}
void MotoB(void)
{
PulseNum = MemorySys[DTime1] * 5 / 9 ;
PulseNtem = PulseNum - PulseN;
PulseMax = 50;
PulseMin = 3000;
PulseT = PulseMin;
PulseN = PulseNtem;
while (PulseN > 0)
{
if ( PulseN >= (PulseNtem - 200))
{
MotoU();
TR0 = 1;
}
else if( TF0 ==1 && (PulseNtem - 200) > PulseN > 200)
{
TF0 = 0;
PulseT = PulseMax;
Out1 = ~Out1;
PulseN --;
}
else if(PulseN <= 200)
{
MotoD();
TR0 = 1;
}
}
}
void MotoP(void)
{
TR0 = 1;
while ( k < 20 )
{
if ( step == 0 )
{
PulseT = Rise[k];
step = 10;
k++;
TR0 = 1;
PulseN--;
}
}
}
step为每档速度的步数,PulseT为当前定时,MotoU()、MotoD() 为加减速
当主程序调用MotoF()函数后就失去响应,Out1也没有输出脉冲
自己顶一顶,沙发下
新手求帮助啊