|
- #include "PLSR.h"
- #include "PSCARR.h"
- #include "tim.h"
-
- Pulse PulseOutput[10];
- BaseOption Base;
- int32_t PulseCount = 0;
- int32_t AllPulseCount = 0;
-
- /**
- * @brief 根据脉冲的频率设置对应的PSC和ARR
- * @param[in] Channel 脉冲通道(目前只有通道0)
- * @param[in] Ferquency 脉冲的频率
- * @return 无
- */
- void SetFrequency(uint8_t Channel, uint32_t Frequency)
- {
- Frequency_Change_PSC_And_ARR(Frequency, &psc, &arr);
- switch(Channel)
- {
- case 0: TIM10->ARR = arr, TIM10->PSC = psc, TIM10->CCR1 = arr / 2; break;
- }
-
- }
-
- /**
- * @brief 设置脉冲基本参数
- * @param[in] Pulse 第几段脉冲
- * @param[in] Ferquency 脉冲的频率
- * @param[in] Count 脉冲的数量
- * @param[in] Direction 脉冲的方向
- * @param[in] NextPulse 下一段脉冲
- * @return 无
- */
- void SetPulse(uint8_t Pulse, uint32_t Ferquency, int32_t Count, uint8_t Direction, int8_t NextPulse)
- {
- PulseOutput[Pulse].Frequency = Ferquency;
- PulseOutput[Pulse].PulseCount = Count;
- PulseOutput[Pulse].Direction = Direction;
- PulseOutput[Pulse].NextPulse = NextPulse;
- }
-
- /**
- * @brief 脉冲初始化
- * @param[in] StartPulse 起始脉冲段
- * @param[in] PulseMod 绝对1/相对0
- * @return 无
- */
- void PulseInit(uint8_t StartPulse, uint8_t PulseMod, int32_t MAX_Pulse)
- {
- Base.StartPulse = StartPulse;
- Base.PulseMod = PulseMod;
- Base.NowPulse = StartPulse;
- Base.MAX_Pulse = MAX_Pulse;
- }
-
- void PulseStart(void)
- {
- // SetPulse(Base.NowPulse, PulseOutput[Base.NowPulse].Frequency,
- // PulseOutput[Base.NowPulse].PulseCount,
- // PulseOutput[Base.NowPulse].Direction,
- // PulseOutput[Base.NowPulse].NextPulse
- // );
- SetFrequency(0, PulseOutput[Base.NowPulse].Frequency);
- HAL_TIM_PWM_Start_IT(&htim10, TIM_CHANNEL_1);
- }
- /**
- * @brief 获取加速度
- * @param[in] Start 起始脉冲频率
- * @param[in] End 目标脉冲频率
- * @param[in] AccCount 需要多少个脉冲完成加速
- * @return 加速度
- */
- int32_t GetAcc(int32_t Start, int32_t End, int32_t AccCount)
- {
- return (End - Start) / AccCount;
- }
|