bikelight.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. /**
  2. * @file Bikelight.c
  3. * @author
  4. * @brief light of ebike
  5. * @version 0.1
  6. * @date 2023-06-20
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. #define BIKELIGHT_
  12. /************************************************************************
  13. Beginning of File, do not put anything above here except notes
  14. Compiler Directives:
  15. *************************************************************************/
  16. #include "syspar.h"
  17. #include "typedefine.h"
  18. #include "mathtool.h"
  19. #include "bikelight.h"
  20. #include "hwsetup.h"
  21. #include "power.h"
  22. #include "CodePara.h"
  23. #include "adc.h"
  24. #include "UserGpio_Config.h"
  25. #include "ti_msp_dl_config.h"
  26. #include "bikebrake.h"
  27. //----------------------------
  28. BIKELEDCHECK_STR BikeLedCheck_F;//前灯参数
  29. BIKELEDCHECK_STR BikeLedCheck_B;//尾灯参数
  30. BIKELEDCHECK_STR BikeLedCheck_L;//左灯参数
  31. BIKELEDCHECK_STR BikeLedCheck_R;//右灯参数
  32. BIKELEDCHECK_STR BikeLedCheck_DC;//DC12V端口参数
  33. //LED_PWM_STR BikePwmChoice;
  34. void LED_EnableDeal(BIKELEDCHECK_STR *p,UWORD switchAction,LED_PWM_STR mode );
  35. void LedMode_One(BIKELEDCHECK_STR *BikeLedSel);//模式1 开灯低亮,刹车高亮
  36. void LedMode_Two(BIKELEDCHECK_STR *BikeLedSel);//模式2 开灯高亮,刹车闪烁
  37. void LedMode_Three(BIKELEDCHECK_STR *BikeLedSel);//模式3 刹车高亮
  38. void LedMode_Four(BIKELEDCHECK_STR *BikeLedSel);//模式4 刹车闪烁
  39. void LedMode_Five(BIKELEDCHECK_STR *BikeLedSel);//模式5 开机亮
  40. void LedMode_Six(BIKELEDCHECK_STR *BikeLedSel);//模式6 超速闪烁报警 国标车
  41. void LedMode_Seven(BIKELEDCHECK_STR *BikeLedSel);//模式7 开机低亮,刹车高亮
  42. void LedMode_Eight(BIKELEDCHECK_STR *BikeLedSel);//模式8 开灯亮,关灯灭
  43. // 函数指针类型定义
  44. typedef void (*FunctionPointer)(BIKELEDCHECK_STR *BikeLedSel);
  45. // 函数指针数组
  46. FunctionPointer ledfunctions[16] = {LedMode_One,LedMode_One, LedMode_Two, LedMode_Three, LedMode_Four,LedMode_Five,LedMode_Six,LedMode_Seven,LedMode_Eight,
  47. LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight};
  48. /***************************************************************
  49. Function: LedMode_One
  50. Description: //模式1 开灯低亮,刹车高亮
  51. Call by: 1ms
  52. Input Variables:
  53. Output/Return Variables: N/A
  54. Subroutine Call: N/A;
  55. Reference: N/A
  56. ****************************************************************/
  57. void LedMode_One(BIKELEDCHECK_STR *BikeLedSel)
  58. {
  59. if((BikeBrake_blGetstate()==TRUE)&&(cp_stBikeRunInfoPara.uwLightSwitch==0))//尾灯低亮,刹车高亮
  60. {
  61. if(BikeLedSel->uwLeddelaycnt>0)
  62. {
  63. BikeLedSel->uwLeddelaycnt--;
  64. BikeLedSel->blBike_LedSta=FALSE;
  65. }
  66. else
  67. {
  68. BikeLedSel->blBike_LedSta=TRUE;
  69. }
  70. }
  71. else
  72. {
  73. if(cp_stBikeRunInfoPara.uwLightSwitch!=0)
  74. {
  75. BikeLedSel->uwLedAddcnt++;
  76. if(BikeLedSel->uwLedAddcnt > BikeLedAddCycle)
  77. {
  78. BikeLedSel->uwLedAddcnt=0;
  79. }
  80. if(BikeLedSel->uwLedAddcnt<BikeLedAddDuty)
  81. {
  82. BikeLedSel->blBike_LedSta=TRUE;
  83. if(BikeBrake_blGetstate()==TRUE)
  84. {
  85. BikeLedSel->uwLedAddcnt=0;
  86. }
  87. }
  88. else
  89. {
  90. BikeLedSel->blBike_LedSta=FALSE;
  91. }
  92. }
  93. else
  94. {
  95. BikeLedSel->blBike_LedSta=FALSE;
  96. BikeLedSel->uwLedAddcnt=0;
  97. }
  98. BikeLedSel->uwLeddelaycnt=10;
  99. }
  100. }
  101. /***************************************************************
  102. Function: LedMode_Two
  103. Description: //模式2 开灯高亮,刹车闪烁
  104. Call by: 1ms
  105. Input Variables:
  106. Output/Return Variables: N/A
  107. Subroutine Call: N/A;
  108. Reference: N/A
  109. ****************************************************************/
  110. void LedMode_Two(BIKELEDCHECK_STR *BikeLedSel)
  111. {
  112. if(BikeBrake_blGetstate()==TRUE) //尾灯高亮,刹车闪烁
  113. {
  114. BikeLedSel->uwLedAddcnt++;
  115. if(BikeLedSel->uwLedAddcnt > BikeLedFlickerCycle)
  116. {
  117. BikeLedSel->uwLedAddcnt=0;
  118. }
  119. if(BikeLedSel->uwLedAddcnt<BikeLedFlickerDuty)
  120. {
  121. BikeLedSel->blBike_LedSta=TRUE;
  122. }
  123. else
  124. {
  125. BikeLedSel->blBike_LedSta=FALSE;
  126. }
  127. }
  128. else
  129. {
  130. if(cp_stBikeRunInfoPara.uwLightSwitch!=0)
  131. {
  132. BikeLedSel->blBike_LedSta=TRUE;
  133. }
  134. else
  135. {
  136. BikeLedSel->blBike_LedSta=FALSE;
  137. }
  138. BikeLedSel->uwLedAddcnt=0;
  139. }
  140. }
  141. /***************************************************************
  142. Function: LedMode_Three
  143. Description: 模式3 刹车高亮
  144. Call by: 1ms
  145. Input Variables:
  146. Output/Return Variables: N/A
  147. Subroutine Call: N/A;
  148. Reference: N/A
  149. ****************************************************************/
  150. void LedMode_Three(BIKELEDCHECK_STR *BikeLedSel)
  151. {
  152. if(BikeBrake_blGetstate()==TRUE) //刹车高亮
  153. {
  154. //BikeLedSel->blBike_LedSta=TRUE;
  155. if(BikeLedSel->uwLeddelaycnt>0)
  156. {
  157. BikeLedSel->uwLeddelaycnt--;
  158. BikeLedSel->blBike_LedSta=FALSE;
  159. }
  160. else
  161. {
  162. BikeLedSel->blBike_LedSta=TRUE;
  163. }
  164. }
  165. else
  166. {
  167. BikeLedSel->uwLeddelaycnt=20;
  168. BikeLedSel->blBike_LedSta=FALSE;
  169. }
  170. }
  171. /***************************************************************
  172. Function: LedMode_Four
  173. Description: 模式4 刹车闪烁
  174. Call by: 1ms
  175. Input Variables:
  176. Output/Return Variables: N/A
  177. Subroutine Call: N/A;
  178. Reference: N/A
  179. ****************************************************************/
  180. void LedMode_Four(BIKELEDCHECK_STR *BikeLedSel)
  181. {
  182. if(BikeBrake_blGetstate()==TRUE) //刹车闪烁
  183. {
  184. BikeLedSel->uwLedAddcnt++;
  185. if(BikeLedSel->uwLedAddcnt > BikeLedFlickerCycle)
  186. {
  187. BikeLedSel->uwLedAddcnt=0;
  188. }
  189. if(BikeLedSel->uwLedAddcnt<BikeLedFlickerDuty)
  190. {
  191. BikeLedSel->blBike_LedSta=TRUE;
  192. }
  193. else
  194. {
  195. BikeLedSel->blBike_LedSta=FALSE;
  196. }
  197. }
  198. else
  199. {
  200. BikeLedSel->blBike_LedSta=FALSE;
  201. }
  202. }
  203. /***************************************************************
  204. Function: LedMode_Five
  205. Description: 模式5 开机亮
  206. Call by: 1ms
  207. Input Variables:
  208. Output/Return Variables: N/A
  209. Subroutine Call: N/A;
  210. Reference: N/A
  211. ****************************************************************/
  212. void LedMode_Five(BIKELEDCHECK_STR *BikeLedSel)
  213. {
  214. BikeLedSel->blBike_LedSta=TRUE; //开机常亮
  215. }
  216. /***************************************************************
  217. Function: LedMode_Six
  218. Description: 模式6 超速闪烁报警 国标车
  219. Call by: 1ms
  220. Input Variables:
  221. Output/Return Variables: N/A
  222. Subroutine Call: N/A;
  223. Reference: N/A
  224. ****************************************************************/
  225. void LedMode_Six (BIKELEDCHECK_STR *BikeLedSel)
  226. {
  227. if(cp_stBikeRunInfoPara.BikeSpeedKmH>=BikeLedOverSpeedMax) //超速报警
  228. {
  229. BikeLedSel->uwLedAddcnt++;
  230. if(BikeLedSel->uwLedAddcnt > BikeLedOverSpedCycle)
  231. {
  232. BikeLedSel->uwLedAddcnt=0;
  233. }
  234. if(BikeLedSel->uwLedAddcnt<BikeLedOverSpedDuty)
  235. {
  236. BikeLedSel->blBike_LedSta=TRUE;
  237. }
  238. else
  239. {
  240. BikeLedSel->blBike_LedSta=FALSE;
  241. }
  242. }
  243. else if(cp_stBikeRunInfoPara.BikeSpeedKmH<=BikeLedOverSpeedMin)
  244. {
  245. BikeLedSel->blBike_LedSta=FALSE;
  246. BikeLedSel->uwLedAddcnt=0;
  247. }
  248. }
  249. /***************************************************************
  250. Function: LedMode_Seven
  251. Description: 模式7 开机低亮,刹车高亮
  252. Call by: 1ms
  253. Input Variables:
  254. Output/Return Variables: N/A
  255. Subroutine Call: N/A;
  256. Reference: N/A
  257. ****************************************************************/
  258. void LedMode_Seven(BIKELEDCHECK_STR *BikeLedSel)
  259. {
  260. // if(BikeBrake_blGetstate()==TRUE)
  261. // {
  262. // BikeLedSel->blBike_LedSta=TRUE;
  263. // }
  264. // else
  265. // {
  266. // BikeLedSel->uwLedAddcnt++;
  267. // if(BikeLedSel->uwLedAddcnt > BikeLedAddCycle)
  268. // {
  269. // BikeLedSel->uwLedAddcnt=0;
  270. // }
  271. // if(BikeLedSel->uwLedAddcnt<BikeLedAddDuty)
  272. // {
  273. // BikeLedSel->blBike_LedSta=TRUE;
  274. // }
  275. // else
  276. // {
  277. // BikeLedSel->blBike_LedSta=FALSE;
  278. // }
  279. //
  280. // }
  281. BikeLedSel->uwLedAddcnt++;
  282. if(BikeLedSel->uwLedAddcnt > BikeLedAddCycle)
  283. {
  284. BikeLedSel->uwLedAddcnt=0;
  285. }
  286. if(BikeLedSel->uwLedAddcnt<BikeLedAddDuty)
  287. {
  288. BikeLedSel->blBike_LedSta=TRUE;
  289. if(BikeBrake_blGetstate()==TRUE)
  290. {
  291. BikeLedSel->uwLedAddcnt=0;
  292. }
  293. }
  294. else
  295. {
  296. BikeLedSel->blBike_LedSta=FALSE;
  297. }
  298. }
  299. /***************************************************************
  300. Function: LedMode_Eight
  301. Description: 模式8 开灯亮,关灯灭
  302. Call by: 1ms
  303. Input Variables:
  304. Output/Return Variables: N/A
  305. Subroutine Call: N/A;
  306. Reference: N/A
  307. ****************************************************************/
  308. void LedMode_Eight(BIKELEDCHECK_STR *BikeLedSel)
  309. {
  310. if (cp_stBikeRunInfoPara.uwLightSwitch == 1)//仪表开灯亮,仪表关灯灭
  311. {
  312. BikeLedSel->blBike_LedSta=TRUE;
  313. }
  314. else
  315. {
  316. BikeLedSel->blBike_LedSta=FALSE;
  317. }
  318. }
  319. /***************************************************************
  320. Function: bikelight_voBikeLightInit;
  321. Description: bike light control initialization
  322. Call by: FSM_voInit
  323. Input Variables: N/A
  324. Output/Return Variables: N/A
  325. Subroutine Call: N/A;
  326. Reference: N/A
  327. ****************************************************************/
  328. void bikelight_voBikeLightInit(BIKELEDCHECK_STR *LedPoit)
  329. {
  330. LedPoit->uwBike_LedOffErrCnt=0;
  331. LedPoit->uwBike_OpenPreTime=0;
  332. LedPoit->uwBike_OpenLedEn=0;
  333. LedPoit->uwBikeLight_PWM=0;
  334. LedPoit->uwBike_LedCheckLowTime=0;
  335. LedPoit->uwLedAddcnt=0;
  336. LedPoit->uwBike_keyLedLowSta=0;
  337. LedPoit->uwBike_keyLedHighSta=0;
  338. LedPoit->blBike_LedSta=FALSE;
  339. LedPoit->uwBikeLight_PWM=0;
  340. LedPoit->blBike_LedCurErr=0;
  341. }
  342. /***************************************************************
  343. Function: bikelight_voBikeLightCoef;
  344. Description: 滤波时间/阈值电压设定参数更新 ,参数输入端
  345. uwBike_LedMode:
  346. 0x01:模式1,连接尾灯,开灯时低亮,刹车时高亮
  347. 0x02:模式2,连接尾灯,开灯时高亮,刹车时闪烁
  348. 0x03:模式3,连接刹车灯,刹车时高亮
  349. 0x04:模式4,连接刹车灯,刹车时闪烁
  350. 0x05:模式5,开机常亮
  351. 0x06:模式6,连接蜂鸣器,超速报警
  352. 0x07:模式7,开机低亮,刹车高亮
  353. 0x08:模式8,仅开灯高亮,关灯灭
  354. uwBike_LedFun 模式功能选择
  355. 0-PWM电池电压有保护,
  356. 1-前后灯分别控PWM6/12V无保护,
  357. 2-DCDC输出
  358. Call by:初始化,接收数据更新
  359. Input Variables: N/A
  360. Output/Return Variables: N/A
  361. Subroutine Call: N/A;
  362. Reference: N/A
  363. ****************************************************************/
  364. void bikelight_voBikeLightCoef(UWORD volt)
  365. {
  366. //前灯
  367. BikeLedCheck_F.uwBike_LedVolt =volt & 0x0f;
  368. BikeLedCheck_F.uwBike_LedMode=8; //前灯模式
  369. BikeLedCheck_F.uwBike_LedFun=1;
  370. //尾灯
  371. BikeLedCheck_B.uwBike_LedMode = (volt & 0xf000)>>12;//尾灯模式
  372. BikeLedCheck_B.uwBike_LedVolt =(volt & 0x0f00)>>8;
  373. BikeLedCheck_B.uwBike_LedFun=1;
  374. //左灯模式
  375. BikeLedCheck_L.uwBike_LedMode=5;
  376. //右灯模式
  377. BikeLedCheck_R.uwBike_LedMode=5;
  378. if( BikeLedCheck_F.uwBike_LedVolt == 12) //拉低短路
  379. {
  380. IO_LED_6or12V_Choise_H(); //12V使能
  381. }
  382. else //高阻
  383. {
  384. IO_LED_6or12V_Choise_L();//6V输出使能
  385. }
  386. BikeLedCheck_DC.uwBike_LedMode=5;
  387. }
  388. /***************************************************************
  389. Function: bikelight_voBikeLightControl;
  390. Description: bike light control initialization
  391. Call by: 1ms
  392. Input Variables: switchAction-开灯情况,Brate_Sta-刹车状态, uwBike_LedMode-尾灯模式
  393. Output/Return Variables: N/A
  394. Subroutine Call: N/A;
  395. Reference: N/A
  396. ****************************************************************/
  397. void bikelight_voBikeLightControl(UWORD switchAction, BOOL Brate_Sta )
  398. {
  399. if( power_stPowStateOut.blPowerStartupFlg ==FALSE)
  400. {
  401. BikeLedCheck_F.blBike_LedSta=FALSE;
  402. BikeLedCheck_B.blBike_LedSta=FALSE;
  403. BikeLedCheck_L.blBike_LedSta=FALSE;
  404. BikeLedCheck_R.blBike_LedSta=FALSE;
  405. DL_TimerG_setCaptureCompareValue(PWM_F_INST, 0, GPIO_PWM_F_C1_IDX);//max=2304
  406. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, 0, GPIO_PWM_B_L_C1_IDX);//max=2304
  407. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, 0, GPIO_PWM_B_L_C0_IDX);//max=2304
  408. DL_TimerG_setCaptureCompareValue(PWM_R_INST, 0, GPIO_PWM_R_C1_IDX);//max=2304
  409. }
  410. else
  411. {
  412. if(( BikeLedCheck_F.uwBike_LedFun==1) ||(BikeLedCheck_B.uwBike_LedFun==1)||(BikeLedCheck_L.uwBike_LedFun==1)||(BikeLedCheck_R.uwBike_LedFun==1))
  413. {
  414. IO_LED_6or12V_EN_H();
  415. }
  416. else
  417. {
  418. ledfunctions[BikeLedCheck_DC.uwBike_LedMode](&BikeLedCheck_DC);
  419. if( BikeLedCheck_DC.blBike_LedSta==TRUE) //尾灯控制
  420. {
  421. IO_LED_6or12V_EN_H();
  422. }
  423. else
  424. {
  425. IO_LED_6or12V_EN_L();
  426. }
  427. }
  428. //-----------尾灯处理--------
  429. #if(BIKELEDOPEN_R_ENABLE!=0)
  430. ledfunctions[BikeLedCheck_B.uwBike_LedMode](&BikeLedCheck_B);
  431. if( BikeLedCheck_B.blBike_LedSta==TRUE) //尾灯控制
  432. {
  433. if(BikeLedCheck_B.uwBike_keyLedHighSta==0)
  434. {
  435. BikeLedCheck_B.uwBike_keyLedHighSta=1;
  436. BikeLedCheck_B.uwBike_OpenLedEn=0;//开灯瞬间处理标志
  437. BikeLedCheck_B.uwBike_LedOffErrCnt=0; //10秒一检测计时
  438. BikeLedCheck_B.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
  439. BikeLedCheck_B.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
  440. BikeLedCheck_B.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
  441. BikeLedCheck_B.blBike_LedCurErr=FALSE;
  442. // DL_TimerG_startCounter(PWM_B_L_INST);
  443. DL_Timer_overrideCCPOut(PWM_B_L_INST, DL_TIMER_FORCE_OUT_DISABLED, DL_TIMER_FORCE_CMPL_OUT_DISABLED, GPIO_PWM_B_L_C1_IDX);
  444. GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_15_EDGE_FALL |DL_GPIO_PIN_15_EDGE_RISE);
  445. GPIOB->POLARITY15_0 |=DL_GPIO_PIN_15_EDGE_RISE;
  446. }
  447. if((BikeLedCheck_B.uwBike_OpenLedEn==0) &&(BikeLedCheck_B.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
  448. {
  449. LED_EnableDeal(&BikeLedCheck_B,1,B_PWM_byte);
  450. }
  451. else
  452. {
  453. GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_15_EDGE_FALL |DL_GPIO_PIN_15_EDGE_RISE);
  454. GPIOB->POLARITY15_0 |=DL_GPIO_PIN_15_EDGE_FALL;
  455. }
  456. BikeLedCheck_B.uwBike_keyLedLowSta=1;
  457. }
  458. else
  459. {
  460. BikeLedCheck_B.uwBike_keyLedHighSta=0;
  461. if(BikeLedCheck_B.uwBike_keyLedLowSta!=0)
  462. {
  463. BikeLedCheck_B.uwBike_keyLedLowSta=0;
  464. BikeLedCheck_B.uwBikeLight_PWM=0;
  465. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, BikeLedCheck_B.uwBikeLight_PWM, GPIO_PWM_B_L_C1_IDX);//max=2304
  466. }
  467. }
  468. #endif
  469. // ---------------前灯处理------------
  470. #if(BIKELEDOPEN_F_ENABLE!=0)
  471. ledfunctions[BikeLedCheck_F.uwBike_LedMode](&BikeLedCheck_F);
  472. if (BikeLedCheck_F.blBike_LedSta == TRUE)
  473. {
  474. if(BikeLedCheck_F.uwBike_keyLedHighSta==0)
  475. {
  476. BikeLedCheck_F.uwBike_keyLedHighSta=1;
  477. BikeLedCheck_F.uwBike_OpenLedEn=0;//开灯瞬间处理标志
  478. BikeLedCheck_F.uwBike_LedOffErrCnt=0; //10秒一检测计时
  479. BikeLedCheck_F.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
  480. BikeLedCheck_F.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
  481. BikeLedCheck_F.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
  482. DL_COMP_setDACCode0(COMP_FLEDCHECK_INST, 0x0f);
  483. BikeLedCheck_F.blBike_LedCurErr=FALSE;
  484. DL_TimerG_startCounter(PWM_F_INST);
  485. }
  486. if((BikeLedCheck_F.uwBike_OpenLedEn==0) &&(BikeLedCheck_F.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
  487. {
  488. LED_EnableDeal(&BikeLedCheck_F,1,F_PWM_byte);
  489. }
  490. else
  491. {
  492. //#if(DCDC_12S6V_SEL_EN!=1)
  493. if( BikeLedCheck_F.uwBike_LedFun!=1)
  494. DL_COMP_setDACCode0(COMP_FLEDCHECK_INST, 0x4f);
  495. //#endif
  496. }
  497. BikeLedCheck_F.uwBike_keyLedLowSta=1;
  498. }
  499. else
  500. {
  501. BikeLedCheck_F.uwBike_keyLedHighSta=0;
  502. if(BikeLedCheck_F.uwBike_keyLedLowSta!=0)
  503. {
  504. BikeLedCheck_F.uwBike_keyLedLowSta=0;
  505. BikeLedCheck_F.uwBikeLight_PWM=0;
  506. DL_TimerG_setCaptureCompareValue(PWM_F_INST, BikeLedCheck_F.uwBikeLight_PWM, GPIO_PWM_F_C1_IDX);//max=2304
  507. }
  508. }
  509. #endif
  510. //------------右灯处理------
  511. ledfunctions[BikeLedCheck_R.uwBike_LedMode](&BikeLedCheck_R);
  512. if(BikeLedCheck_R.blBike_LedSta==TRUE) //
  513. {
  514. if(BikeLedCheck_R.uwBike_keyLedHighSta==0)
  515. {
  516. BikeLedCheck_R.uwBike_keyLedHighSta=1;
  517. BikeLedCheck_R.uwBike_OpenLedEn=0;//开灯瞬间处理标志
  518. BikeLedCheck_R.uwBike_LedOffErrCnt=0; //10秒一检测计时
  519. BikeLedCheck_R.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
  520. BikeLedCheck_R.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
  521. BikeLedCheck_R.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
  522. BikeLedCheck_R.blBike_LedCurErr=FALSE;
  523. DL_TimerG_startCounter(PWM_R_INST);
  524. GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_8_EDGE_RISE |DL_GPIO_PIN_8_EDGE_FALL);
  525. GPIOB->POLARITY15_0 |=DL_GPIO_PIN_8_EDGE_RISE;
  526. }
  527. if((BikeLedCheck_R.uwBike_OpenLedEn==0) &&(BikeLedCheck_R.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
  528. {
  529. LED_EnableDeal(&BikeLedCheck_R,1,R_PWM_byte);
  530. }
  531. else
  532. {
  533. GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_8_EDGE_RISE |DL_GPIO_PIN_8_EDGE_FALL);
  534. GPIOB->POLARITY15_0 |=DL_GPIO_PIN_8_EDGE_FALL;
  535. }
  536. BikeLedCheck_R.uwBike_keyLedLowSta=1;
  537. }
  538. else
  539. {
  540. BikeLedCheck_R.uwBike_keyLedHighSta=0;
  541. if(BikeLedCheck_R.uwBike_keyLedLowSta!=0)
  542. {
  543. BikeLedCheck_R.uwBike_keyLedLowSta=0;
  544. BikeLedCheck_R.uwBikeLight_PWM=0;
  545. DL_TimerG_setCaptureCompareValue(PWM_R_INST, BikeLedCheck_R.uwBikeLight_PWM, GPIO_PWM_R_C1_IDX);//max=2304
  546. }
  547. }
  548. //------------左灯处理------
  549. ledfunctions[BikeLedCheck_L.uwBike_LedMode](&BikeLedCheck_L);
  550. if(BikeLedCheck_L.blBike_LedSta==TRUE) //
  551. {
  552. if(BikeLedCheck_L.uwBike_keyLedHighSta==0)
  553. {
  554. BikeLedCheck_L.uwBike_keyLedHighSta=1;
  555. BikeLedCheck_L.uwBike_OpenLedEn=0;//开灯瞬间处理标志
  556. BikeLedCheck_L.uwBike_LedOffErrCnt=0; //10秒一检测计时
  557. BikeLedCheck_L.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
  558. BikeLedCheck_L.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
  559. BikeLedCheck_L.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
  560. BikeLedCheck_L.blBike_LedCurErr=FALSE;
  561. //DL_TimerG_startCounter(PWM_B_L_INST);
  562. DL_Timer_overrideCCPOut(PWM_B_L_INST, DL_TIMER_FORCE_OUT_DISABLED, DL_TIMER_FORCE_CMPL_OUT_DISABLED, GPIO_PWM_B_L_C0_IDX);
  563. GPIOA->POLARITY15_0 &= ~(DL_GPIO_PIN_3_EDGE_RISE |DL_GPIO_PIN_3_EDGE_FALL);
  564. GPIOA->POLARITY15_0 |=DL_GPIO_PIN_3_EDGE_RISE;
  565. }
  566. if((BikeLedCheck_L.uwBike_OpenLedEn==0) &&(BikeLedCheck_L.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
  567. {
  568. LED_EnableDeal(&BikeLedCheck_L,1,L_PWM_byte);
  569. }
  570. else
  571. {
  572. GPIOA->POLARITY15_0 &= ~(DL_GPIO_PIN_3_EDGE_RISE |DL_GPIO_PIN_3_EDGE_FALL);
  573. GPIOA->POLARITY15_0 |=DL_GPIO_PIN_3_EDGE_FALL;
  574. }
  575. BikeLedCheck_L.uwBike_keyLedLowSta=1;
  576. }
  577. else
  578. {
  579. BikeLedCheck_L.uwBike_keyLedHighSta=0;
  580. if(BikeLedCheck_L.uwBike_keyLedLowSta!=0)
  581. {
  582. BikeLedCheck_L.uwBike_keyLedLowSta=0;
  583. BikeLedCheck_L.uwBikeLight_PWM=0;
  584. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, BikeLedCheck_L.uwBikeLight_PWM, GPIO_PWM_B_L_C0_IDX);//max=2304
  585. }
  586. }
  587. //---------------------
  588. #if(BIKE_OXFORD_EN!=0)
  589. IO_FORWARDLED_ON(); //开前灯
  590. IO_BACKLED_ON();
  591. #endif
  592. //--------------LED电路检测----------
  593. //-------F_LED
  594. if( BikeLedCheck_F.uwBike_LedFun!=1)
  595. {
  596. if((BikeLedCheck_F.blBike_LedCurErr==TRUE )&&(BikeLedCheck_F.blBike_LedSta == TRUE)) //过流标志,前灯恢复检测
  597. {
  598. BikeLedCheck_F.uwBike_LedOffErrCnt++;
  599. if(BikeLedCheck_F.uwBike_LedOffErrCnt>2000) //1000ms
  600. {
  601. BikeLedCheck_F.uwBike_keyLedHighSta=0;
  602. BikeLedCheck_F.uwBike_LedOffErrCnt=0;
  603. BikeLedCheck_F.blBike_LedCurErr=FALSE;
  604. BikeLedCheck_F.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
  605. }
  606. }
  607. else
  608. {
  609. BikeLedCheck_F.uwBike_LedOffErrCnt=0;
  610. }
  611. }
  612. //------B_LED
  613. if( BikeLedCheck_B.uwBike_LedFun!=1)
  614. {
  615. if((BikeLedCheck_B.blBike_LedCurErr==TRUE)&&(BikeLedCheck_B.blBike_LedSta == TRUE)) //后灯恢复检测
  616. {
  617. BikeLedCheck_B.uwBike_LedOffErrCnt++;
  618. if(BikeLedCheck_B.uwBike_LedOffErrCnt>2000)
  619. {
  620. BikeLedCheck_B.uwBike_keyLedHighSta=0;
  621. BikeLedCheck_B.uwBike_LedOffErrCnt=0;
  622. BikeLedCheck_B.blBike_LedCurErr=FALSE;
  623. BikeLedCheck_B.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
  624. }
  625. }
  626. else
  627. {
  628. BikeLedCheck_B.uwBike_LedOffErrCnt=0;
  629. }
  630. }
  631. //------R_LED
  632. if( BikeLedCheck_R.uwBike_LedFun!=1)
  633. {
  634. if((BikeLedCheck_R.blBike_LedCurErr==TRUE )&&(BikeLedCheck_R.blBike_LedSta == TRUE)) //过流标志,前灯恢复检测
  635. {
  636. BikeLedCheck_R.uwBike_LedOffErrCnt++;
  637. if(BikeLedCheck_R.uwBike_LedOffErrCnt>2000) //1000ms
  638. {
  639. BikeLedCheck_R.uwBike_keyLedHighSta=0;
  640. BikeLedCheck_R.uwBike_LedOffErrCnt=0;
  641. BikeLedCheck_R.blBike_LedCurErr=FALSE;
  642. BikeLedCheck_R.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
  643. }
  644. }
  645. else
  646. {
  647. BikeLedCheck_R.uwBike_LedOffErrCnt=0;
  648. }
  649. }
  650. //------L_LED
  651. if( BikeLedCheck_L.uwBike_LedFun!=1)
  652. {
  653. if((BikeLedCheck_L.blBike_LedCurErr==TRUE )&&(BikeLedCheck_L.blBike_LedSta == TRUE)) //过流标志,前灯恢复检测
  654. {
  655. BikeLedCheck_L.uwBike_LedOffErrCnt++;
  656. if(BikeLedCheck_L.uwBike_LedOffErrCnt>2000) //1000ms
  657. {
  658. BikeLedCheck_L.uwBike_keyLedHighSta=0;
  659. BikeLedCheck_L.uwBike_LedOffErrCnt=0;
  660. BikeLedCheck_L.blBike_LedCurErr=FALSE;
  661. BikeLedCheck_L.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
  662. }
  663. }
  664. else
  665. {
  666. BikeLedCheck_L.uwBike_LedOffErrCnt=0;
  667. }
  668. }
  669. //------
  670. }
  671. }
  672. void LED_EnableDeal(BIKELEDCHECK_STR *p,UWORD switchAction,LED_PWM_STR mode )
  673. {
  674. if(switchAction!=0)
  675. {
  676. if(p->uwBike_OpenPreTime<2000)
  677. p->uwBike_OpenPreTime++;
  678. if(p->uwBike_OpenPreTime<=2)//2ms
  679. {
  680. if(mode==F_PWM_byte)
  681. {
  682. p->uwBikeLight_PWM=LIGHT_FIRSTPWM;//
  683. }
  684. else
  685. {
  686. p->uwBikeLight_PWM=LIGHTBLR_FIRSTPWM;//
  687. if(p->uwBike_LedFun ==1 )
  688. p->uwBikeLight_PWM=LIGHT_FIRSTPWM;// 4us
  689. }
  690. }
  691. else if(p->uwBike_OpenPreTime<=3) //4
  692. {
  693. // p->uwBikeLight_PWM =691 ;//720;//
  694. if((p->uwBike_OpenLedEn ==0)&&(p->blBike_LedCurErr==TRUE))
  695. {
  696. p->uwBikeLight_PWM =LIGHT_SECTPWM ;//720;//
  697. }
  698. else
  699. {
  700. p->uwBikeLight_PWM=0;
  701. }
  702. if(p->uwBike_LedFun ==1 ) //去掉保护
  703. {
  704. p->uwBikeLight_PWM = LIGHTBLR_NoProPWM;
  705. }
  706. }
  707. // else if(p->uwBike_OpenPreTime>=1000)
  708. // {
  709. // p->uwBikeLight_PWM=0;//
  710. // p->uwBike_OpenLedEn=1;
  711. // }
  712. if((p->uwBike_OpenPreTime>2) && ((p->uwBikeLight_PWM!=0)||(p->uwBike_LedFun ==1 )))// ||(p->uwBike_LedCheckLowTime>=2)
  713. {
  714. p->blBike_LedCurErr=FALSE;
  715. p->uwBike_OpenLedEn=1;
  716. }
  717. if(p->uwBike_OpenLedEn!=0) //
  718. {
  719. p->uwBikeLight_PWM=LIGHT_MAXPWM;//
  720. }
  721. }
  722. else
  723. {
  724. p->uwBikeLight_PWM=0;//
  725. }
  726. if(mode==F_PWM_byte)
  727. {
  728. DL_TimerG_setCaptureCompareValue(PWM_F_INST, p->uwBikeLight_PWM, GPIO_PWM_F_C1_IDX);//max=2304
  729. }
  730. else if(mode==B_PWM_byte)
  731. {
  732. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, p->uwBikeLight_PWM, GPIO_PWM_B_L_C1_IDX);//max=2304
  733. }
  734. else if(mode==L_PWM_byte)
  735. {
  736. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, p->uwBikeLight_PWM, GPIO_PWM_B_L_C0_IDX);//max=2304
  737. }
  738. else if(mode==R_PWM_byte)
  739. {
  740. DL_TimerG_setCaptureCompareValue(PWM_R_INST, p->uwBikeLight_PWM, GPIO_PWM_R_C1_IDX);//max=2304
  741. }
  742. }
  743. /*************************************************************************
  744. Local Functions (N/A)
  745. *************************************************************************/
  746. /*************************************************************************
  747. End of this File (EOF)!
  748. Do not put anything after this part!
  749. *************************************************************************/