训练营PLSR题目
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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