|
|
@@ -41,10 +41,7 @@ static void Tim2CntCallBack(void *pArg); |
|
|
|
static void ReadRegisterParam(PLSR *plsr); |
|
|
|
static void configPulsePort(PLSR *plsr); |
|
|
|
static void ComputePartNum(PLSR *plsr, SEGMENT_PART *segmentPart); |
|
|
|
static void FirstSegmentProc(SEGMENT_PART *segmentPart); |
|
|
|
static void SecondSegmentProc(SEGMENT_PART *segmentPart); |
|
|
|
static void ThirdSegmentProc(SEGMENT_PART *segmentPart); |
|
|
|
|
|
|
|
static void StartPulseOutput(void); |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief PLSR功能初始化 |
|
|
@@ -105,6 +102,7 @@ int32_t decPulse = 0; |
|
|
|
int32_t uniformTime = 0; |
|
|
|
int32_t uniformPulse = 0; |
|
|
|
uint8_t currentSegment = 0; |
|
|
|
uint8_t currentSegmentID = 0; |
|
|
|
uint32_t currentSpeed = 0; |
|
|
|
uint8_t RunFlag = 0; |
|
|
|
|
|
|
@@ -122,17 +120,17 @@ PLSR plsr = { |
|
|
|
.defaultDecSpeedTime = 10, |
|
|
|
.segment[0].pulseFreq = 2000, |
|
|
|
.segment[0].pulseNumber = 1000, |
|
|
|
.segment[0].jumpNumber = 0, |
|
|
|
.segment[0].jumpNumber = 3, |
|
|
|
.segment[1].pulseFreq = 1000, |
|
|
|
.segment[1].pulseNumber = 2000, |
|
|
|
.segment[1].jumpNumber = 0, |
|
|
|
.segment[1].jumpNumber = 4, |
|
|
|
.segment[2].pulseFreq = 6000, |
|
|
|
.segment[2].pulseNumber = 2000, |
|
|
|
.segment[2].jumpNumber = 0, |
|
|
|
.segment[2].jumpNumber = 2, |
|
|
|
.segment[3].pulseFreq = 6000, |
|
|
|
.segment[3].pulseNumber = 10000, |
|
|
|
.segment[3].jumpNumber = 0, |
|
|
|
.startRunSegment = 0 |
|
|
|
.startRunSegment = 1 |
|
|
|
}; |
|
|
|
|
|
|
|
void PlsrModuleTask(void *pArg) |
|
|
@@ -160,7 +158,8 @@ void PlsrModuleTask(void *pArg) |
|
|
|
plsr.sendEnableState = 1; |
|
|
|
plsr.accDecSpeedMode = STRAIGHT_LINE_MODE; |
|
|
|
|
|
|
|
currentSegment = plsr.startRunSegment; |
|
|
|
currentSegmentID = plsr.startRunSegment; |
|
|
|
currentSegment = currentSegmentID - 1; |
|
|
|
|
|
|
|
while (1) |
|
|
|
{ |
|
|
@@ -196,27 +195,9 @@ void PlsrModuleTask(void *pArg) |
|
|
|
if ((plsr.accDecSpeedMode == STRAIGHT_LINE_MODE) && (RunFlag == 0)) |
|
|
|
{ |
|
|
|
RunFlag = 1; |
|
|
|
|
|
|
|
|
|
|
|
ComputePartNum(&plsr, ¤tSeg); |
|
|
|
|
|
|
|
switch (currentSeg.currentPart) |
|
|
|
{ |
|
|
|
case 1: |
|
|
|
{ |
|
|
|
FirstSegmentProc(¤tSeg); |
|
|
|
break; |
|
|
|
} |
|
|
|
case 2: |
|
|
|
{ |
|
|
|
SecondSegmentProc(¤tSeg); |
|
|
|
break; |
|
|
|
} |
|
|
|
case 3: |
|
|
|
{ |
|
|
|
ThirdSegmentProc(¤tSeg); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
StartPulseOutput(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -314,7 +295,7 @@ static void TimCallBack(void *pArg) |
|
|
|
{ |
|
|
|
if (pulseCount > currentSeg.secondPartNum - 1) |
|
|
|
{ |
|
|
|
if ((currentSegment == (plsr.segmentAllNum -1)) |
|
|
|
if ((currentSegmentID == (plsr.segmentAllNum)) |
|
|
|
&& (plsr.segment[currentSegment].jumpNumber == 0)) |
|
|
|
{ |
|
|
|
currentSeg.currentPart = 3; |
|
|
@@ -326,10 +307,13 @@ static void TimCallBack(void *pArg) |
|
|
|
currentSeg.currentPart = 1; |
|
|
|
pulseCount = 0; |
|
|
|
RunFlag = 0; |
|
|
|
|
|
|
|
if (plsr.segment[currentSegment].jumpNumber == 0) |
|
|
|
currentSegment++; |
|
|
|
else |
|
|
|
currentSegment = plsr.segment[currentSegment].jumpNumber; |
|
|
|
currentSegment = plsr.segment[currentSegment].jumpNumber - 1; |
|
|
|
|
|
|
|
currentSegmentID = currentSegment + 1; |
|
|
|
} |
|
|
|
allcount++; |
|
|
|
pulseCount++; |
|
|
@@ -460,34 +444,35 @@ static void configPulsePort(PLSR *plsr) |
|
|
|
|
|
|
|
static void ComputePartNum(PLSR *plsr, SEGMENT_PART *segmentPart) |
|
|
|
{ |
|
|
|
uint32_t target = plsr->segment[currentSegment].pulseFreq; |
|
|
|
uint32_t targetFreq = plsr->segment[currentSegment].pulseFreq; |
|
|
|
uint32_t targetPulseCount = plsr->segment[currentSegment].pulseNumber; |
|
|
|
ABS(targetPulseCount); |
|
|
|
|
|
|
|
accSpeedSlope = plsr->defaultSpeed / plsr->defaultAccSpeedTime; |
|
|
|
decSpeedSlope = plsr->defaultSpeed / plsr->defaultDecSpeedTime; |
|
|
|
|
|
|
|
/* 计算每段脉冲三个部分脉冲数量 */ |
|
|
|
/* 最后一段 */ |
|
|
|
if ((currentSegment == (plsr->segmentAllNum -1)) |
|
|
|
if ((currentSegmentID == (plsr->segmentAllNum)) |
|
|
|
&& (plsr->segment[currentSegment].jumpNumber == 0)) |
|
|
|
{ |
|
|
|
decTime = target / decSpeedSlope; |
|
|
|
segmentPart->thirdPartNum = target / 2 * decTime / 1000; |
|
|
|
decTime = targetFreq / decSpeedSlope; |
|
|
|
segmentPart->thirdPartNum = targetFreq / 2 * decTime / 1000; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
segmentPart->thirdPartNum = 0; |
|
|
|
} |
|
|
|
|
|
|
|
if (currentSpeed < target) |
|
|
|
if (currentSpeed < targetFreq) |
|
|
|
{ |
|
|
|
accTime = (target - currentSpeed) / accSpeedSlope; |
|
|
|
segmentPart->firstPartNum = (target + currentSpeed) / 2 * accTime / 1000; |
|
|
|
accTime = (targetFreq - currentSpeed) / accSpeedSlope; |
|
|
|
segmentPart->firstPartNum = (targetFreq + currentSpeed) / 2 * accTime / 1000; |
|
|
|
} |
|
|
|
else if (currentSpeed > target) |
|
|
|
else if (currentSpeed > targetFreq) |
|
|
|
{ |
|
|
|
decTime = (currentSpeed - target) / decSpeedSlope; |
|
|
|
segmentPart->firstPartNum = (target + currentSpeed) / 2 * decTime / 1000; |
|
|
|
decTime = (currentSpeed - targetFreq) / decSpeedSlope; |
|
|
|
segmentPart->firstPartNum = (targetFreq + currentSpeed) / 2 * decTime / 1000; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
@@ -496,22 +481,15 @@ static void ComputePartNum(PLSR *plsr, SEGMENT_PART *segmentPart) |
|
|
|
segmentPart->secondPartNum = targetPulseCount |
|
|
|
- segmentPart->firstPartNum |
|
|
|
- segmentPart->thirdPartNum; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void FirstSegmentProc(SEGMENT_PART *segmentPart) |
|
|
|
{ |
|
|
|
int32_t targetFreq = 0; |
|
|
|
int32_t slope = 0; |
|
|
|
int32_t diffValue = 0; |
|
|
|
|
|
|
|
if (currentSpeed == plsr.segment[currentSegment].pulseFreq) |
|
|
|
if (currentSpeed == plsr->segment[currentSegment].pulseFreq) |
|
|
|
segmentPart->currentState = 1; |
|
|
|
else if ((currentSpeed < plsr.segment[currentSegment].pulseFreq)) |
|
|
|
else if ((currentSpeed < plsr->segment[currentSegment].pulseFreq)) |
|
|
|
segmentPart->currentState = 2; |
|
|
|
else |
|
|
|
segmentPart->currentState = 3; |
|
|
|
|
|
|
|
|
|
|
|
/* 计算每个脉冲的频率增量 */ |
|
|
|
switch (segmentPart->currentState) |
|
|
|
{ |
|
|
|
/* 匀速处理 */ |
|
|
@@ -523,9 +501,7 @@ static void FirstSegmentProc(SEGMENT_PART *segmentPart) |
|
|
|
/* 加速处理 */ |
|
|
|
case 2 : |
|
|
|
{ |
|
|
|
targetFreq = plsr.segment[currentSegment].pulseFreq; |
|
|
|
slope = plsr.defaultSpeed / plsr.defaultAccSpeedTime; |
|
|
|
segmentPart->inc = ((targetFreq - currentSpeed) / slope) |
|
|
|
segmentPart->inc = ((targetFreq - currentSpeed) / accSpeedSlope) |
|
|
|
* ((targetFreq + currentSpeed) / 2) / 1000; |
|
|
|
segmentPart->inc = (targetFreq - currentSpeed) / segmentPart->inc; |
|
|
|
|
|
|
@@ -534,16 +510,18 @@ static void FirstSegmentProc(SEGMENT_PART *segmentPart) |
|
|
|
/* 减速处理 */ |
|
|
|
case 3 : |
|
|
|
{ |
|
|
|
targetFreq = plsr.segment[currentSegment].pulseFreq; |
|
|
|
slope = plsr.defaultSpeed / plsr.defaultDecSpeedTime; |
|
|
|
segmentPart->dec = ((currentSpeed - targetFreq) / slope) |
|
|
|
segmentPart->dec = ((currentSpeed - targetFreq) / decSpeedSlope) |
|
|
|
* ((currentSpeed + targetFreq) / 2) / 1000; |
|
|
|
segmentPart->dec = (currentSpeed - targetFreq) / segmentPart->dec; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void StartPulseOutput(void) |
|
|
|
{ |
|
|
|
if (currentSpeed <= 1000) |
|
|
|
{ |
|
|
|
tim10.setPsc(&tim10, 2625 - 1); |
|
|
@@ -560,15 +538,3 @@ static void FirstSegmentProc(SEGMENT_PART *segmentPart) |
|
|
|
tim10.open(&tim10); |
|
|
|
tim10.openIrq(&tim10); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void SecondSegmentProc(SEGMENT_PART *segmentPart) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void ThirdSegmentProc(SEGMENT_PART *segmentPart) |
|
|
|
{ |
|
|
|
|
|
|
|
} |