|
@@ -322,14 +322,6 @@ void Y1Direction(void *p_arg) |
|
|
if (NowFrequency != PulseOutput[NowPulse].Frequency && PulseRuning == 1)/* 如果现在寄存器内的频率与实际输出的频率不一致 */ |
|
|
if (NowFrequency != PulseOutput[NowPulse].Frequency && PulseRuning == 1)/* 如果现在寄存器内的频率与实际输出的频率不一致 */ |
|
|
{ |
|
|
{ |
|
|
FixArrFlag = 1; //使能频率修改脉冲加减速 |
|
|
FixArrFlag = 1; //使能频率修改脉冲加减速 |
|
|
if (PulseOutput[NowPulse].Frequency > NowFrequency) |
|
|
|
|
|
{ |
|
|
|
|
|
Acc = (PulseOutput[NowPulse].Frequency - NowFrequency ) / Options.AccUpTime; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
Acc = (PulseOutput[NowPulse].Frequency - NowFrequency ) / Options.AccDownTime; |
|
|
|
|
|
} |
|
|
|
|
|
HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */ |
|
|
HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -363,10 +355,9 @@ void PulseStartTsk(void *p_arg) |
|
|
if (Register_L[0x3000] == 0x01 && EN == 1) |
|
|
if (Register_L[0x3000] == 0x01 && EN == 1) |
|
|
{ |
|
|
{ |
|
|
EN = 0; |
|
|
EN = 0; |
|
|
PulseStartFlag = 1; |
|
|
|
|
|
PulseRuning = 1; |
|
|
|
|
|
|
|
|
PulseStartFlag = 1; /* 脉冲第一段开始标志位 */ |
|
|
|
|
|
PulseRuning = 1; /* 脉冲进行中标志位 */ |
|
|
NowFrequency = PulseOutput[NowPulse].Frequency; /* 保存当前脉冲的频率 */ |
|
|
NowFrequency = PulseOutput[NowPulse].Frequency; /* 保存当前脉冲的频率 */ |
|
|
PulseStart(); |
|
|
|
|
|
HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */ |
|
|
HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */ |
|
|
} |
|
|
} |
|
|
else if (Register_L[0x3000] == 0x02 && EN == 0) |
|
|
else if (Register_L[0x3000] == 0x02 && EN == 0) |
|
@@ -547,12 +538,12 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
if (htim == (&htim3)) |
|
|
if (htim == (&htim3)) |
|
|
{ |
|
|
{ |
|
|
/* 段切换的加减速 */ |
|
|
/* 段切换的加减速 */ |
|
|
if (ArrFlag == 1) |
|
|
|
|
|
|
|
|
if (ArrFlag == 1 && NowPulse != 10) |
|
|
{ |
|
|
{ |
|
|
/* 脉冲加速 */ |
|
|
/* 脉冲加速 */ |
|
|
if (Acc > 0) |
|
|
|
|
|
|
|
|
if (PulseOutput[NowPulse].Frequency > PulseOutput[PrePulse].Frequency) |
|
|
{ |
|
|
{ |
|
|
if (ArrTimes <= Options.AccUpTime) |
|
|
|
|
|
|
|
|
if (ArrTimes <= (int32_t)(PulseOutput[NowPulse].Frequency - PulseOutput[PrePulse].Frequency) / AccUp) |
|
|
{ |
|
|
{ |
|
|
SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * AccUp); |
|
|
SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * AccUp); |
|
|
if(ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ |
|
|
if(ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ |
|
@@ -567,13 +558,14 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
/* 脉冲减速 */ |
|
|
/* 脉冲减速 */ |
|
|
else if (Acc <= 0) |
|
|
|
|
|
|
|
|
else if (PulseOutput[NowPulse].Frequency <= PulseOutput[PrePulse].Frequency) |
|
|
{ |
|
|
{ |
|
|
if (ArrTimes <= Options.AccDownTime) |
|
|
|
|
|
|
|
|
if (ArrTimes <= (int32_t)(PulseOutput[NowPulse].Frequency - PulseOutput[PrePulse].Frequency) / AccDown) |
|
|
{ |
|
|
{ |
|
|
SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * AccDown); |
|
|
SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * AccDown); |
|
|
if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ |
|
|
if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ |
|
|
ArrTimes++; |
|
|
ArrTimes++; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
@@ -585,10 +577,10 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
/* 实时修改频率的加减速 */ |
|
|
/* 实时修改频率的加减速 */ |
|
|
if (FixArrFlag == 1) |
|
|
|
|
|
|
|
|
if (FixArrFlag == 1 && NowPulse != 10) |
|
|
{ |
|
|
{ |
|
|
/* 脉冲加速 */ |
|
|
/* 脉冲加速 */ |
|
|
if (Acc > 0) |
|
|
|
|
|
|
|
|
if (PulseOutput[NowPulse].Frequency > NowFrequency) |
|
|
{ |
|
|
{ |
|
|
if (ArrTimes <= Options.AccUpTime) |
|
|
if (ArrTimes <= Options.AccUpTime) |
|
|
{ |
|
|
{ |
|
@@ -605,7 +597,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
/* 脉冲减速 */ |
|
|
/* 脉冲减速 */ |
|
|
else if (Acc <= 0) |
|
|
|
|
|
|
|
|
else if (PulseOutput[NowPulse].Frequency <= NowFrequency) |
|
|
{ |
|
|
{ |
|
|
if (ArrTimes <= Options.AccDownTime) |
|
|
if (ArrTimes <= Options.AccDownTime) |
|
|
{ |
|
|
{ |
|
@@ -626,7 +618,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
/* 第一段脉冲的加速 */ |
|
|
/* 第一段脉冲的加速 */ |
|
|
if (NowPulse == Options.StartPulse && PulseStartFlag == 1) |
|
|
if (NowPulse == Options.StartPulse && PulseStartFlag == 1) |
|
|
{ |
|
|
{ |
|
|
if (ArrTimes <= Options.AccUpTime) |
|
|
|
|
|
|
|
|
if (ArrTimes < PulseOutput[NowPulse].Frequency / AccUp) |
|
|
{ |
|
|
{ |
|
|
ArrTimes++; |
|
|
ArrTimes++; |
|
|
SetFrequency(Options.SentPost, ArrTimes * AccUp); |
|
|
SetFrequency(Options.SentPost, ArrTimes * AccUp); |
|
@@ -641,11 +633,11 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
/* 最后一段脉冲的减速 */ |
|
|
/* 最后一段脉冲的减速 */ |
|
|
if (PulseRuning == 0) |
|
|
|
|
|
|
|
|
if (PulseRuning == 0 && NowPulse != 10) |
|
|
{ |
|
|
{ |
|
|
if (ArrTimes <= Options.AccDownTime) |
|
|
|
|
|
|
|
|
if (ArrTimes <= PulseOutput[NowPulse].Frequency / (- AccDown)) |
|
|
{ |
|
|
{ |
|
|
SetFrequency(Options.SentPost, NowFrequency + ArrTimes * AccDown); |
|
|
|
|
|
|
|
|
SetFrequency(Options.SentPost, PulseOutput[NowPulse].Frequency + ArrTimes * AccDown); |
|
|
if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ |
|
|
if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ |
|
|
ArrTimes++; |
|
|
ArrTimes++; |
|
|
} |
|
|
} |
|
|