My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

lpc17xx_qei.c 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /**********************************************************************
  2. * $Id$ lpc17xx_qei.c 2010-05-21
  3. *//**
  4. * @file lpc17xx_qei.c
  5. * @brief Contains all functions support for QEI firmware library on LPC17xx
  6. * @version 2.0
  7. * @date 21. May. 2010
  8. * @author NXP MCU SW Application Team
  9. *
  10. * Copyright(C) 2010, NXP Semiconductor
  11. * All rights reserved.
  12. *
  13. ***********************************************************************
  14. * Software that is described herein is for illustrative purposes only
  15. * which provides customers with programming information regarding the
  16. * products. This software is supplied "AS IS" without any warranties.
  17. * NXP Semiconductors assumes no responsibility or liability for the
  18. * use of the software, conveys no license or title under any patent,
  19. * copyright, or mask work right to the product. NXP Semiconductors
  20. * reserves the right to make changes in the software without
  21. * notification. NXP Semiconductors also make no representation or
  22. * warranty that such application will be suitable for the specified
  23. * use without further testing or modification.
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors'
  26. * relevant copyright in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. **********************************************************************/
  31. /* Peripheral group ----------------------------------------------------------- */
  32. /** @addtogroup QEI
  33. * @{
  34. */
  35. /* Includes ------------------------------------------------------------------- */
  36. #include "lpc17xx_qei.h"
  37. #include "lpc17xx_clkpwr.h"
  38. /* If this source file built with example, the LPC17xx FW library configuration
  39. * file in each example directory ("lpc17xx_libcfg.h") must be included,
  40. * otherwise the default FW library configuration file must be included instead
  41. */
  42. #ifdef __BUILD_WITH_EXAMPLE__
  43. #include "lpc17xx_libcfg.h"
  44. #else
  45. #include "lpc17xx_libcfg_default.h"
  46. #endif /* __BUILD_WITH_EXAMPLE__ */
  47. #ifdef _QEI
  48. /* Private Types -------------------------------------------------------------- */
  49. /** @defgroup QEI_Private_Types QEI Private Types
  50. * @{
  51. */
  52. /**
  53. * @brief QEI configuration union type definition
  54. */
  55. typedef union {
  56. QEI_CFG_Type bmQEIConfig;
  57. uint32_t ulQEIConfig;
  58. } QEI_CFGOPT_Type;
  59. /**
  60. * @}
  61. */
  62. /* Public Functions ----------------------------------------------------------- */
  63. /** @addtogroup QEI_Public_Functions
  64. * @{
  65. */
  66. /*********************************************************************//**
  67. * @brief Resets value for each type of QEI value, such as velocity,
  68. * counter, position, etc..
  69. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  70. * @param[in] ulResetType QEI Reset Type, should be one of the following:
  71. * - QEI_RESET_POS: Reset Position Counter
  72. * - QEI_RESET_POSOnIDX: Reset Position Counter on Index signal
  73. * - QEI_RESET_VEL: Reset Velocity
  74. * - QEI_RESET_IDX: Reset Index Counter
  75. * @return None
  76. **********************************************************************/
  77. void QEI_Reset(LPC_QEI_TypeDef *QEIx, uint32_t ulResetType)
  78. {
  79. CHECK_PARAM(PARAM_QEIx(QEIx));
  80. CHECK_PARAM(PARAM_QEI_RESET(ulResetType));
  81. QEIx->QEICON = ulResetType;
  82. }
  83. /*********************************************************************//**
  84. * @brief Initializes the QEI peripheral according to the specified
  85. * parameters in the QEI_ConfigStruct.
  86. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  87. * @param[in] QEI_ConfigStruct Pointer to a QEI_CFG_Type structure
  88. * that contains the configuration information for the
  89. * specified QEI peripheral
  90. * @return None
  91. **********************************************************************/
  92. void QEI_Init(LPC_QEI_TypeDef *QEIx, QEI_CFG_Type *QEI_ConfigStruct)
  93. {
  94. CHECK_PARAM(PARAM_QEIx(QEIx));
  95. CHECK_PARAM(PARAM_QEI_DIRINV(QEI_ConfigStruct->DirectionInvert));
  96. CHECK_PARAM(PARAM_QEI_SIGNALMODE(QEI_ConfigStruct->SignalMode));
  97. CHECK_PARAM(PARAM_QEI_CAPMODE(QEI_ConfigStruct->CaptureMode));
  98. CHECK_PARAM(PARAM_QEI_INVINX(QEI_ConfigStruct->InvertIndex));
  99. /* Set up clock and power for QEI module */
  100. CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCQEI, ENABLE);
  101. /* As default, peripheral clock for QEI module
  102. * is set to FCCLK / 2 */
  103. CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_QEI, CLKPWR_PCLKSEL_CCLK_DIV_1);
  104. // Reset all remaining value in QEI peripheral
  105. QEIx->QEICON = QEI_CON_RESP | QEI_CON_RESV | QEI_CON_RESI;
  106. QEIx->QEIMAXPOS = 0x00;
  107. QEIx->CMPOS0 = 0x00;
  108. QEIx->CMPOS1 = 0x00;
  109. QEIx->CMPOS2 = 0x00;
  110. QEIx->INXCMP = 0x00;
  111. QEIx->QEILOAD = 0x00;
  112. QEIx->VELCOMP = 0x00;
  113. QEIx->FILTER = 0x00;
  114. // Disable all Interrupt
  115. QEIx->QEIIEC = QEI_IECLR_BITMASK;
  116. // Clear all Interrupt pending
  117. QEIx->QEICLR = QEI_INTCLR_BITMASK;
  118. // Set QEI configuration value corresponding to its setting up value
  119. QEIx->QEICONF = ((QEI_CFGOPT_Type *)QEI_ConfigStruct)->ulQEIConfig;
  120. }
  121. /*********************************************************************//**
  122. * @brief De-initializes the QEI peripheral registers to their
  123. * default reset values.
  124. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  125. * @return None
  126. **********************************************************************/
  127. void QEI_DeInit(LPC_QEI_TypeDef *QEIx)
  128. {
  129. CHECK_PARAM(PARAM_QEIx(QEIx));
  130. /* Turn off clock and power for QEI module */
  131. CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCQEI, DISABLE);
  132. }
  133. /*****************************************************************************//**
  134. * @brief Fills each QIE_InitStruct member with its default value:
  135. * - DirectionInvert = QEI_DIRINV_NONE
  136. * - SignalMode = QEI_SIGNALMODE_QUAD
  137. * - CaptureMode = QEI_CAPMODE_4X
  138. * - InvertIndex = QEI_INVINX_NONE
  139. * @param[in] QIE_InitStruct Pointer to a QEI_CFG_Type structure
  140. * which will be initialized.
  141. * @return None
  142. *******************************************************************************/
  143. void QEI_ConfigStructInit(QEI_CFG_Type *QIE_InitStruct)
  144. {
  145. QIE_InitStruct->CaptureMode = QEI_CAPMODE_4X;
  146. QIE_InitStruct->DirectionInvert = QEI_DIRINV_NONE;
  147. QIE_InitStruct->InvertIndex = QEI_INVINX_NONE;
  148. QIE_InitStruct->SignalMode = QEI_SIGNALMODE_QUAD;
  149. }
  150. /*********************************************************************//**
  151. * @brief Check whether if specified flag status is set or not
  152. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  153. * @param[in] ulFlagType Status Flag Type, should be one of the following:
  154. * - QEI_STATUS_DIR: Direction Status
  155. * @return New Status of this status flag (SET or RESET)
  156. **********************************************************************/
  157. FlagStatus QEI_GetStatus(LPC_QEI_TypeDef *QEIx, uint32_t ulFlagType)
  158. {
  159. CHECK_PARAM(PARAM_QEIx(QEIx));
  160. CHECK_PARAM(PARAM_QEI_STATUS(ulFlagType));
  161. return ((QEIx->QEISTAT & ulFlagType) ? SET : RESET);
  162. }
  163. /*********************************************************************//**
  164. * @brief Get current position value in QEI peripheral
  165. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  166. * @return Current position value of QEI peripheral
  167. **********************************************************************/
  168. uint32_t QEI_GetPosition(LPC_QEI_TypeDef *QEIx)
  169. {
  170. CHECK_PARAM(PARAM_QEIx(QEIx));
  171. return (QEIx->QEIPOS);
  172. }
  173. /*********************************************************************//**
  174. * @brief Set max position value for QEI peripheral
  175. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  176. * @param[in] ulMaxPos Max position value to set
  177. * @return None
  178. **********************************************************************/
  179. void QEI_SetMaxPosition(LPC_QEI_TypeDef *QEIx, uint32_t ulMaxPos)
  180. {
  181. CHECK_PARAM(PARAM_QEIx(QEIx));
  182. QEIx->QEIMAXPOS = ulMaxPos;
  183. }
  184. /*********************************************************************//**
  185. * @brief Set position compare value for QEI peripheral
  186. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  187. * @param[in] bPosCompCh Compare Position channel, should be:
  188. * - QEI_COMPPOS_CH_0: QEI compare position channel 0
  189. * - QEI_COMPPOS_CH_1: QEI compare position channel 1
  190. * - QEI_COMPPOS_CH_2: QEI compare position channel 2
  191. * @param[in] ulPosComp Compare Position value to set
  192. * @return None
  193. **********************************************************************/
  194. void QEI_SetPositionComp(LPC_QEI_TypeDef *QEIx, uint8_t bPosCompCh, uint32_t ulPosComp)
  195. {
  196. uint32_t *tmp;
  197. CHECK_PARAM(PARAM_QEIx(QEIx));
  198. CHECK_PARAM(PARAM_QEI_COMPPOS_CH(bPosCompCh));
  199. tmp = (uint32_t *) (&(QEIx->CMPOS0) + bPosCompCh * 4);
  200. *tmp = ulPosComp;
  201. }
  202. /*********************************************************************//**
  203. * @brief Get current index counter of QEI peripheral
  204. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  205. * @return Current value of QEI index counter
  206. **********************************************************************/
  207. uint32_t QEI_GetIndex(LPC_QEI_TypeDef *QEIx)
  208. {
  209. CHECK_PARAM(PARAM_QEIx(QEIx));
  210. return (QEIx->INXCNT);
  211. }
  212. /*********************************************************************//**
  213. * @brief Set value for index compare in QEI peripheral
  214. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  215. * @param[in] ulIndexComp Compare Index Value to set
  216. * @return None
  217. **********************************************************************/
  218. void QEI_SetIndexComp(LPC_QEI_TypeDef *QEIx, uint32_t ulIndexComp)
  219. {
  220. CHECK_PARAM(PARAM_QEIx(QEIx));
  221. QEIx->INXCMP = ulIndexComp;
  222. }
  223. /*********************************************************************//**
  224. * @brief Set timer reload value for QEI peripheral. When the velocity timer is
  225. * over-flow, the value that set for Timer Reload register will be loaded
  226. * into the velocity timer for next period. The calculated velocity in RPM
  227. * therefore will be affect by this value.
  228. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  229. * @param[in] QEIReloadStruct QEI reload structure
  230. * @return None
  231. **********************************************************************/
  232. void QEI_SetTimerReload(LPC_QEI_TypeDef *QEIx, QEI_RELOADCFG_Type *QEIReloadStruct)
  233. {
  234. uint64_t pclk;
  235. CHECK_PARAM(PARAM_QEIx(QEIx));
  236. CHECK_PARAM(PARAM_QEI_TIMERRELOAD(QEIReloadStruct->ReloadOption));
  237. if (QEIReloadStruct->ReloadOption == QEI_TIMERRELOAD_TICKVAL) {
  238. QEIx->QEILOAD = QEIReloadStruct->ReloadValue - 1;
  239. } else {
  240. pclk = (uint64_t)CLKPWR_GetPCLK(CLKPWR_PCLKSEL_QEI);
  241. pclk = (pclk /(1000000/QEIReloadStruct->ReloadValue)) - 1;
  242. QEIx->QEILOAD = (uint32_t)pclk;
  243. }
  244. }
  245. /*********************************************************************//**
  246. * @brief Get current timer counter in QEI peripheral
  247. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  248. * @return Current timer counter in QEI peripheral
  249. **********************************************************************/
  250. uint32_t QEI_GetTimer(LPC_QEI_TypeDef *QEIx)
  251. {
  252. CHECK_PARAM(PARAM_QEIx(QEIx));
  253. return (QEIx->QEITIME);
  254. }
  255. /*********************************************************************//**
  256. * @brief Get current velocity pulse counter in current time period
  257. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  258. * @return Current velocity pulse counter value
  259. **********************************************************************/
  260. uint32_t QEI_GetVelocity(LPC_QEI_TypeDef *QEIx)
  261. {
  262. CHECK_PARAM(PARAM_QEIx(QEIx));
  263. return (QEIx->QEIVEL);
  264. }
  265. /*********************************************************************//**
  266. * @brief Get the most recently measured velocity of the QEI. When
  267. * the Velocity timer in QEI is over-flow, the current velocity
  268. * value will be loaded into Velocity Capture register.
  269. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  270. * @return The most recently measured velocity value
  271. **********************************************************************/
  272. uint32_t QEI_GetVelocityCap(LPC_QEI_TypeDef *QEIx)
  273. {
  274. CHECK_PARAM(PARAM_QEIx(QEIx));
  275. return (QEIx->QEICAP);
  276. }
  277. /*********************************************************************//**
  278. * @brief Set Velocity Compare value for QEI peripheral
  279. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  280. * @param[in] ulVelComp Compare Velocity value to set
  281. * @return None
  282. **********************************************************************/
  283. void QEI_SetVelocityComp(LPC_QEI_TypeDef *QEIx, uint32_t ulVelComp)
  284. {
  285. CHECK_PARAM(PARAM_QEIx(QEIx));
  286. QEIx->VELCOMP = ulVelComp;
  287. }
  288. /*********************************************************************//**
  289. * @brief Set value of sampling count for the digital filter in
  290. * QEI peripheral
  291. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  292. * @param[in] ulSamplingPulse Value of sampling count to set
  293. * @return None
  294. **********************************************************************/
  295. void QEI_SetDigiFilter(LPC_QEI_TypeDef *QEIx, uint32_t ulSamplingPulse)
  296. {
  297. CHECK_PARAM(PARAM_QEIx(QEIx));
  298. QEIx->FILTER = ulSamplingPulse;
  299. }
  300. /*********************************************************************//**
  301. * @brief Check whether if specified interrupt flag status in QEI
  302. * peripheral is set or not
  303. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  304. * @param[in] ulIntType Interrupt Flag Status type, should be:
  305. - QEI_INTFLAG_INX_Int: index pulse was detected interrupt
  306. - QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
  307. - QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
  308. - QEI_INTFLAG_DIR_Int: Change of direction interrupt
  309. - QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
  310. - QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
  311. - QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the
  312. current position interrupt
  313. - QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the
  314. current position interrupt
  315. - QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the
  316. current position interrupt
  317. - QEI_INTFLAG_REV_Int: Index compare value is equal to the current
  318. index count interrupt
  319. - QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
  320. - QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
  321. - QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
  322. * @return New State of specified interrupt flag status (SET or RESET)
  323. **********************************************************************/
  324. FlagStatus QEI_GetIntStatus(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType)
  325. {
  326. CHECK_PARAM(PARAM_QEIx(QEIx));
  327. CHECK_PARAM(PARAM_QEI_INTFLAG(ulIntType));
  328. return((QEIx->QEIINTSTAT & ulIntType) ? SET : RESET);
  329. }
  330. /*********************************************************************//**
  331. * @brief Enable/Disable specified interrupt in QEI peripheral
  332. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  333. * @param[in] ulIntType Interrupt Flag Status type, should be:
  334. * - QEI_INTFLAG_INX_Int: index pulse was detected interrupt
  335. * - QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
  336. * - QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
  337. * - QEI_INTFLAG_DIR_Int: Change of direction interrupt
  338. * - QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
  339. * - QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
  340. * - QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the
  341. * current position interrupt
  342. * - QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the
  343. * current position interrupt
  344. * - QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the
  345. * current position interrupt
  346. * - QEI_INTFLAG_REV_Int: Index compare value is equal to the current
  347. * index count interrupt
  348. * - QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
  349. * - QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
  350. * - QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
  351. * @param[in] NewState New function state, should be:
  352. * - DISABLE
  353. * - ENABLE
  354. * @return None
  355. **********************************************************************/
  356. void QEI_IntCmd(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType, FunctionalState NewState)
  357. {
  358. CHECK_PARAM(PARAM_QEIx(QEIx));
  359. CHECK_PARAM(PARAM_QEI_INTFLAG(ulIntType));
  360. CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
  361. if (NewState == ENABLE) {
  362. QEIx->QEIIES = ulIntType;
  363. } else {
  364. QEIx->QEIIEC = ulIntType;
  365. }
  366. }
  367. /*********************************************************************//**
  368. * @brief Sets (forces) specified interrupt in QEI peripheral
  369. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  370. * @param[in] ulIntType Interrupt Flag Status type, should be:
  371. - QEI_INTFLAG_INX_Int: index pulse was detected interrupt
  372. - QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
  373. - QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
  374. - QEI_INTFLAG_DIR_Int: Change of direction interrupt
  375. - QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
  376. - QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
  377. - QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the
  378. current position interrupt
  379. - QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the
  380. current position interrupt
  381. - QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the
  382. current position interrupt
  383. - QEI_INTFLAG_REV_Int: Index compare value is equal to the current
  384. index count interrupt
  385. - QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
  386. - QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
  387. - QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
  388. * @return None
  389. **********************************************************************/
  390. void QEI_IntSet(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType)
  391. {
  392. CHECK_PARAM(PARAM_QEIx(QEIx));
  393. CHECK_PARAM(PARAM_QEI_INTFLAG(ulIntType));
  394. QEIx->QEISET = ulIntType;
  395. }
  396. /*********************************************************************//**
  397. * @brief Clear (force) specified interrupt (pending) in QEI peripheral
  398. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  399. * @param[in] ulIntType Interrupt Flag Status type, should be:
  400. - QEI_INTFLAG_INX_Int: index pulse was detected interrupt
  401. - QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
  402. - QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
  403. - QEI_INTFLAG_DIR_Int: Change of direction interrupt
  404. - QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
  405. - QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
  406. - QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the
  407. current position interrupt
  408. - QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the
  409. current position interrupt
  410. - QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the
  411. current position interrupt
  412. - QEI_INTFLAG_REV_Int: Index compare value is equal to the current
  413. index count interrupt
  414. - QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
  415. - QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
  416. - QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
  417. * @return None
  418. **********************************************************************/
  419. void QEI_IntClear(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType)
  420. {
  421. CHECK_PARAM(PARAM_QEIx(QEIx));
  422. CHECK_PARAM(PARAM_QEI_INTFLAG(ulIntType));
  423. QEIx->QEICLR = ulIntType;
  424. }
  425. /*********************************************************************//**
  426. * @brief Calculates the actual velocity in RPM passed via velocity
  427. * capture value and Pulse Per Round (of the encoder) value
  428. * parameter input.
  429. * @param[in] QEIx QEI peripheral, should be LPC_QEI
  430. * @param[in] ulVelCapValue Velocity capture input value that can
  431. * be got from QEI_GetVelocityCap() function
  432. * @param[in] ulPPR Pulse per round of encoder
  433. * @return The actual value of velocity in RPM (Round per minute)
  434. **********************************************************************/
  435. uint32_t QEI_CalculateRPM(LPC_QEI_TypeDef *QEIx, uint32_t ulVelCapValue, uint32_t ulPPR)
  436. {
  437. uint64_t rpm, clock, Load, edges;
  438. // Get current Clock rate for timer input
  439. clock = (uint64_t)CLKPWR_GetPCLK(CLKPWR_PCLKSEL_QEI);
  440. // Get Timer load value (velocity capture period)
  441. Load = (uint64_t)(QEIx->QEILOAD + 1);
  442. // Get Edge
  443. edges = (uint64_t)((QEIx->QEICONF & QEI_CONF_CAPMODE) ? 4 : 2);
  444. // Calculate RPM
  445. rpm = ((clock * ulVelCapValue * 60) / (Load * ulPPR * edges));
  446. return (uint32_t)(rpm);
  447. }
  448. /**
  449. * @}
  450. */
  451. #endif /* _QEI */
  452. /**
  453. * @}
  454. */
  455. /* --------------------------------- End Of File ------------------------------ */