Преглед на файлове

增加直线加减速多段跳转功能

feature/PLSR功能
1923777848 преди 1 ден
родител
ревизия
ba4a9f0c58
променени са 2 файла, в които са добавени 67 реда и са изтрити 45 реда
  1. +54
    -44
      TrainCamp_zhangcheng_PLSR/app/src/plsr.c
  2. +13
    -1
      TrainCamp_zhangcheng_PLSR/bsp/src/time.c

+ 54
- 44
TrainCamp_zhangcheng_PLSR/app/src/plsr.c Целия файл

@@ -99,7 +99,7 @@ int32_t uniformTime = 0;
int32_t uniformPulse = 0;
uint8_t currentSegment = 0;
uint32_t currentSpeed = 0;
uint8_t RunFlag = 0;

int32_t pulseFreq = 168 - 1;
uint32_t pulseReload = 20;
@@ -109,16 +109,29 @@ SEGMENT_PART currentSeg = {
.currentPart = 1
};
PLSR plsr = {
.segmentAllNum = 1,
.segment[0].jumpNumber = 0
};
.segmentAllNum = 4,
.defaultSpeed = 1000,
.defaultAccSpeedTime = 5,
.defaultDecSpeedTime = 10,
.segment[0].pulseFreq = 2000,
.segment[0].pulseNumber = 1000,
.segment[0].jumpNumber = 0,
.segment[1].pulseFreq = 3000,
.segment[1].pulseNumber = 2000,
.segment[1].jumpNumber = 0,
.segment[2].pulseFreq = 6000,
.segment[2].pulseNumber = 2000,
.segment[2].jumpNumber = 0,
.segment[3].pulseFreq = 9000,
.segment[3].pulseNumber = 2000,
.segment[3].jumpNumber = 0,
.startRunSegment = 0
};
void PlsrModuleTask(void *pArg)
{
int8_t res;
uint8_t pArgment = 0;
uint8_t RunFlag = 0;


uint8_t nextSegment = plsr.startRunSegment;

@@ -134,28 +147,25 @@ uint8_t RunFlag = 0;
tim10.pwmInit(&tim10);
tim10.pwmSetPulse(&tim10, TIM10->ARR);

plsr.sendEnableState = 0;
plsr.sendEnableState = 1;
plsr.accDecSpeedMode = STRAIGHT_LINE_MODE;
plsr.segment[0].pulseFreq = 2000;
plsr.segment[0].pulseNumber = 3000;
plsr.defaultSpeed = 1000;
plsr.defaultAccSpeedTime = 10;
plsr.defaultDecSpeedTime = 10;
currentSegment = plsr.startRunSegment;

while (1)
{
// ReadRegisterParam(&plsr);
currentSegment = plsr.currentSegment;

if (plsr.sendEnableState != 1)
{
continue;
}

if (plsr.segment[currentSegment].pulseFreq <= 5000)
pulseFreq = 1680 - 1;
pulseFreq = 3360 - 1;
else if ((plsr.segment[currentSegment].pulseFreq > 5000)
&& (plsr.segment[currentSegment].pulseFreq <= 100000))
pulseFreq = 84 - 1;
pulseFreq = 2 - 1;
else
continue;

@@ -216,9 +226,7 @@ uint8_t RunFlag = 0;
void TimCallBack(void *pArg)
{
uint16_t reloadValue = 0;
uint32_t diffValue;
static int32_t pulseCount = 0;
static uint8_t endFlag = 0;

pulseCount++;
if (currentSeg.currentPart == 1)
@@ -227,23 +235,20 @@ void TimCallBack(void *pArg)
{
case 2: ///< 加速
{
if ((currentSpeed + currentSeg.inc) >= plsr.segment[currentSegment].pulseFreq)
if ((currentSpeed + currentSeg.inc) >= plsr.segment[currentSegment].pulseFreq
|| (pulseCount > currentSeg.firstPartNum - 1))
{
diffValue = currentSpeed + currentSeg.inc - plsr.segment[currentSegment].pulseFreq;
currentSeg.inc = currentSeg.inc - diffValue;
currentSpeed = plsr.segment[currentSegment].pulseFreq;
currentSeg.currentPart = 2;
pulseCount = 0;
}
currentSpeed += currentSeg.inc;
else
currentSpeed += currentSeg.inc;
reloadValue = 168000000 / (TIM10->PSC + 1) / (currentSpeed);
tim10.setPer(&tim10, reloadValue - 1);
tim10.pwmSetPulse(&tim10, TIM10->ARR / 2 + 1);

if (pulseCount > currentSeg.firstPartNum - 1)
{
currentSeg.currentPart = 2;
pulseCount = 0;
tim10.registerIrq(&tim10, TimCallBack, &currentSeg.currentPart);
}
tim10.pwmSetPulse(&tim10, TIM10->ARR / 2 + 1);
break;
}
default:
@@ -254,23 +259,30 @@ void TimCallBack(void *pArg)
}
else if (currentSeg.currentPart == 2)
{
reloadValue = 168000000 / (TIM10->PSC + 1) / (currentSpeed);
tim10.setPer(&tim10, reloadValue - 1);
tim10.pwmSetPulse(&tim10, TIM10->ARR / 2 + 1);

if (pulseCount > currentSeg.secondPartNum - 1)
if (pulseCount > currentSeg.secondPartNum - 4)
{
currentSeg.currentPart = 3;
pulseCount = 0;
tim10.registerIrq(&tim10, TimCallBack, &currentSeg.currentPart);
if ((currentSegment == (plsr.segmentAllNum -1))
&& (plsr.segment[currentSegment].jumpNumber == 0))
{
currentSeg.currentPart = 3;
pulseCount = 0;
currentSeg.dec = currentSpeed / currentSeg.thirdPartNum;
return;
}

currentSeg.dec = currentSpeed / currentSeg.thirdPartNum;
currentSeg.currentPart = 1;
pulseCount = 0;
RunFlag = 0;
if (plsr.segment[currentSegment].jumpNumber == 0)
currentSegment++;
else
currentSegment = plsr.segment[currentSegment].jumpNumber;
}
}
else if (currentSeg.currentPart == 3)
{
if (((currentSpeed - currentSeg.dec) <= 0)
|| (pulseCount > currentSeg.thirdPartNum - 1))
|| (pulseCount > currentSeg.thirdPartNum))
{
pulseCount = 0;
currentSeg.currentPart = 1;
@@ -423,16 +435,14 @@ static void FirstSegmentProc(SEGMENT_PART *segmentPart)
incAll += segmentPart->inc;
if (plsr.segment[currentSegment].pulseFreq <= 5000)
{
tim10.setPsc(&tim10, 1680 - 1);
tim10.setPsc(&tim10, 3360 - 1);
if (currentSpeed != 0)
tim10.setPer(&tim10, 100000 / currentSpeed);
tim10.setPer(&tim10, 50000 / currentSpeed);
else
tim10.setPer(&tim10, 1000);
tim10.registerIrq(&tim10, TimCallBack, &currentSeg.currentPart);
tim10.open(&tim10);
tim10.openIrq(&tim10);
}
else
{


+ 13
- 1
TrainCamp_zhangcheng_PLSR/bsp/src/time.c Целия файл

@@ -70,19 +70,32 @@ int8_t TimInit(TIM_OBJ *tim, uint16_t psc, uint32_t per)
if (tim->TIM == TIM2)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
}
else if (tim->TIM == TIM10)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10,ENABLE);
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
}
else if (tim->TIM == TIM11)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11,ENABLE);
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
}
else if (tim->TIM == TIM13)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM13,ENABLE);
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
}
else if (tim->TIM == TIM14)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14,ENABLE);
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
}
else
return -1;

@@ -92,7 +105,6 @@ int8_t TimInit(TIM_OBJ *tim, uint16_t psc, uint32_t per)
else
TIM_InternalClockConfig(tim->TIM);

TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period=per;
TIM_TimeBaseInitStructure.TIM_Prescaler=psc;


Зареждане…
Отказ
Запис