训练营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.
 
 
 
 
 
 

78 lines
1.9 KiB

  1. #include "PLSR.h"
  2. #include "PSCARR.h"
  3. #include "tim.h"
  4. Pulse PulseOutput[10];
  5. BaseOption Base;
  6. int32_t PulseCount = 0;
  7. int32_t AllPulseCount = 0;
  8. /**
  9. * @brief 根据脉冲的频率设置对应的PSC和ARR
  10. * @param[in] Channel 脉冲通道(目前只有通道0)
  11. * @param[in] Ferquency 脉冲的频率
  12. * @return 无
  13. */
  14. void SetFrequency(uint8_t Channel, uint32_t Frequency)
  15. {
  16. Frequency_Change_PSC_And_ARR(Frequency, &psc, &arr);
  17. switch(Channel)
  18. {
  19. case 0: TIM10->ARR = arr, TIM10->PSC = psc, TIM10->CCR1 = arr / 2; break;
  20. }
  21. }
  22. /**
  23. * @brief 设置脉冲基本参数
  24. * @param[in] Pulse 第几段脉冲
  25. * @param[in] Ferquency 脉冲的频率
  26. * @param[in] Count 脉冲的数量
  27. * @param[in] Direction 脉冲的方向
  28. * @param[in] NextPulse 下一段脉冲
  29. * @return 无
  30. */
  31. void SetPulse(uint8_t Pulse, uint32_t Ferquency, int32_t Count, uint8_t Direction, int8_t NextPulse)
  32. {
  33. PulseOutput[Pulse].Frequency = Ferquency;
  34. PulseOutput[Pulse].PulseCount = Count;
  35. PulseOutput[Pulse].Direction = Direction;
  36. PulseOutput[Pulse].NextPulse = NextPulse;
  37. }
  38. /**
  39. * @brief 脉冲初始化
  40. * @param[in] StartPulse 起始脉冲段
  41. * @param[in] PulseMod 绝对1/相对0
  42. * @return 无
  43. */
  44. void PulseInit(uint8_t StartPulse, uint8_t PulseMod, int32_t MAX_Pulse)
  45. {
  46. Base.StartPulse = StartPulse;
  47. Base.PulseMod = PulseMod;
  48. Base.NowPulse = StartPulse;
  49. Base.MAX_Pulse = MAX_Pulse;
  50. }
  51. void PulseStart(void)
  52. {
  53. // SetPulse(Base.NowPulse, PulseOutput[Base.NowPulse].Frequency,
  54. // PulseOutput[Base.NowPulse].PulseCount,
  55. // PulseOutput[Base.NowPulse].Direction,
  56. // PulseOutput[Base.NowPulse].NextPulse
  57. // );
  58. SetFrequency(0, PulseOutput[Base.NowPulse].Frequency);
  59. HAL_TIM_PWM_Start_IT(&htim10, TIM_CHANNEL_1);
  60. }
  61. /**
  62. * @brief 获取加速度
  63. * @param[in] Start 起始脉冲频率
  64. * @param[in] End 目标脉冲频率
  65. * @param[in] AccCount 需要多少个脉冲完成加速
  66. * @return 加速度
  67. */
  68. int32_t GetAcc(int32_t Start, int32_t End, int32_t AccCount)
  69. {
  70. return (End - Start) / AccCount;
  71. }