训练营PLSR题目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

700 lines
18 KiB

  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2025 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. #include "dma.h"
  22. #include "tim.h"
  23. #include "usart.h"
  24. #include "gpio.h"
  25. /* Private includes ----------------------------------------------------------*/
  26. /* USER CODE BEGIN Includes */
  27. #include "PLSR.h"
  28. #include "includes.h"
  29. #include "modbus.h"
  30. #include "bitset.h"
  31. /* USER CODE END Includes */
  32. /* Private typedef -----------------------------------------------------------*/
  33. /* USER CODE BEGIN PTD */
  34. uint8_t ArrFlag = 0; /* 加速度Flag */
  35. float Acc; /* 加速度 */
  36. double AccUp;
  37. double AccDown;
  38. int32_t AllPulseCNT = 0;
  39. int32_t BaseCNT = 0;
  40. int32_t CNT_Only[11] = {0};
  41. uint32_t N_Acc = 0;
  42. uint8_t EXT_Flag = 0;
  43. uint8_t PulseStartFlag = 0;
  44. uint32_t ArrTimes = 0;
  45. uint8_t FixArrFlag = 0;
  46. uint8_t PulseRuning = 0;
  47. extern uint8_t Register_H[16384]; ///<寄存器的高字节
  48. extern uint8_t Register_L[16384]; ///<寄存器的低字节
  49. /* USER CODE END PTD */
  50. /* Private define ------------------------------------------------------------*/
  51. /* USER CODE BEGIN PD */
  52. /* USER CODE END PD */
  53. /* Private macro -------------------------------------------------------------*/
  54. /* USER CODE BEGIN PM */
  55. /* USER CODE END PM */
  56. /* Private variables ---------------------------------------------------------*/
  57. /* USER CODE BEGIN PV */
  58. /* USER CODE END PV */
  59. /* Private function prototypes -----------------------------------------------*/
  60. void SystemClock_Config(void);
  61. /* USER CODE BEGIN PFP */
  62. /* USER CODE END PFP */
  63. /* Private user code ---------------------------------------------------------*/
  64. /* USER CODE BEGIN 0 */
  65. /* 任务优先级 */
  66. #define TASK_Y1Direction 6
  67. #define TASK_PulseStart 5
  68. #define TASK_DirOutput 6
  69. #define TASK_PulseGetCount 5
  70. #define TASK_EXTSet 6
  71. /* 任务堆栈大小 */
  72. #define Task_Y1Direction_SIZE 256
  73. #define Task_PulseStart_SIZE 512
  74. #define Task_DirOutput_SIZE 256
  75. #define Task_PulseGetCount_SIZE 256
  76. #define Task_EXTSet_SIZE 256
  77. /* 任务控制块 */
  78. OS_TCB Y1Direction_Tsk;
  79. OS_TCB PulseStart_Tsk;
  80. OS_TCB DirOutput_Tsk;
  81. OS_TCB PulseGetCount_Tsk;
  82. OS_TCB EXTSet_Tsk;
  83. /* 任务栈 */
  84. CPU_STK Task_Y1Direction_STK[Task_Y1Direction_SIZE];
  85. CPU_STK Task_PulseStart_STK[Task_PulseStart_SIZE];
  86. CPU_STK Task_DirOutput_STK[Task_DirOutput_SIZE];
  87. CPU_STK Task_PulseGetCount_STK[Task_PulseGetCount_SIZE];
  88. CPU_STK Task_EXTSet_STK[Task_EXTSet_SIZE];
  89. /* 任务函数 */
  90. void Y1Direction(void *p_arg);
  91. void PulseStartTsk(void *p_arg);
  92. void DirOutput(void *p_arg);
  93. void PulseGetCount(void *p_arg);
  94. void EXTSet(void *p_arg);
  95. /* USER CODE END 0 */
  96. /**
  97. * @brief The application entry point.
  98. * @retval int
  99. */
  100. int main(void)
  101. {
  102. /* USER CODE BEGIN 1 */
  103. OS_ERR err;
  104. /* USER CODE END 1 */
  105. /* MCU Configuration--------------------------------------------------------*/
  106. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  107. HAL_Init();
  108. /* USER CODE BEGIN Init */
  109. /* USER CODE END Init */
  110. /* Configure the system clock */
  111. SystemClock_Config();
  112. /* USER CODE BEGIN SysInit */
  113. HAL_PWR_EnableBkUpAccess();/* 使能备份域访问 */
  114. __HAL_RCC_BKPSRAM_CLK_ENABLE();/* 使能备份SRAM时钟 */
  115. HAL_PWREx_EnableBkUpReg();/* 使能备份SRAM */
  116. /* USER CODE END SysInit */
  117. /* Initialize all configured peripherals */
  118. MX_GPIO_Init();
  119. MX_DMA_Init();
  120. MX_USART1_UART_Init();
  121. MX_TIM10_Init();
  122. MX_TIM2_Init();
  123. MX_TIM11_Init();
  124. MX_TIM13_Init();
  125. MX_TIM14_Init();
  126. MX_TIM3_Init();
  127. /* USER CODE BEGIN 2 */
  128. BSP_Init();
  129. OSInit(&err);
  130. CPU_SR_ALLOC();
  131. CPU_CRITICAL_ENTER();///进入临界区
  132. /* 任务1 */
  133. OSTaskCreate((OS_TCB * )&Y1Direction_Tsk, /* 任务控制块 */
  134. (CPU_CHAR* )"Y1Direction", /* 任务名字 */
  135. (OS_TASK_PTR)Y1Direction, /* 任务函数 */
  136. (void * )0, /* 传递给任务函数的参数 */
  137. (OS_PRIO )TASK_Y1Direction, /* 任务优先级 */
  138. (CPU_STK * )&Task_Y1Direction_STK[0], /* 任务堆栈基地址 */
  139. (CPU_STK_SIZE)Task_Y1Direction_SIZE/10, /* 任务堆栈深度限位 */
  140. (CPU_STK_SIZE)Task_Y1Direction_SIZE, /* 任务堆栈大小 */
  141. (OS_MSG_QTY)0,/* 任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息 */
  142. (OS_TICK )0,/* 当使能时间片轮转时的时间片长度,为0时为默认长度 */
  143. (void * )0,/* 用户补充的存储区 */
  144. (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,/* 任务选项 */
  145. (OS_ERR * )&err);/* 存放该函数错误时的返回值 */
  146. /* 任务2 */
  147. OSTaskCreate((OS_TCB * )&PulseStart_Tsk,
  148. (CPU_CHAR* )"PulseStartTsk",
  149. (OS_TASK_PTR)PulseStartTsk,
  150. (void * )0,
  151. (OS_PRIO )TASK_PulseStart,
  152. (CPU_STK * )&Task_PulseStart_STK[0],
  153. (CPU_STK_SIZE)Task_PulseStart_SIZE/10,
  154. (CPU_STK_SIZE)Task_PulseStart_SIZE,
  155. (OS_MSG_QTY)0,
  156. (OS_TICK )0,
  157. (void * )0,
  158. (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
  159. (OS_ERR * )&err);
  160. /* 任务3 */
  161. OSTaskCreate((OS_TCB * )&DirOutput_Tsk,
  162. (CPU_CHAR* )"DirOutput_Tsk",
  163. (OS_TASK_PTR)DirOutput,
  164. (void * )0,
  165. (OS_PRIO )TASK_DirOutput,
  166. (CPU_STK * )&Task_DirOutput_STK[0],
  167. (CPU_STK_SIZE)Task_DirOutput_SIZE/10,
  168. (CPU_STK_SIZE)Task_DirOutput_SIZE,
  169. (OS_MSG_QTY)0,
  170. (OS_TICK )0,
  171. (void * )0,
  172. (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
  173. (OS_ERR * )&err);
  174. /* 任务4 */
  175. OSTaskCreate((OS_TCB * )&PulseGetCount_Tsk,
  176. (CPU_CHAR* )"PulseGetCount_Tsk",
  177. (OS_TASK_PTR)PulseGetCount,
  178. (void * )0,
  179. (OS_PRIO )TASK_PulseGetCount,
  180. (CPU_STK * )&Task_PulseGetCount_STK[0],
  181. (CPU_STK_SIZE)Task_PulseGetCount_SIZE/10,
  182. (CPU_STK_SIZE)Task_PulseGetCount_SIZE,
  183. (OS_MSG_QTY)0,
  184. (OS_TICK )0,
  185. (void * )0,
  186. (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
  187. (OS_ERR * )&err);
  188. /* 任务5 */
  189. OSTaskCreate((OS_TCB * )&EXTSet_Tsk,
  190. (CPU_CHAR* )"EXTSet_Tsk",
  191. (OS_TASK_PTR)EXTSet,
  192. (void * )0,
  193. (OS_PRIO )TASK_EXTSet,
  194. (CPU_STK * )&Task_EXTSet_STK[0],
  195. (CPU_STK_SIZE)Task_EXTSet_SIZE/10,
  196. (CPU_STK_SIZE)Task_EXTSet_SIZE,
  197. (OS_MSG_QTY)0,
  198. (OS_TICK )0,
  199. (void * )0,
  200. (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
  201. (OS_ERR * )&err);
  202. /* 掉电数据读取 */
  203. ModbusLoadSRAM();
  204. PLSRPluseLoad(); //读取脉冲设置
  205. PLSROptionLoad(); //读取脉冲基础设置
  206. AccUp = (double)(Options.InitSpeed / Options.AccUpTime);
  207. AccDown = - (double)(Options.InitSpeed / Options.AccDownTime);
  208. NowFrequency = PulseOutput[Options.StartPulse].Frequency;
  209. NowPulse = Options.StartPulse;
  210. CPU_CRITICAL_EXIT() ; ///退出临界区
  211. OSStart(&err);
  212. /* USER CODE END 2 */
  213. /* Infinite loop */
  214. /* USER CODE BEGIN WHILE */
  215. while (1)
  216. {
  217. /* USER CODE END WHILE */
  218. /* USER CODE BEGIN 3 */
  219. }
  220. /* USER CODE END 3 */
  221. }
  222. /**
  223. * @brief System Clock Configuration
  224. * @retval None
  225. */
  226. void SystemClock_Config(void)
  227. {
  228. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  229. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  230. /** Configure the main internal regulator output voltage
  231. */
  232. __HAL_RCC_PWR_CLK_ENABLE();
  233. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  234. /** Initializes the RCC Oscillators according to the specified parameters
  235. * in the RCC_OscInitTypeDef structure.
  236. */
  237. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  238. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  239. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  240. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  241. RCC_OscInitStruct.PLL.PLLM = 6;
  242. RCC_OscInitStruct.PLL.PLLN = 72;
  243. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  244. RCC_OscInitStruct.PLL.PLLQ = 4;
  245. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  246. {
  247. Error_Handler();
  248. }
  249. /** Initializes the CPU, AHB and APB buses clocks
  250. */
  251. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  252. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  253. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  254. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  255. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  256. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  257. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  258. {
  259. Error_Handler();
  260. }
  261. }
  262. /* USER CODE BEGIN 4 */
  263. /**
  264. * @brief 任务1, 脉冲加减速
  265. * @return 无
  266. */
  267. void Y1Direction(void *p_arg)
  268. {
  269. p_arg = p_arg;
  270. OS_ERR err;
  271. while(1)
  272. {
  273. if (NowFrequency != PulseOutput[NowPulse].Frequency && PulseRuning == 1)/* 如果现在寄存器内的频率与实际输出的频率不一致 */
  274. {
  275. FixArrFlag = 1; //使能频率修改脉冲加减速
  276. HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */
  277. }
  278. /* 计算加速度(斜率) */
  279. AccUp = (double)(Options.InitSpeed / Options.AccUpTime);
  280. AccDown = - (double)(Options.InitSpeed / Options.AccDownTime);
  281. /* 挂起指定的时钟节拍 */
  282. OSTimeDly(100, OS_OPT_TIME_DLY, &err);
  283. }
  284. }
  285. /**
  286. * @brief 任务2,脉冲开始,数据处理
  287. * @return 无
  288. */
  289. void PulseStartTsk(void *p_arg)
  290. {
  291. p_arg = p_arg;
  292. OS_ERR err;
  293. uint8_t EN = 1;
  294. while(1)
  295. {
  296. PLSRPluseLoad(); //读取脉冲设置
  297. PLSROptionLoad(); //读取脉冲基础设置
  298. if (Register_L[0x3000] == 0x01 && EN == 1)
  299. {
  300. EN = 0;
  301. PulseStartFlag = 1; /* 脉冲第一段开始标志位 */
  302. PulseRuning = 1; /* 脉冲进行中标志位 */
  303. NowFrequency = PulseOutput[NowPulse].Frequency; /* 保存当前脉冲的频率 */
  304. HAL_TIM_Base_Start_IT(&htim3); /* 启动定时器3和中断 */
  305. }
  306. else if (Register_L[0x3000] == 0x02 && EN == 0)
  307. {
  308. EN = 1;
  309. }
  310. ModbusSaveSRAM();
  311. OSTimeDly(10, OS_OPT_TIME_DLY, &err); // 延时 10 个节拍
  312. }
  313. }
  314. /**
  315. * @brief 任务3,脉冲方向输出
  316. * @return 无
  317. */
  318. void DirOutput(void *p_arg)
  319. {
  320. p_arg = p_arg;
  321. OS_ERR err;
  322. while(1)
  323. {
  324. /* 根据当前的方向和输出的方向的端口进行输出的配置 */
  325. if (Options.DirPost == 0)
  326. {
  327. if (Options.Dir == 1)
  328. {
  329. HAL_GPIO_WritePin(GPIOH, Y12_Pin, GPIO_PIN_SET);
  330. }
  331. else
  332. {
  333. HAL_GPIO_WritePin(GPIOH, Y12_Pin, GPIO_PIN_RESET);
  334. }
  335. }
  336. if (Options.DirPost == 1)
  337. {
  338. if (Options.Dir == 1)
  339. {
  340. HAL_GPIO_WritePin(GPIOH, Y13_Pin, GPIO_PIN_SET);
  341. }
  342. else
  343. {
  344. HAL_GPIO_WritePin(GPIOH, Y13_Pin, GPIO_PIN_RESET);
  345. }
  346. }
  347. if (Options.DirPost == 2)
  348. {
  349. if (Options.Dir == 1)
  350. {
  351. HAL_GPIO_WritePin(GPIOH, Y14_Pin, GPIO_PIN_SET);
  352. }
  353. else
  354. {
  355. HAL_GPIO_WritePin(GPIOH, Y14_Pin, GPIO_PIN_RESET);
  356. }
  357. }
  358. if (Options.DirPost == 3)
  359. {
  360. if (Options.Dir == 1)
  361. {
  362. HAL_GPIO_WritePin(GPIOH, Y15_Pin, GPIO_PIN_SET);
  363. }
  364. else
  365. {
  366. HAL_GPIO_WritePin(GPIOH, Y15_Pin, GPIO_PIN_RESET);
  367. }
  368. }
  369. /* 预留时间给其他任务 */
  370. OSTimeDly(100, OS_OPT_TIME_DLY, &err); // 延时 100 个节拍
  371. }
  372. }
  373. /**
  374. * @brief 任务4,脉冲计数
  375. * @return 无
  376. */
  377. void PulseGetCount(void *p_arg)
  378. {
  379. p_arg = p_arg;
  380. OS_ERR err;
  381. while(1)
  382. {
  383. /* 根据当前脉冲的方向设置输出的方向 */
  384. if(PulseOutput[NowPulse].PulseCount < 0)
  385. {
  386. Options.Dir = 1;
  387. }
  388. else
  389. {
  390. Options.Dir = 0;
  391. }
  392. if (TIM2->CNT != 0) CNT_Only[NowPulse] = TIM2->CNT;
  393. AllPulseCNT = CNT_Only[0] + CNT_Only[1] + CNT_Only[2] + CNT_Only[3] +
  394. CNT_Only[4] + CNT_Only[5] + CNT_Only[6] + CNT_Only[7] +
  395. CNT_Only[8] + CNT_Only[9];
  396. CountSave();
  397. OSTimeDly(10, OS_OPT_TIME_DLY, &err);
  398. }
  399. }
  400. /**
  401. * @brief 任务5,EXT
  402. * @return 无
  403. */
  404. void EXTSet(void *p_arg)
  405. {
  406. p_arg = p_arg;
  407. OS_ERR err;
  408. uint8_t X4_Sta, X5_Sta;
  409. while(1)
  410. {
  411. if(HAL_GPIO_ReadPin(GPIOB, X4_Pin) == GPIO_PIN_SET)
  412. {
  413. OSTimeDly(10, OS_OPT_TIME_DLY, &err);
  414. if(HAL_GPIO_ReadPin(GPIOB, X4_Pin) == GPIO_PIN_SET)
  415. {
  416. X4_Sta = 1;
  417. while(HAL_GPIO_ReadPin(GPIOB, X4_Pin) == GPIO_PIN_SET);
  418. }
  419. }
  420. if(HAL_GPIO_ReadPin(GPIOG, X5_Pin) == GPIO_PIN_SET)
  421. {
  422. OSTimeDly(10, OS_OPT_TIME_DLY, &err);
  423. if(HAL_GPIO_ReadPin(GPIOG, X5_Pin) == GPIO_PIN_SET)
  424. {
  425. X5_Sta = 1;
  426. while(HAL_GPIO_ReadPin(GPIOG, X5_Pin) == GPIO_PIN_SET);
  427. }
  428. }
  429. /* X4引脚的EXT信号 */
  430. if(X4_Sta == 1 && Options.EXT == 0 && PulseOutput[NowPulse].EXT == 1)
  431. {
  432. if (TIM2->CNT != 0) CNT_Only[NowPulse] = TIM2->CNT; /* 保存当前的脉冲计数 */
  433. TIM2->CNT = TIM2->ARR - 1;
  434. EXT_Flag = 1;
  435. X4_Sta = 0;
  436. }
  437. else
  438. {
  439. X4_Sta = 0;
  440. }
  441. /* X5引脚的EXT信号 */
  442. if(X5_Sta == 1 && Options.EXT == 1 && PulseOutput[NowPulse].EXT == 1)
  443. {
  444. if (TIM2->CNT != 0) CNT_Only[NowPulse] = TIM2->CNT; /* 保存当前的脉冲计数 */
  445. TIM2->CNT = TIM2->ARR - 1;
  446. EXT_Flag = 1;
  447. X5_Sta = 0;
  448. }
  449. else
  450. {
  451. X5_Sta = 0;
  452. }
  453. if(EXT_Flag == 1)
  454. {
  455. EXT_Flag = 0;
  456. HAL_TIM_GenerateEvent(&htim2, TIM_EVENTSOURCE_UPDATE);
  457. }
  458. OSTimeDly(100, OS_OPT_TIME_DLY, &err);
  459. }
  460. }
  461. /**
  462. * @brief 定时器中断回调函数,用来实现脉冲加减速(定时时间1ms)
  463. * @return 无
  464. */
  465. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  466. {
  467. OSIntEnter(); /* 进入中断 */
  468. if (htim == (&htim3))
  469. {
  470. /* 段切换的加减速 */
  471. if (ArrFlag == 1)
  472. {
  473. /* 脉冲加速 */
  474. if (PulseOutput[NowPulse].Frequency > PulseOutput[PrePulse].Frequency) /* 如果当前的脉冲频率大于之前的脉冲频率 */
  475. {
  476. if (ArrTimes <= (int32_t)(PulseOutput[NowPulse].Frequency - PulseOutput[PrePulse].Frequency) / AccUp)
  477. {
  478. ArrTimes++;
  479. SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * AccUp);
  480. }
  481. else
  482. {
  483. SetFrequency(Options.SentPost, PulseOutput[NowPulse].Frequency);
  484. ArrTimes = 0;
  485. ArrFlag = 0;
  486. HAL_TIM_Base_Stop_IT(&htim3); // 停止定时器并禁用中断
  487. }
  488. }
  489. /* 脉冲减速 */
  490. else if (PulseOutput[NowPulse].Frequency <= PulseOutput[PrePulse].Frequency) /* 如果当前的脉冲频率小于之前的脉冲频率 */
  491. {
  492. if (ArrTimes <= (int32_t)(PulseOutput[NowPulse].Frequency - PulseOutput[PrePulse].Frequency) / AccDown)
  493. {
  494. SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * AccDown);
  495. // if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */
  496. ArrTimes++;
  497. }
  498. else
  499. {
  500. SetFrequency(Options.SentPost, PulseOutput[NowPulse].Frequency);
  501. ArrTimes = 0;
  502. ArrFlag = 0;
  503. HAL_TIM_Base_Stop_IT(&htim3); // 停止定时器并禁用中断
  504. }
  505. }
  506. }
  507. /* 实时修改频率的加减速 */
  508. if (FixArrFlag == 1)
  509. {
  510. /* 脉冲加速 */
  511. if (PulseOutput[NowPulse].Frequency > NowFrequency)
  512. {
  513. if (ArrTimes <= Options.AccUpTime)
  514. {
  515. SetFrequency(Options.SentPost, NowFrequency + ArrTimes * AccUp);
  516. ArrTimes++;
  517. }
  518. else
  519. {
  520. SetFrequency(Options.SentPost, PulseOutput[NowPulse].Frequency);
  521. NowFrequency = PulseOutput[NowPulse].Frequency;
  522. ArrTimes = 0;
  523. FixArrFlag = 0;
  524. HAL_TIM_Base_Stop_IT(&htim3); // 停止定时器并禁用中断
  525. }
  526. }
  527. /* 脉冲减速 */
  528. else if (PulseOutput[NowPulse].Frequency <= NowFrequency)
  529. {
  530. if (ArrTimes <= Options.AccDownTime)
  531. {
  532. SetFrequency(Options.SentPost, NowFrequency + ArrTimes * AccDown);
  533. // if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */
  534. ArrTimes++;
  535. }
  536. else
  537. {
  538. SetFrequency(Options.SentPost, PulseOutput[NowPulse].Frequency);
  539. NowFrequency = PulseOutput[NowPulse].Frequency;
  540. ArrTimes = 0;
  541. FixArrFlag = 0;
  542. HAL_TIM_Base_Stop_IT(&htim3); // 停止定时器并禁用中断
  543. }
  544. }
  545. }
  546. /* 第一段脉冲的加速 */
  547. if (NowPulse == Options.StartPulse && PulseStartFlag == 1)
  548. {
  549. SetFrequency(Options.SentPost, PulseOutput[NowPulse].Frequency);
  550. PulseStart();
  551. PulseStartFlag = 0;
  552. HAL_TIM_Base_Stop_IT(&htim3); // 停止定时器并禁用中断
  553. // if (ArrTimes <= PulseOutput[Options.StartPulse].Frequency / AccUp)
  554. // {
  555. // ArrTimes++;
  556. // SetFrequency(Options.SentPost, ArrTimes * AccUp);
  557. // if (ArrTimes == 1) PulseStart(); /* 开始产生脉冲 */
  558. //
  559. // }
  560. // else
  561. // {
  562. // SetFrequency(Options.SentPost, PulseOutput[NowPulse].Frequency);
  563. // PulseStartFlag = 0;
  564. // ArrTimes = 0;
  565. // HAL_TIM_Base_Stop_IT(&htim3); // 停止定时器并禁用中断
  566. // }
  567. }
  568. #ifdef Acc
  569. /* 最后一段脉冲的减速 */
  570. if (PulseRuning == 0 && NowPulse == 10)
  571. {
  572. if (ArrTimes < PulseOutput[PrePulse].Frequency / (- AccDown))
  573. {
  574. SetFrequency(Options.SentPost, PulseOutput[PrePulse].Frequency + ArrTimes * AccDown);
  575. // if (ArrTimes == 0) PulseStart(); /* 开始产生脉冲 */
  576. ArrTimes++;
  577. }
  578. else
  579. {
  580. ArrTimes = 0;
  581. FixArrFlag = 0;
  582. HAL_TIM_PWM_Stop_IT(&htim10,TIM_CHANNEL_1); /* 停止PWM输出 */
  583. HAL_TIM_Base_Stop_IT(&htim3); // 停止定时器并禁用中断
  584. }
  585. }
  586. #endif
  587. }
  588. OSIntExit(); /* 退出中断 */
  589. }
  590. /* USER CODE END 4 */
  591. /**
  592. * @brief This function is executed in case of error occurrence.
  593. * @retval None
  594. */
  595. void Error_Handler(void)
  596. {
  597. /* USER CODE BEGIN Error_Handler_Debug */
  598. /* User can add his own implementation to report the HAL error return state */
  599. __disable_irq();
  600. while (1)
  601. {
  602. }
  603. /* USER CODE END Error_Handler_Debug */
  604. }
  605. #ifdef USE_FULL_ASSERT
  606. /**
  607. * @brief Reports the name of the source file and the source line number
  608. * where the assert_param error has occurred.
  609. * @param file: pointer to the source file name
  610. * @param line: assert_param error line source number
  611. * @retval None
  612. */
  613. void assert_failed(uint8_t *file, uint32_t line)
  614. {
  615. /* USER CODE BEGIN 6 */
  616. /* User can add his own implementation to report the file name and line number,
  617. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  618. /* USER CODE END 6 */
  619. }
  620. #endif /* USE_FULL_ASSERT */