| @@ -41,10 +41,10 @@ extern float Acc; /* | |||
| extern uint8_t PulseNum; /* Âö³å¶Î¼ÆÊý */ | |||
| extern int32_t AllPulseCNT; | |||
| extern int32_t BaseCNT; | |||
| extern int32_t CNT_Only[10]; | |||
| extern int32_t CNT_Only[11]; | |||
| extern uint32_t N_Acc; | |||
| extern uint8_t EndFlag; | |||
| extern uint8_t FullFlag; | |||
| extern uint8_t PulseRuning; | |||
| /* USER CODE END ET */ | |||
| /* Exported constants --------------------------------------------------------*/ | |||
| @@ -37,14 +37,18 @@ | |||
| /* USER CODE BEGIN PTD */ | |||
| uint8_t ArrFlag = 0; /* 加速度Flag */ | |||
| float Acc; /* 加速度 */ | |||
| double AccUp; | |||
| double AccDown; | |||
| int32_t AllPulseCNT = 0; | |||
| int32_t BaseCNT = 0; | |||
| int32_t CNT_Only[10] = {0}; | |||
| int32_t CNT_Only[11] = {0}; | |||
| uint32_t N_Acc = 0; | |||
| uint8_t EXT_Flag = 0; | |||
| uint8_t PulseStartFlag = 0; | |||
| uint8_t ArrTimes = 0; | |||
| uint8_t FixArrFlag = 0; | |||
| uint8_t PulseRuning = 0; | |||
| extern uint8_t Register_H[16384]; ///<寄存器的高字节 | |||
| extern uint8_t Register_L[16384]; ///<寄存器的低字节 | |||
| @@ -79,7 +83,7 @@ void SystemClock_Config(void); | |||
| #define TASK_Y1Direction 6 | |||
| #define TASK_PulseStart 5 | |||
| #define TASK_DirOutput 6 | |||
| #define TASK_PulseGetCount 5 | |||
| #define TASK_PulseGetCount 4 | |||
| #define TASK_EXTSet 6 | |||
| /* 任务堆栈大小 */ | |||
| @@ -237,6 +241,8 @@ int main(void) | |||
| ModbusLoadSRAM(); | |||
| PLSRPluseLoad(); //读取脉冲设置 | |||
| PLSROptionLoad(); //读取脉冲基础设置 | |||
| AccUp = (double)(Options.InitSpeed / Options.AccUpTime); | |||
| AccDown = - (double)(Options.InitSpeed / Options.AccDownTime); | |||
| NowFrequency = PulseOutput[0].Frequency; | |||
| NowPulse = Options.StartPulse; | |||
| CPU_CRITICAL_EXIT() ; ///退出临界区 | |||
| @@ -313,7 +319,7 @@ void Y1Direction(void *p_arg) | |||
| while(1) | |||
| { | |||
| if (NowFrequency != PulseOutput[NowPulse].Frequency)/* 如果现在寄存器内的频率与实际输出的频率不一致 */ | |||
| if (NowFrequency != PulseOutput[NowPulse].Frequency && PulseRuning == 1)/* 如果现在寄存器内的频率与实际输出的频率不一致 */ | |||
| { | |||
| FixArrFlag = 1; //使能频率修改脉冲加减速 | |||
| if (PulseOutput[NowPulse].Frequency > NowFrequency) | |||
| @@ -326,7 +332,16 @@ void Y1Direction(void *p_arg) | |||
| } | |||
| HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */ | |||
| } | |||
| OSTimeDly(100, OS_OPT_TIME_DLY, &err); // 延时 100 个节拍 | |||
| /* 计算加速度(斜率) */ | |||
| AccUp = (double)(Options.InitSpeed / Options.AccUpTime); | |||
| AccDown = - (double)(Options.InitSpeed / Options.AccDownTime); | |||
| /* 计算当前段脉冲减速的脉冲数 */ | |||
| N_Acc = PulseOutput[NowPulse].Frequency / 2000 * Options.AccDownTime; | |||
| /* 挂起指定的时钟节拍 */ | |||
| OSTimeDly(100, OS_OPT_TIME_DLY, &err); | |||
| } | |||
| } | |||
| @@ -349,6 +364,7 @@ void PulseStartTsk(void *p_arg) | |||
| { | |||
| EN = 0; | |||
| PulseStartFlag = 1; | |||
| PulseRuning = 1; | |||
| NowFrequency = PulseOutput[NowPulse].Frequency; /* 保存当前脉冲的频率 */ | |||
| PulseStart(); | |||
| HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */ | |||
| @@ -538,7 +554,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |||
| { | |||
| if (ArrTimes <= Options.AccUpTime) | |||
| { | |||
| SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * Acc); | |||
| SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * AccUp); | |||
| if(ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ | |||
| ArrTimes++; | |||
| } | |||
| @@ -555,7 +571,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |||
| { | |||
| if (ArrTimes <= Options.AccDownTime) | |||
| { | |||
| SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * Acc); | |||
| SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * AccDown); | |||
| if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ | |||
| ArrTimes++; | |||
| } | |||
| @@ -576,7 +592,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |||
| { | |||
| if (ArrTimes <= Options.AccUpTime) | |||
| { | |||
| SetFrequency(Options.SentPost, NowFrequency + ArrTimes * Acc); | |||
| SetFrequency(Options.SentPost, NowFrequency + ArrTimes * AccUp); | |||
| if(ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ | |||
| ArrTimes++; | |||
| } | |||
| @@ -593,7 +609,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |||
| { | |||
| if (ArrTimes <= Options.AccDownTime) | |||
| { | |||
| SetFrequency(Options.SentPost, NowFrequency + ArrTimes * Acc); | |||
| SetFrequency(Options.SentPost, NowFrequency + ArrTimes * AccDown); | |||
| if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ | |||
| ArrTimes++; | |||
| } | |||
| @@ -610,11 +626,10 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |||
| /* 第一段脉冲的加速 */ | |||
| if (NowPulse == Options.StartPulse && PulseStartFlag == 1) | |||
| { | |||
| Acc = PulseOutput[NowPulse].Frequency / Options.AccUpTime;/* 计算加速度 */ | |||
| if(ArrTimes <= Options.AccUpTime) | |||
| if (ArrTimes <= Options.AccUpTime) | |||
| { | |||
| ArrTimes++; | |||
| SetFrequency(Options.SentPost, ArrTimes * Acc); | |||
| SetFrequency(Options.SentPost, ArrTimes * AccUp); | |||
| if (ArrTimes == 1) PulseStart(); /* 开始产生脉冲 */ | |||
| } | |||
| else | |||
| @@ -626,9 +641,21 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |||
| } | |||
| } | |||
| /* 最后一段脉冲的减速 */ | |||
| if(Options.AllPulse == PulseNum) | |||
| if (PulseRuning == 0) | |||
| { | |||
| Acc = - PulseOutput[NowPulse].Frequency / Options.AccUpTime;/* 计算加速度 */ | |||
| if (ArrTimes <= Options.AccDownTime) | |||
| { | |||
| SetFrequency(Options.SentPost, NowFrequency + ArrTimes * AccDown); | |||
| if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */ | |||
| ArrTimes++; | |||
| } | |||
| else | |||
| { | |||
| ArrTimes = 0; | |||
| FixArrFlag = 0; | |||
| HAL_TIM_PWM_Stop_IT(&htim10,TIM_CHANNEL_1); /* 停止PWM输出 */ | |||
| HAL_TIM_Base_Stop_IT(&htim3); // 停止定时器并禁用中断 | |||
| } | |||
| /* 思路: 在中断内计算正常情况下减速时间对应多少脉冲,在给最后一段脉冲赋值时减去对应的值,同时使能减速标志位 | |||
| 在此函数内实现最后一段脉冲的减速过程。 */ | |||
| } | |||
| @@ -236,23 +236,11 @@ void TIM2_IRQHandler(void) | |||
| else | |||
| { | |||
| NowPulse = PulseOutput[NowPulse].NextPulse - 1; /* 进入下一段脉冲 */ | |||
| } | |||
| /* 准备加减速 */ | |||
| if(PulseOutput[PrePulse].Frequency <= PulseOutput[NowPulse].Frequency) | |||
| { | |||
| Acc = GetAcc(PulseOutput[PrePulse].Frequency, | |||
| PulseOutput[NowPulse].Frequency, Options.AccUpTime); /* 计算加速度 */ | |||
| } | |||
| else | |||
| { | |||
| Acc = GetAcc(PulseOutput[PrePulse].Frequency, | |||
| PulseOutput[NowPulse].Frequency, Options.AccDownTime); /* 计算加速度 */ | |||
| } | |||
| } | |||
| ArrFlag = 1; | |||
| SetNextPulse();/* 设置下一次进入中断的脉冲数 */ | |||
| NowFrequency = PulseOutput[NowPulse].Frequency; /* 保存当前脉冲的频率 */ | |||
| HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */ | |||
| } | |||
| /* 如果之后没有脉冲 */ | |||
| @@ -260,7 +248,9 @@ void TIM2_IRQHandler(void) | |||
| { | |||
| PulseCount = 0; | |||
| ArrFlag = 0; | |||
| HAL_TIM_PWM_Stop_IT(&htim10,TIM_CHANNEL_1); /* 停止PWM输出 */ | |||
| PulseRuning = 0; | |||
| NowPulse = 10; | |||
| HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */ | |||
| } | |||
| } | |||
| @@ -285,17 +275,6 @@ void TIM2_IRQHandler(void) | |||
| else | |||
| { | |||
| NowPulse = PulseOutput[NowPulse].NextPulse - 1; /* 进入下一段脉冲 */ | |||
| } | |||
| /* 准备加减速 */ | |||
| if (PulseOutput[PrePulse].Frequency <= PulseOutput[NowPulse].Frequency) | |||
| { | |||
| Acc = GetAcc(PulseOutput[PrePulse].Frequency, | |||
| PulseOutput[NowPulse].Frequency, Options.AccUpTime); /* 计算加速度 */ | |||
| } | |||
| else | |||
| { | |||
| Acc = GetAcc(PulseOutput[PrePulse].Frequency, | |||
| PulseOutput[NowPulse].Frequency, Options.AccDownTime); /* 计算加速度 */ | |||
| } | |||
| ArrFlag = 1; | |||
| SetNextPulse();/* 设置下一次进入中断的脉冲数 */ | |||
| @@ -309,7 +288,8 @@ void TIM2_IRQHandler(void) | |||
| { | |||
| PulseCount = 0; | |||
| ArrFlag = 0; | |||
| HAL_TIM_PWM_Stop_IT(&htim10,TIM_CHANNEL_1); /* 停止PWM输出 */ | |||
| PulseRuning = 0; | |||
| HAL_TIM_PWM_Stop_IT(&htim10,TIM_CHANNEL_1); /* 停止PWM输出 */ | |||
| } | |||
| } | |||
| OSIntExit(); /* 退出中断 */ | |||
| @@ -153,7 +153,7 @@ | |||
| <RecentlyUsedMenus>1</RecentlyUsedMenus> | |||
| <MenuShadows>1</MenuShadows> | |||
| <ShowAllMenusAfterDelay>1</ShowAllMenusAfterDelay> | |||
| <CommandsUsage>C210000025001386000005000000298100000A00000010860000EE0500002CE100000200000029E1000004000000239200000600000020810000050000000F810000010000005F860000040000001D810000010000000C8100001000000004860000030000005986000001000000288100001100000056860000E90200002BE100000700000000840000030000001F810000FB0000000E81000002000000098600000100000025E10000010000000B8100000600000000E1000002000000148600003D0200005886000001000000278100000F0000000086000002000000058100000100000011860000320300000281000001000000468100001601000060860000010000001E810000060000005D86000016000000088600000500000005860000010000001686000001000000</CommandsUsage> | |||
| <CommandsUsage>6E110000250013860000050000002981000010000000108600002E0600002CE100000200000029E1000004000000239200000600000020810000060000000F810000010000005F860000040000001D810000010000000C8100001000000004860000030000005986000001000000288100001500000056860000F20200002BE100000700000000840000030000001F810000060100000E81000002000000098600000100000025E10000010000000B8100000600000000E10000020000001486000059020000588600000100000027810000100000000086000002000000058100000100000011860000580300000281000001000000468100002001000060860000010000001E810000060000005D86000016000000088600000500000005860000010000001686000001000000</CommandsUsage> | |||
| </MFCToolBarParameters> | |||
| <CommandManager> | |||
| <CommandsWithoutImages>300020870000238700002487000021870000198600000D8400000F84000008840000FFFFFFFF54840000328100001C810000098400002AE10000008200001C8200000182000067860000838600005886000004DC00007784000007840000808C000044D500007486000045D5000046D5000047D5000048D5000049D500004AD500004BD500004CD500001C8F00001E8F00001F8F0000208F0000218F0000118F000000DC000001DC000002DC000003DC0000A4860000A38600005486000059860000</CommandsWithoutImages> | |||
| @@ -1013,6 +1013,8 @@ | |||
| <item>PulseNum</item> | |||
| <item>CNT_Only</item> | |||
| <item>NowFrequency</item> | |||
| <item>AccUp</item> | |||
| <item>AccDown</item> | |||
| <item></item> | |||
| </expressions> | |||
| <col-names> | |||
| @@ -1121,7 +1123,7 @@ | |||
| </BasePane-34048> | |||
| <MFCToolBar-34049> | |||
| <Name>Debug</Name> | |||
| <Buttons>00200000010000000800FFFF01001100434D4643546F6F6C426172427574746F6E568600000000040035000000FFFEFF0000000000000000000000000001000000010000000180138600000000040031000000FFFEFF00000000000000000000000000010000000100000001805E8600000000040037000000FFFEFF0000000000000000000000000001000000010000000180608600000000040039000000FFFEFF00000000000000000000000000010000000100000001805D8600000000040036000000FFFEFF000000000000000000000000000100000001000000018010860000000004002F000000FFFEFF0000000000000000000000000001000000010000000180118600000000000030000000FFFEFF000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6E148600000000040032000000FFFEFF205200650073006500740020007400680065002000640065006200750067006700650064002000700072006F006700720061006D000A00520065007300650074000000000000000000000000000100000001000000000000000000000001000000060009802087000000000000FFFFFFFFFFFEFF06530079007300740065006D000100000000000000000000000100000001000000000000000000000001000000000009802387000000000000FFFFFFFFFFFEFF0443006F00720065000100000000000000000000000100000001000000000000000000000001000000000009802487000000000000FFFFFFFFFFFEFF0853006F006600740077006100720065000100000000000000000000000100000001000000000000000000000001000000000009802187000000000000FFFFFFFFFFFEFF12480061007200640077006100720065002000720065007300650074002000700069006E000100000000000000000000000100000001000000000000000000000001000000000009800000000000000400FFFFFFFFFFFEFF000000000000000000000000000100000001000000000000000000000001000000000009801986000000000000FFFFFFFFFFFEFF000100000000000000000000000100000001000000000000000000000001000000000000000000FFFEFF0544006500620075006700C6000000</Buttons> | |||
| <Buttons>00200000010000000800FFFF01001100434D4643546F6F6C426172427574746F6E568600000000000035000000FFFEFF0000000000000000000000000001000000010000000180138600000000000031000000FFFEFF00000000000000000000000000010000000100000001805E8600000000000037000000FFFEFF0000000000000000000000000001000000010000000180608600000000000039000000FFFEFF00000000000000000000000000010000000100000001805D8600000000000036000000FFFEFF000000000000000000000000000100000001000000018010860000000000002F000000FFFEFF0000000000000000000000000001000000010000000180118600000000040030000000FFFEFF000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6E148600000000000032000000FFFEFF205200650073006500740020007400680065002000640065006200750067006700650064002000700072006F006700720061006D000A00520065007300650074000000000000000000000000000100000001000000000000000000000001000000060009802087000000000000FFFFFFFFFFFEFF06530079007300740065006D000100000000000000000000000100000001000000000000000000000001000000000009802387000000000000FFFFFFFFFFFEFF0443006F00720065000100000000000000000000000100000001000000000000000000000001000000000009802487000000000000FFFFFFFFFFFEFF0853006F006600740077006100720065000100000000000000000000000100000001000000000000000000000001000000000009802187000000000000FFFFFFFFFFFEFF12480061007200640077006100720065002000720065007300650074002000700069006E000100000000000000000000000100000001000000000000000000000001000000000009800000000000000400FFFFFFFFFFFEFF000000000000000000000000000100000001000000000000000000000001000000000009801986000000000000FFFFFFFFFFFEFF000100000000000000000000000100000001000000000000000000000001000000000000000000FFFEFF0544006500620075006700C6000000</Buttons> | |||
| </MFCToolBar-34049> | |||
| <Pane-34049> | |||
| <ID>34049</ID> | |||
| @@ -1138,7 +1140,7 @@ | |||
| </BasePane-34049> | |||
| <MFCToolBar-34050> | |||
| <Name>Trace</Name> | |||
| <Buttons>00200000010000000200FFFF01001100434D4643546F6F6C426172427574746F6E539200000000040089000000FFFEFF03450054004D0000000000000000000000000001000000010000000180549200000000000025000000FFFEFF03530057004F00000000000000000000000000010000000100000000000000FFFEFF05540072006100630065002F000000</Buttons> | |||
| <Buttons>00200000010000000200FFFF01001100434D4643546F6F6C426172427574746F6E53920000000004008A000000FFFEFF03450054004D0000000000000000000000000001000000010000000180549200000000000025000000FFFEFF03530057004F00000000000000000000000000010000000100000000000000FFFEFF05540072006100630065002F000000</Buttons> | |||
| </MFCToolBar-34050> | |||
| <Pane-34050> | |||
| <ID>34050</ID> | |||
| @@ -20,7 +20,7 @@ | |||
| <LeaveTargetRunning>_ 0</LeaveTargetRunning> | |||
| </StLinkDriver> | |||
| <DebugChecksum> | |||
| <Checksum>4243162381</Checksum> | |||
| <Checksum>2476724192</Checksum> | |||
| </DebugChecksum> | |||
| <Exceptions> | |||
| <StopOnUncaught>_ 0</StopOnUncaught> | |||
| @@ -2,42 +2,30 @@ | |||
| <userBookmarks> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>315</row> | |||
| <row>375</row> | |||
| </bookmark> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>592</row> | |||
| <row>436</row> | |||
| </bookmark> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>318</row> | |||
| <row>466</row> | |||
| </bookmark> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>305</row> | |||
| <row>532</row> | |||
| </bookmark> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>333</row> | |||
| <row>342</row> | |||
| </bookmark> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>366</row> | |||
| <row>312</row> | |||
| </bookmark> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>427</row> | |||
| </bookmark> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>457</row> | |||
| </bookmark> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>523</row> | |||
| </bookmark> | |||
| <bookmark> | |||
| <path>C:\Users\Chiri\Desktop\TrainCamp-Jiangyunsong-PLSR\Core\Src\main.c</path> | |||
| <row>595</row> | |||
| <row>238</row> | |||
| </bookmark> | |||
| </userBookmarks> | |||
| @@ -33,7 +33,7 @@ int32_t PulseCount = 0; | |||
| void SetFrequency(uint8_t SentPost, uint32_t Frequency) | |||
| { | |||
| CalculatePSCARR(Frequency, 72000000, 65535, &psc, &arr); | |||
| printf("Fre=%d,",Frequency); | |||
| //printf("Fre=%d,",Frequency); | |||
| switch (SentPost) | |||
| { | |||
| case 0: TIM10->ARR = arr, TIM10->PSC = psc, TIM10->CCR1 = arr / 2; break; | |||
| @@ -102,11 +102,27 @@ void SetNextPulse(void) | |||
| { | |||
| if (PulseOutput[NowPulse].PulseCount > 0) | |||
| { | |||
| TIM2->ARR = PulseOutput[NowPulse].PulseCount; | |||
| if (Options.AllPulse - PulseNum == 1) | |||
| { | |||
| TIM2->ARR = PulseOutput[NowPulse].PulseCount - N_Acc; | |||
| } | |||
| else | |||
| { | |||
| TIM2->ARR = PulseOutput[NowPulse].PulseCount; | |||
| } | |||
| } | |||
| else | |||
| { | |||
| TIM2->ARR = - PulseOutput[NowPulse].PulseCount; | |||
| if (Options.AllPulse - PulseNum == 1) | |||
| { | |||
| TIM2->ARR = - PulseOutput[NowPulse].PulseCount - N_Acc; | |||
| } | |||
| else | |||
| { | |||
| TIM2->ARR = - PulseOutput[NowPulse].PulseCount; | |||
| } | |||
| } | |||
| } | |||