IRScan.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. /**************************** (C) COPYRIGHT 2015 Fortiortech shenzhen *****************************
  2. File Name : IRScan.c
  3. Author : Billy Long Fortiortech Market Dept
  4. Version : V1.0
  5. Date : 01/07/2015
  6. Description : This file contains main function used for Motor Control.
  7. ***************************************************************************************************
  8. All Rights Reserved
  9. **************************************************************************************************/
  10. /* Includes -------------------------------------------------------------------------------------*/
  11. #include <MyProject.h>
  12. #include <FU68xx_4_MCU.h>
  13. /* Private typedef ------------------------------------------------------------------------------*/
  14. /* Private define -------------------------------------------------------------------------------*/
  15. /* Private macro --------------------------------------------------------------------------------*/
  16. /* Private variables ----------------------------------------------------------------------------*/
  17. IRScan_TypeDef xdata IRScan;
  18. IRControl_TypeDef xdata IRControl;
  19. IRControl_AutoPowerDef AutoPowerState;
  20. LineControlSpeedDEF xdata LineSpeedState;
  21. uint8 NatureWinFlag = 0;
  22. /* Private function prototypes ------------------------------------------------------------------*/
  23. /* Private functions ----------------------------------------------------------------------------*/
  24. /* -------------------------------------------------------------------------------------------------
  25. Function Name : void IRInit(void)
  26. Description :
  27. Input : 无
  28. Output : 无
  29. -------------------------------------------------------------------------------------------------*/
  30. void IRInit(void)
  31. {
  32. IRControl.LEDONOFFStatus = 1;
  33. IRScan.BitValue = 0;
  34. IRScan.BitCnt = 0;
  35. IRScan.Bit0Cnt = 0;
  36. IRScan.ByteValue = 0;
  37. IRScan.UserCode = 0;
  38. IRScan.DataCode = 0;
  39. IRScan.IRReceiveFlag = 0;
  40. IRScan.CurrentUserCode = 0;
  41. IRScan.OldDataCodeMixTimes1 = 0;
  42. IRScan.OldDataCodeMixTimes0 = 0;
  43. IRScan.CurrentDataCode = 0;
  44. IRScan.DataCodeLengthCover = 1;
  45. IRScan.UserCodeLengthCover = 1;
  46. IRScan.DataCodeLengthCover = (IRScan.DataCodeLengthCover << (DataCodeLength)) - 1;
  47. IRScan.UserCodeLengthCover = (IRScan.UserCodeLengthCover << (UserCodeLength)) - 1;
  48. IRControl.FlagONOFF = 0;
  49. IRControl.FlagFR = 0;
  50. IRControl.FlagSpeed = 0;
  51. IRControl.TargetSpeed = 0;
  52. IRControl.ONOFFStatus = 0;
  53. IRControl.FlagNatureWind = 0;
  54. IRControl.FlagLED = 0;
  55. IRControl.FlagAutoPower = 0;
  56. IRControl.FlagUserCodeSave = 0;
  57. IRControl.FlagUserCodeSaveOFF = 0;
  58. IRControl.FlagUserCodeRead = 1; //上电读出一次UserCode
  59. IRControl.FlagLED1Protect = 0; //LED欠压过压保护标记
  60. IRControl.FlagLED2Protect = 0;
  61. IRScan.TempDataCode[0] = 0;
  62. IRScan.TempDataCode[1] = 0;
  63. IRScan.TempDataCode[2] = 0;
  64. IRScan.TempDataCode[3] = 0;
  65. IRScan.DataCodeNum = 0;
  66. IRScan.BYTE0 = 0;
  67. IRScan.BYTE1 = 0;
  68. IRScan.BYTE2 = 0;
  69. IRScan.BYTE3 = 0;
  70. IRScan.PID = 0;
  71. IRScan.B = 0;
  72. IRControl.NatureFlage = 0;
  73. IRScan.OverFlowStatus = 0;
  74. mcFRState.OldTargetSpeed = 1;
  75. mcFRState.FR = CCW;
  76. mcFRState.FlagFR = 0;
  77. mcFRState.FRStatus = 0;
  78. // Time.ReciveDelayFlage=0;
  79. // Time.ReciveDelayCount=0;
  80. // Time.PowerUpTimeCount=0;
  81. AutoPowerState.FlagAutoPower = 0;
  82. AutoPowerState.Timer10sec = 0;
  83. AutoPowerState.ShutDowntime = 0;
  84. AutoPowerState.CurrentTime = 0;
  85. #if (Motor_Speed_Control_Mode == SPEED_LOOP_CONTROL)
  86. {
  87. IRControl.SpeedLevel[0] = MOTOR_SPEED_LEVEL_0;
  88. IRControl.SpeedLevel[1] = MOTOR_SPEED_LEVEL_1;
  89. IRControl.SpeedLevel[2] = MOTOR_SPEED_LEVEL_2;
  90. IRControl.SpeedLevel[3] = MOTOR_SPEED_LEVEL_3;
  91. IRControl.SpeedLevel[4] = MOTOR_SPEED_LEVEL_4;
  92. IRControl.SpeedLevel[5] = MOTOR_SPEED_LEVEL_5;
  93. IRControl.SpeedLevel[6] = MOTOR_SPEED_LEVEL_6;
  94. }
  95. #elif (Motor_Speed_Control_Mode == POWER_LOOP_CONTROL)
  96. {
  97. IRControl.SpeedLevel[0] = MOTOR_POWER_LEVEL_0;
  98. IRControl.SpeedLevel[1] = MOTOR_POWER_LEVEL_1;
  99. IRControl.SpeedLevel[2] = MOTOR_POWER_LEVEL_2;
  100. IRControl.SpeedLevel[3] = MOTOR_POWER_LEVEL_3;
  101. IRControl.SpeedLevel[4] = MOTOR_POWER_LEVEL_4;
  102. IRControl.SpeedLevel[5] = MOTOR_POWER_LEVEL_5;
  103. IRControl.SpeedLevel[6] = MOTOR_POWER_LEVEL_6;
  104. }
  105. #endif
  106. LineSpeedState.TargetSpeed = 0;
  107. LineSpeedState.PreTargetSpeed = 0;
  108. }
  109. /* -------------------------------------------------------------------------------------------------
  110. Function Name : void IRValue(void)
  111. Description : 红外接收头解码
  112. Input : 无
  113. Output : 无
  114. -------------------------------------------------------------------------------------------------*/
  115. //void IRValue(void)
  116. //{
  117. // uint8 tempof1 = 0;
  118. // uint8 tempof2 = 0;
  119. //
  120. // if (IRScan.BitCnt == 0)
  121. // {
  122. // IRScan.Bit0Cnt = TIM3__DR;
  123. //
  124. // if ((IRScan.Bit0Cnt <= TempLeadCodeMax) && (IRScan.Bit0Cnt >= TempLeadCodeMin))
  125. // {
  126. // IRScan.BitCnt++;
  127. // }
  128. // }
  129. // else
  130. // {
  131. // IRScan.Bit0Cnt = TIM3__ARR - TIM3__DR;
  132. //
  133. // if ((IRScan.Bit0Cnt >= TempBitValue1Min) && (IRScan.Bit0Cnt <= TempBitValue1Max))
  134. // {
  135. // IRScan.BitValue = 1;
  136. // tempof1 = 0x00;
  137. // }
  138. // else if ((IRScan.Bit0Cnt >= TempBitValue0Min) && (IRScan.Bit0Cnt <= TempBitValue0Max))
  139. // {
  140. // IRScan.BitValue = 0;
  141. // tempof1 = 0x00;
  142. // }
  143. // else
  144. // {
  145. // tempof1 = 0xFF;
  146. // }
  147. //
  148. // if (tempof1 != 0xff)
  149. // {
  150. // if (IRScan.BitCnt <= UserCodeLength)
  151. // {
  152. // IRScan.ByteValue += (IRScan.BitValue << (UserCodeLength - IRScan.BitCnt));
  153. //
  154. // if (IRScan.BitCnt == UserCodeLength)
  155. // {
  156. // IRScan.UserCode = IRScan.ByteValue;
  157. // IRScan.ByteValue = 0;
  158. // }
  159. //
  160. // IRScan.BitCnt ++;
  161. // }
  162. // else
  163. // {
  164. // IRScan.ByteValue += (IRScan.BitValue << (DataCodeLength - (IRScan.BitCnt - UserCodeLength)));
  165. //
  166. // if (IRScan.BitCnt == AllCodeLength)
  167. // {
  168. // IRScan.DataCode = IRScan.ByteValue;
  169. // IRScan.ByteValue = 0;
  170. // IRScan.BitCnt = 0;
  171. //
  172. // // tempof2 = (uint8)IRScan.DataCode;
  173. // // tempof1 = IRScan.DataCode>>8;
  174. // // tempof1 = 0xff -tempof1-1;
  175. // // tempof1 = 0xff -tempof1;
  176. //
  177. // if (IRScan.UserCode == UserCodeDef)
  178. // {
  179. // IRScan.IRReceiveFlag = 1;
  180. // }
  181. // }
  182. // else
  183. // { IRScan.BitCnt ++; }
  184. // }
  185. // }
  186. // else
  187. // {
  188. // IRScan.ByteValue = 0;
  189. // IRScan.BitCnt = 0;
  190. // }
  191. // }
  192. //}
  193. /* -------------------------------------------------------------------------------------------------
  194. Function Name : void SetSpeed(uint8 SpeedLevel)
  195. Description : 速度设置
  196. Input : SpeedLevel:速度挡位
  197. Output : 无
  198. -------------------------------------------------------------------------------------------------*/
  199. void SetSpeed(uint8 SpeedLevel)
  200. {
  201. IRControl.TargetSpeed = SpeedLevel;
  202. if (!mcSpeedRamp.FlagONOFF)
  203. {
  204. mcSpeedRamp.FlagONOFF = 1;
  205. }
  206. IRControl.ONOFFStatus = 1;
  207. IRControl.FlagSpeed = 1;
  208. mcFRState.OldTargetSpeed = IRControl.TargetSpeed;
  209. NatureWinFlag = 0; //正反转切换后根据遥控档位启动
  210. IRControl.NatureFlage = 0;
  211. // SetBuzzer(1,1);
  212. }
  213. /* -------------------------------------------------------------------------------------------------
  214. Function Name : void SetAutoPower(uint16 Time)
  215. Description : 定时设置
  216. Input : Time:定时时长
  217. Output : 无
  218. -------------------------------------------------------------------------------------------------*/
  219. void SetAutoPower(uint16 Time)
  220. {
  221. IRControl.FlagAutoPower = 1;
  222. AutoPowerState.ShutDowntime = Time;
  223. }
  224. uint32 idata TempByteValue;
  225. uint16 buf1[32] = {0};
  226. uint8 k = 0;
  227. uint16 TIM4_DR_Temp = 0;
  228. uint16 TIM4_ARR_Temp = 0;
  229. ///*-------------------------------------------------------------------------------------------------
  230. // Function Name : void RFValue(void)
  231. // Description : RF接收头解码
  232. // Input : 无
  233. // Output : 无
  234. //-------------------------------------------------------------------------------------------------*/
  235. void IRValue(void)
  236. {
  237. static uint8 UserSavedStatus = 0;
  238. static uint8 UserSavedOffStatus = 0;
  239. static idata uint32 TempByteValueEff;
  240. static idata uint32 TempBitValue;
  241. static idata uint8 effect_value = 0;
  242. uint8 tempof1 = 0;
  243. TIM4_ARR_Temp = TIM4__ARR;
  244. TIM4_DR_Temp = TIM4__DR;
  245. IRScan.Bit0Cnt = TIM4_ARR_Temp - TIM4_DR_Temp;
  246. //读出高电平
  247. //两组遥控信号之间的低电平信号认为是第二组信号的起始信号,低电平长度6ms
  248. // if((TIM4_DR_Temp <= 15000)&&(TIM4_DR_Temp >= 12000)&&(IRScan.Bit0Cnt <= 2100)&&(IRScan.Bit0Cnt >= 1500))
  249. if ((TIM4_DR_Temp <= TempLeadCodeMax) && (TIM4_DR_Temp >= TempLeadCodeMin) && (IRScan.Bit0Cnt <= TempLeadCode0Max) && (IRScan.Bit0Cnt >= TempLeadCode0Min))
  250. {
  251. IRScan.BitCnt = 1;
  252. effect_value = 0;
  253. }
  254. if (IRScan.BitCnt == 1)
  255. {
  256. IRScan.BitCnt = 2;
  257. TempByteValue = 0;
  258. TempByteValueEff = 0;
  259. }
  260. else if (IRScan.BitCnt >= 2)
  261. {
  262. IRScan.Bit0Cnt = TIM4__DR;
  263. // buf1[k] = IRScan.Bit0Cnt;
  264. // if(++k == 32)
  265. // {
  266. // k = 0;
  267. // }
  268. if ((IRScan.Bit0Cnt >= TempBitValue1Min) && (IRScan.Bit0Cnt <= TempBitValue1Max))
  269. {
  270. //当前数据为1
  271. TempBitValue = 1;
  272. tempof1 = 0x00;
  273. }
  274. else if ((IRScan.Bit0Cnt >= TempBitValue0Min) && (IRScan.Bit0Cnt <= TempBitValue0Max))
  275. {
  276. //当前数据为0
  277. TempBitValue = 0;
  278. tempof1 = 0x00;
  279. }
  280. else
  281. {
  282. tempof1 = 0xff; //当前数据电平长度不符合要求
  283. }
  284. if (tempof1 != 0xff)
  285. {
  286. /****************************遥控解码部分**************/
  287. //存储有效数据至对应位
  288. TempByteValue += (TempBitValue << ((AllCodeLength - 1) - (IRScan.BitCnt - 2)));
  289. IRScan.BitCnt ++;
  290. //接收满24位数据时进行处理(数据长度实际为25位,最后一位在起始信号时读取)
  291. if ((IRScan.BitCnt - 2) == AllCodeLength)
  292. {
  293. IRScan.DataCode = (TempByteValue) & 0XFFFF;
  294. //存储当前遥控地址吗
  295. IRScan.UserCode = (TempByteValue >> 16) & 0XFFFF;
  296. TempByteValue = 0;
  297. if (IRScan.UserCode == 0x00ff)
  298. {
  299. if (IRScan.DataCode == 0x8877)
  300. {
  301. if (KeySpeed == 0) //处于关机状态按下该按键则以一档速度运行并短“滴”一声
  302. {
  303. KeySpeed = 1;
  304. SetBuzzer(1, 1);
  305. SetSpeed_LEDPin;
  306. }
  307. else //处于开机状态按下该按键则关机并长“滴”一声
  308. {
  309. KeySpeed = 0;
  310. SetBuzzer(5, 1);
  311. ResetSpeed_LEDPin;
  312. YaoTou_Flag = 0;
  313. ResetYaoTou_LEDPin;
  314. }
  315. }
  316. else if (IRScan.DataCode == 0x6897)//摇头
  317. {
  318. if (KeySpeed) //只有在主控电机运行时才开摇头
  319. {
  320. YaoTou_Flag ^= 1;
  321. if (YaoTou_Flag) //
  322. {
  323. SetBuzzer(1, 1);
  324. SetYaoTou_LEDPin;
  325. }
  326. else
  327. {
  328. SetBuzzer(1, 2);
  329. ResetYaoTou_LEDPin;
  330. }
  331. }
  332. }
  333. else if (IRScan.DataCode == 0x48b7)//加大风量并短“滴”一声
  334. {
  335. if (KeySpeed != 0)
  336. {
  337. if (KeySpeed < 3)
  338. { KeySpeed++; }
  339. SetBuzzer(1, 1);
  340. SetSpeed_LEDPin;
  341. }
  342. }
  343. else if (IRScan.DataCode == 0xa857)//减小风量并短“滴”一声
  344. {
  345. if (KeySpeed != 0)
  346. {
  347. if (KeySpeed > 1)
  348. { KeySpeed--; }
  349. SetSpeed_LEDPin;
  350. SetBuzzer(1, 1);
  351. }
  352. }
  353. }
  354. }
  355. }
  356. else
  357. {
  358. TempByteValue = 0;
  359. IRScan.BitCnt = 0;
  360. }
  361. }
  362. }
  363. /* -------------------------------------------------------------------------------------------------
  364. Function Name : void IRScanControl(void)
  365. Description : 遥控信号处理
  366. Input : 无
  367. Output : 无
  368. -------------------------------------------------------------------------------------------------*/
  369. void IRScanControl(void)
  370. {
  371. if (IRScan.IRReceiveFlag)
  372. {
  373. //Time.ReciveDelayFlage=1;
  374. if (IRScan.DataCode == IRFRCCW)
  375. { SetBuzzer(2, 2); }
  376. else
  377. { SetBuzzer(2, 1); }
  378. switch (IRScan.DataCode)
  379. {
  380. case IRALLOFF:
  381. {
  382. IRControl.ONOFFStatus = 0;
  383. IRControl.TargetSpeed = 0;
  384. IRControl.FlagSpeed = 1;
  385. mcSpeedRamp.FlagONOFF = 0;
  386. IRControl.NatureFlage = 0;
  387. //在反转过程中关机时退出反转状态
  388. mcFRState.FlagFR = 0;
  389. mcFRState.FRStatus = 0;
  390. NatureWinFlag = 0;
  391. if (IRControl.LEDONOFFStatus)
  392. {
  393. ResetLEDPin;
  394. IRControl.LEDONOFFStatus = 0;
  395. }
  396. break;
  397. }
  398. case IRONOFF:
  399. {
  400. if (mcSpeedRamp.FlagONOFF == 1)
  401. {
  402. IRControl.ONOFFStatus = 0;
  403. IRControl.TargetSpeed = 0;
  404. mcFRState.OldTargetSpeed = IRControl.TargetSpeed;
  405. mcSpeedRamp.FlagONOFF = 0;
  406. IRControl.NatureFlage = 0;
  407. //在反转过程中关机时退出反转状态
  408. mcFRState.FlagFR = 0;
  409. mcFRState.FRStatus = 0;
  410. IRControl.FlagSpeed = 1;
  411. NatureWinFlag = 0;
  412. }
  413. break;
  414. }
  415. case IRFRCCW:
  416. {
  417. if (mcFRState.FR == CCW)
  418. {
  419. if ((mcState == mcRun) || (mcState == mcStart))
  420. { IRControl.FlagFR = 1; }
  421. else if ((mcState == mcReady) || (mcState == mcFault))
  422. {
  423. mcFRState.FR = CW;
  424. if (IRControl.TargetSpeed == 0)
  425. { SetSpeed(3); }
  426. else
  427. { SetSpeed(IRControl.TargetSpeed); }
  428. }
  429. }
  430. else
  431. {
  432. IRControl.FlagFR = 0;
  433. if (!NatureWinFlag)
  434. {
  435. if (IRControl.TargetSpeed == 0)
  436. { SetSpeed(3); }
  437. else
  438. { SetSpeed(IRControl.TargetSpeed); }
  439. }
  440. else
  441. {
  442. }
  443. }
  444. break;
  445. }
  446. case IRFRCW:
  447. {
  448. if (mcFRState.FR == CW)
  449. {
  450. if ((mcState == mcRun) || (mcState == mcStart))
  451. { IRControl.FlagFR = 1; }
  452. else if ((mcState == mcReady) || (mcState == mcFault))
  453. {
  454. mcFRState.FR = CCW;
  455. if (IRControl.TargetSpeed == 0)
  456. { SetSpeed(3); }
  457. else
  458. { SetSpeed(IRControl.TargetSpeed); }
  459. }
  460. }
  461. else
  462. {
  463. IRControl.FlagFR = 0;
  464. if (!NatureWinFlag)
  465. {
  466. if (IRControl.TargetSpeed == 0)
  467. { SetSpeed(3); }
  468. else
  469. { SetSpeed(IRControl.TargetSpeed); }
  470. }
  471. else
  472. {
  473. }
  474. }
  475. break;
  476. }
  477. case IRLED:
  478. {
  479. IRControl.FlagLED = 1;
  480. break;
  481. }
  482. case IRSpeed1:
  483. {
  484. SetSpeed(1);
  485. break;
  486. }
  487. case IRSpeed2:
  488. {
  489. SetSpeed(2);
  490. break;
  491. }
  492. case IRSpeed3:
  493. {
  494. SetSpeed(3);
  495. break;
  496. }
  497. case IRSpeed4:
  498. {
  499. SetSpeed(4);
  500. break;
  501. }
  502. case IRSpeed5:
  503. {
  504. SetSpeed(5);
  505. break;
  506. }
  507. case IRSpeed6:
  508. {
  509. SetSpeed(6);
  510. break;
  511. }
  512. case IRAUTOPOWER1H:
  513. {
  514. SetAutoPower(360); //360*10s =3600s =1h
  515. break;
  516. }
  517. case IRAUTOPOWER2H:
  518. {
  519. SetAutoPower(720);
  520. break;
  521. }
  522. case IRAUTOPOWER4H:
  523. {
  524. SetAutoPower(1400);
  525. break;
  526. }
  527. case IRNatureWind:
  528. {
  529. if (!IRControl.ONOFFStatus)
  530. {
  531. IRControl.ONOFFStatus = 1;
  532. mcSpeedRamp.FlagONOFF = 1;
  533. }
  534. if (!NatureWinFlag)
  535. {
  536. // mcFRState.OldTargetSpeed = 1;
  537. // IRControl.TargetSpeed = mcFRState.OldTargetSpeed;
  538. IRControl.TargetSpeed = NatureWinCode[0];
  539. mcFRState.OldTargetSpeed = IRControl.TargetSpeed;
  540. IRControl.FlagSpeed = 1;
  541. IRControl.NatureFlage = 1;
  542. //IRControl.FlagSpeed = 1;
  543. NatureWinFlag = 1;
  544. }
  545. break;
  546. }
  547. default:
  548. break;
  549. }
  550. IRScan.IRReceiveFlag = 0;
  551. }
  552. }
  553. /* -------------------------------------------------------------------------------------------------
  554. Function Name : void AutoPowerControl(void)
  555. Description : 自动控制开关机
  556. Input : 无
  557. Output : 无
  558. -------------------------------------------------------------------------------------------------*/
  559. void AutoPowerControl(void)
  560. {
  561. if (IRControl.FlagAutoPower)
  562. {
  563. // if (AutoPowerState.FlagAutoPower)
  564. // {
  565. // AutoPowerState.FlagAutoPower = 0;
  566. // }
  567. // else
  568. // {
  569. AutoPowerState.FlagAutoPower = 1;
  570. // }
  571. AutoPowerState.Timer10sec = 0; //每次按遥控重新计时
  572. AutoPowerState.CurrentTime = 0;
  573. IRControl.FlagAutoPower = 0;
  574. }
  575. //自动关机
  576. if ((AutoPowerState.FlagAutoPower && IRControl.ONOFFStatus) || ( AutoPowerState.FlagAutoPower && IRControl.LEDONOFFStatus))
  577. {
  578. AutoPowerState.Timer10sec++;
  579. if (AutoPowerState.Timer10sec > 10000)
  580. {
  581. AutoPowerState.Timer10sec = 0;
  582. AutoPowerState.CurrentTime++;
  583. if (AutoPowerState.CurrentTime >= AutoPowerState.ShutDowntime)
  584. {
  585. // if(IRControl.ONOFFStatus)
  586. // {
  587. IRControl.ONOFFStatus = 0;
  588. mcFRState.OldTargetSpeed = 0;
  589. IRControl.TargetSpeed = 0;
  590. mcSpeedRamp.FlagONOFF = 0;
  591. // }
  592. // else
  593. // {
  594. // IRControl.ONOFFStatus =1;
  595. // PIControlTime = SPEED_LOOP_TIME;
  596. // IRControl.TargetSpeed = MOTOR_POWER_LEVEL_1;
  597. // }
  598. // IRControl.FlagONOFF = 1;
  599. // BZScan.FlagBZ = 1;
  600. IRControl.FlagSpeed = 1;
  601. if (IRControl.LEDONOFFStatus)
  602. {
  603. ResetLEDPin;
  604. IRControl.LEDONOFFStatus = 0;
  605. }
  606. AutoPowerState.CurrentTime = 0;
  607. AutoPowerState.FlagAutoPower = 0;
  608. }
  609. }
  610. }
  611. else
  612. {
  613. AutoPowerState.FlagAutoPower = 0;
  614. AutoPowerState.Timer10sec = 0;
  615. AutoPowerState.ShutDowntime = 0;
  616. AutoPowerState.CurrentTime = 0;
  617. }
  618. }
  619. /* -------------------------------------------------------------------------------------------------
  620. Function Name : uint8 GetUserCode(void)
  621. Description : LED显示,IO口电平变化实现
  622. Input : 无
  623. Output : 无
  624. -------------------------------------------------------------------------------------------------*/
  625. void LEDDisplay(void)
  626. {
  627. // static uint8 LEDDiaplayStatus = 0;
  628. if (IRControl.FlagLED)
  629. {
  630. if (IRControl.LEDONOFFStatus == 0)
  631. {
  632. SetLEDPin;
  633. // IRControl.ONOFFStatus=1;
  634. IRControl.LEDONOFFStatus = 1;
  635. }
  636. else
  637. {
  638. // IRControl.ONOFFStatus=0;
  639. ResetLEDPin;
  640. IRControl.LEDONOFFStatus = 0;
  641. }
  642. IRControl.FlagLED = 0;
  643. }
  644. }
  645. void IRONOFF_Control(void)
  646. {
  647. if ((mcSpeedRamp.TargetValue == 0) && (mcState != mcRun) && (mcState != mcStop))
  648. {
  649. //关机后堵转保护次数和缺相保护次数清零
  650. mcProtectTime.SecondStartTimes = 0;
  651. mcProtectTime.StallTimes = 0;
  652. mcProtectTime.LossPHTimes = 0;
  653. mcProtectTime.CurrentPretectTimes = 0;
  654. }
  655. }
  656. void NatureWind(void)
  657. {
  658. static uint16 NatureWindCnt = 0;
  659. static uint8 NatureWindStep = 0;
  660. static uint8 FlageAddorDelace = 0;
  661. // if ((!NatureWinFlag) || (IRControl.FlagFR) || (!IRControl.ONOFFStatus) || (mcState != mcRun))
  662. // {
  663. // NatureWindCnt = 0;
  664. // NatureWindStep = 0;
  665. // return;
  666. // }
  667. // else
  668. // {
  669. NatureWindCnt++;
  670. // }
  671. // IRControl.ONOFFStatus =1;
  672. // mcSpeedRamp.FlagONOFF = 1;
  673. if (NatureWindCnt > 5000)
  674. {
  675. NatureWindCnt = 0;
  676. if (FlageAddorDelace == 0)
  677. {
  678. if (NatureWindStep < 5)
  679. { NatureWindStep++; }
  680. else
  681. {
  682. NatureWindStep = 5;
  683. FlageAddorDelace = 1;
  684. }
  685. IRControl.TargetSpeed = NatureWinCode[NatureWindStep];
  686. IRControl.FlagSpeed = 1;
  687. }
  688. else if (FlageAddorDelace)
  689. {
  690. if (NatureWindStep > 0)
  691. { NatureWindStep--; }
  692. else
  693. {
  694. NatureWindStep = 0;
  695. FlageAddorDelace = 0;
  696. }
  697. IRControl.TargetSpeed = NatureWinCode[NatureWindStep];
  698. IRControl.FlagSpeed = 1;
  699. }
  700. }
  701. }