lpc_mcpwm.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /**********************************************************************
  2. * $Id$ lpc_mcpwm.c 2011-06-02
  3. *//**
  4. * @file lpc_mcpwm.c
  5. * @brief Contains all functions support for Motor Control PWM
  6. * firmware library on LPC
  7. * @version 1.0
  8. * @date 02. June. 2011
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2011, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @addtogroup MCPWM
  34. * @{
  35. */
  36. #ifdef __BUILD_WITH_EXAMPLE__
  37. #include "lpc_libcfg.h"
  38. #else
  39. #include "lpc_libcfg_default.h"
  40. #endif /* __BUILD_WITH_EXAMPLE__ */
  41. #ifdef _MCPWM
  42. /* Includes ------------------------------------------------------------------- */
  43. #include "lpc_mcpwm.h"
  44. #include "lpc_clkpwr.h"
  45. /* Public Functions ----------------------------------------------------------- */
  46. /** @addtogroup MCPWM_Public_Functions
  47. * @{
  48. */
  49. /*********************************************************************//**
  50. * @brief Initializes the MCPWM peripheral
  51. * @param[in] MCPWMx Motor Control PWM peripheral selected,
  52. * Should be: LPC_MCPWM
  53. * @return None
  54. **********************************************************************/
  55. void MCPWM_Init(LPC_MCPWM_TypeDef *MCPWMx)
  56. {
  57. /* Turn On MCPWM PCLK */
  58. CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCMCPWM, ENABLE);
  59. MCPWMx->CAP_CLR = MCPWM_CAPCLR_CAP(0) | MCPWM_CAPCLR_CAP(1) | MCPWM_CAPCLR_CAP(2);
  60. MCPWMx->INTF_CLR = MCPWM_INT_ILIM(0) | MCPWM_INT_ILIM(1) | MCPWM_INT_ILIM(2) \
  61. | MCPWM_INT_IMAT(0) | MCPWM_INT_IMAT(1) | MCPWM_INT_IMAT(2) \
  62. | MCPWM_INT_ICAP(0) | MCPWM_INT_ICAP(1) | MCPWM_INT_ICAP(2);
  63. MCPWMx->INTEN_CLR = MCPWM_INT_ILIM(0) | MCPWM_INT_ILIM(1) | MCPWM_INT_ILIM(2) \
  64. | MCPWM_INT_IMAT(0) | MCPWM_INT_IMAT(1) | MCPWM_INT_IMAT(2) \
  65. | MCPWM_INT_ICAP(0) | MCPWM_INT_ICAP(1) | MCPWM_INT_ICAP(2);
  66. }
  67. /*********************************************************************//**
  68. * @brief Configures each channel in MCPWM peripheral according to the
  69. * specified parameters in the MCPWM_CHANNEL_CFG_Type.
  70. * @param[in] MCPWMx Motor Control PWM peripheral selected
  71. * should be: LPC_MCPWM
  72. * @param[in] channelNum Channel number, should be: 0..2.
  73. * @param[in] channelSetup Pointer to a MCPWM_CHANNEL_CFG_Type structure
  74. * that contains the configuration information for the
  75. * specified MCPWM channel.
  76. * @return None
  77. **********************************************************************/
  78. void MCPWM_ConfigChannel(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channelNum,
  79. MCPWM_CHANNEL_CFG_Type * channelSetup)
  80. {
  81. if (channelNum < MCPWM_MAX_CHANNEL)
  82. {
  83. if (channelNum == MCPWM_CHANNEL_0)
  84. {
  85. MCPWMx->TC0 = channelSetup->channelTimercounterValue;
  86. MCPWMx->LIM0 = channelSetup->channelPeriodValue;
  87. MCPWMx->MAT0 = channelSetup->channelPulsewidthValue;
  88. }
  89. else if (channelNum == MCPWM_CHANNEL_1)
  90. {
  91. MCPWMx->TC1 = channelSetup->channelTimercounterValue;
  92. MCPWMx->LIM1 = channelSetup->channelPeriodValue;
  93. MCPWMx->MAT1 = channelSetup->channelPulsewidthValue;
  94. }
  95. else if (channelNum == MCPWM_CHANNEL_2)
  96. {
  97. MCPWMx->TC2 = channelSetup->channelTimercounterValue;
  98. MCPWMx->LIM2 = channelSetup->channelPeriodValue;
  99. MCPWMx->MAT2 = channelSetup->channelPulsewidthValue;
  100. }
  101. else
  102. {
  103. return;
  104. }
  105. if (channelSetup->channelType == MCPWM_CHANNEL_CENTER_MODE)
  106. {
  107. MCPWMx->CON_SET = MCPWM_CON_CENTER(channelNum);
  108. }
  109. else
  110. {
  111. MCPWMx->CON_CLR = MCPWM_CON_CENTER(channelNum);
  112. }
  113. if (channelSetup->channelPolarity == MCPWM_CHANNEL_PASSIVE_HI)
  114. {
  115. MCPWMx->CON_SET = MCPWM_CON_POLAR(channelNum);
  116. }
  117. else
  118. {
  119. MCPWMx->CON_CLR = MCPWM_CON_POLAR(channelNum);
  120. }
  121. if (channelSetup->channelDeadtimeEnable == ENABLE)
  122. {
  123. MCPWMx->CON_SET = MCPWM_CON_DTE(channelNum);
  124. MCPWMx->DT &= ~(MCPWM_DT(channelNum, 0x3FF));
  125. MCPWMx->DT |= MCPWM_DT(channelNum, channelSetup->channelDeadtimeValue);
  126. }
  127. else
  128. {
  129. MCPWMx->CON_CLR = MCPWM_CON_DTE(channelNum);
  130. }
  131. if (channelSetup->channelUpdateEnable == ENABLE)
  132. {
  133. MCPWMx->CON_CLR = MCPWM_CON_DISUP(channelNum);
  134. }
  135. else
  136. {
  137. MCPWMx->CON_SET = MCPWM_CON_DISUP(channelNum);
  138. }
  139. }
  140. }
  141. /*********************************************************************//**
  142. * @brief Write to MCPWM shadow registers - Update the value for period
  143. * and pulse width in MCPWM peripheral.
  144. * @param[in] MCPWMx Motor Control PWM peripheral selected
  145. * Should be: LPC_MCPWM
  146. * @param[in] channelNum Channel Number, should be: 0..2.
  147. * @param[in] channelSetup Pointer to a MCPWM_CHANNEL_CFG_Type structure
  148. * that contains the configuration information for the
  149. * specified MCPWM channel.
  150. * @return None
  151. **********************************************************************/
  152. void MCPWM_WriteToShadow(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channelNum,
  153. MCPWM_CHANNEL_CFG_Type *channelSetup)
  154. {
  155. if (channelNum == MCPWM_CHANNEL_0)
  156. {
  157. MCPWMx->LIM0 = channelSetup->channelPeriodValue;
  158. MCPWMx->MAT0 = channelSetup->channelPulsewidthValue;
  159. }
  160. else if (channelNum == MCPWM_CHANNEL_1)
  161. {
  162. MCPWMx->LIM1 = channelSetup->channelPeriodValue;
  163. MCPWMx->MAT1 = channelSetup->channelPulsewidthValue;
  164. }
  165. else if (channelNum == MCPWM_CHANNEL_2)
  166. {
  167. MCPWMx->LIM2 = channelSetup->channelPeriodValue;
  168. MCPWMx->MAT2 = channelSetup->channelPulsewidthValue;
  169. }
  170. }
  171. /*********************************************************************//**
  172. * @brief Configures capture function in MCPWM peripheral
  173. * @param[in] MCPWMx Motor Control PWM peripheral selected
  174. * Should be: LPC_MCPWM
  175. * @param[in] channelNum MCI (Motor Control Input pin) number
  176. * Should be: 0..2
  177. * @param[in] captureConfig Pointer to a MCPWM_CAPTURE_CFG_Type structure
  178. * that contains the configuration information for the
  179. * specified MCPWM capture.
  180. * @return
  181. **********************************************************************/
  182. void MCPWM_ConfigCapture(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channelNum,
  183. MCPWM_CAPTURE_CFG_Type *captureConfig)
  184. {
  185. if (channelNum < MCPWM_MAX_CHANNEL)
  186. {
  187. if (captureConfig->captureFalling == ENABLE)
  188. {
  189. MCPWMx->CAPCON_SET = MCPWM_CAPCON_CAPMCI_FE(captureConfig->captureChannel, channelNum);
  190. }
  191. else
  192. {
  193. MCPWMx->CAPCON_CLR = MCPWM_CAPCON_CAPMCI_FE(captureConfig->captureChannel, channelNum);
  194. }
  195. if (captureConfig->captureRising == ENABLE)
  196. {
  197. MCPWMx->CAPCON_SET = MCPWM_CAPCON_CAPMCI_RE(captureConfig->captureChannel, channelNum);
  198. }
  199. else
  200. {
  201. MCPWMx->CAPCON_CLR = MCPWM_CAPCON_CAPMCI_RE(captureConfig->captureChannel, channelNum);
  202. }
  203. if (captureConfig->timerReset == ENABLE)
  204. {
  205. MCPWMx->CAPCON_SET = MCPWM_CAPCON_RT(captureConfig->captureChannel);
  206. }
  207. else
  208. {
  209. MCPWMx->CAPCON_CLR = MCPWM_CAPCON_RT(captureConfig->captureChannel);
  210. }
  211. if (captureConfig->hnfEnable == ENABLE)
  212. {
  213. MCPWMx->CAPCON_SET = MCPWM_CAPCON_HNFCAP(channelNum);
  214. }
  215. else
  216. {
  217. MCPWMx->CAPCON_CLR = MCPWM_CAPCON_HNFCAP(channelNum);
  218. }
  219. }
  220. }
  221. /*********************************************************************//**
  222. * @brief Clears current captured value in specified capture channel
  223. * @param[in] MCPWMx Motor Control PWM peripheral selected
  224. * Should be: LPC_MCPWM
  225. * @param[in] captureChannel Capture channel number, should be: 0..2
  226. * @return None
  227. **********************************************************************/
  228. void MCPWM_ClearCapture(LPC_MCPWM_TypeDef *MCPWMx, uint32_t captureChannel)
  229. {
  230. MCPWMx->CAP_CLR = MCPWM_CAPCLR_CAP(captureChannel);
  231. }
  232. /*********************************************************************//**
  233. * @brief Get current captured value in specified capture channel
  234. * @param[in] MCPWMx Motor Control PWM peripheral selected,
  235. * Should be: LPC_MCPWM
  236. * @param[in] captureChannel Capture channel number, should be: 0..2
  237. * @return None
  238. **********************************************************************/
  239. uint32_t MCPWM_GetCapture(LPC_MCPWM_TypeDef *MCPWMx, uint32_t captureChannel)
  240. {
  241. if (captureChannel == MCPWM_CHANNEL_0)
  242. {
  243. return (MCPWMx->CAP0);
  244. }
  245. else if (captureChannel == MCPWM_CHANNEL_1)
  246. {
  247. return (MCPWMx->CAP1);
  248. }
  249. else if (captureChannel == MCPWM_CHANNEL_2)
  250. {
  251. return (MCPWMx->CAP2);
  252. }
  253. return (0);
  254. }
  255. /*********************************************************************//**
  256. * @brief Configures Count control in MCPWM peripheral
  257. * @param[in] MCPWMx Motor Control PWM peripheral selected
  258. * Should be: LPC_MCPWM
  259. * @param[in] channelNum Channel number, should be: 0..2
  260. * @param[in] countMode Count mode, should be:
  261. * - ENABLE: Enables count mode.
  262. * - DISABLE: Disable count mode, the channel is in timer mode.
  263. * @param[in] countConfig Pointer to a MCPWM_COUNT_CFG_Type structure
  264. * that contains the configuration information for the
  265. * specified MCPWM count control.
  266. * @return None
  267. **********************************************************************/
  268. void MCPWM_CountConfig(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channelNum,
  269. uint32_t countMode, MCPWM_COUNT_CFG_Type *countConfig)
  270. {
  271. if (channelNum < MCPWM_MAX_CHANNEL)
  272. {
  273. if (countMode == ENABLE)
  274. {
  275. MCPWMx->CNTCON_SET = MCPWM_CNTCON_CNTR(channelNum);
  276. if (countConfig->countFalling == ENABLE)
  277. {
  278. MCPWMx->CNTCON_SET = MCPWM_CNTCON_TCMCI_FE(countConfig->counterChannel,channelNum);
  279. }
  280. else
  281. {
  282. MCPWMx->CNTCON_CLR = MCPWM_CNTCON_TCMCI_FE(countConfig->counterChannel,channelNum);
  283. }
  284. if (countConfig->countRising == ENABLE)
  285. {
  286. MCPWMx->CNTCON_SET = MCPWM_CNTCON_TCMCI_RE(countConfig->counterChannel,channelNum);
  287. }
  288. else
  289. {
  290. MCPWMx->CNTCON_CLR = MCPWM_CNTCON_TCMCI_RE(countConfig->counterChannel,channelNum);
  291. }
  292. }
  293. else
  294. {
  295. MCPWMx->CNTCON_CLR = MCPWM_CNTCON_CNTR(channelNum);
  296. }
  297. }
  298. }
  299. /*********************************************************************//**
  300. * @brief Start MCPWM activity for each MCPWM channel
  301. * @param[in] MCPWMx Motor Control PWM peripheral selected
  302. * Should be: LPC_MCPWM
  303. * @param[in] channel0 State of this command on channel 0:
  304. * - ENABLE: 'Start' command will effect on channel 0
  305. * - DISABLE: 'Start' command will not effect on channel 0
  306. * @param[in] channel1 State of this command on channel 1:
  307. * - ENABLE: 'Start' command will effect on channel 1
  308. * - DISABLE: 'Start' command will not effect on channel 1
  309. * @param[in] channel2 State of this command on channel 2:
  310. * - ENABLE: 'Start' command will effect on channel 2
  311. * - DISABLE: 'Start' command will not effect on channel 2
  312. * @return None
  313. **********************************************************************/
  314. void MCPWM_Start(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channel0,
  315. uint32_t channel1, uint32_t channel2)
  316. {
  317. uint32_t regVal = 0;
  318. regVal = (channel0 ? MCPWM_CON_RUN(0) : 0) | (channel1 ? MCPWM_CON_RUN(1) : 0) \
  319. | (channel2 ? MCPWM_CON_RUN(2) : 0);
  320. MCPWMx->CON_SET = regVal;
  321. }
  322. /*********************************************************************//**
  323. * @brief Stop MCPWM activity for each MCPWM channel
  324. * @param[in] MCPWMx Motor Control PWM peripheral selected
  325. * Should be: LPC_MCPWM
  326. * @param[in] channel0 State of this command on channel 0:
  327. * - ENABLE: 'Stop' command will effect on channel 0
  328. * - DISABLE: 'Stop' command will not effect on channel 0
  329. * @param[in] channel1 State of this command on channel 1:
  330. * - ENABLE: 'Stop' command will effect on channel 1
  331. * - DISABLE: 'Stop' command will not effect on channel 1
  332. * @param[in] channel2 State of this command on channel 2:
  333. * - ENABLE: 'Stop' command will effect on channel 2
  334. * - DISABLE: 'Stop' command will not effect on channel 2
  335. * @return None
  336. **********************************************************************/
  337. void MCPWM_Stop(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channel0,
  338. uint32_t channel1, uint32_t channel2)
  339. {
  340. uint32_t regVal = 0;
  341. regVal = (channel0 ? MCPWM_CON_RUN(0) : 0) | (channel1 ? MCPWM_CON_RUN(1) : 0) \
  342. | (channel2 ? MCPWM_CON_RUN(2) : 0);
  343. MCPWMx->CON_CLR = regVal;
  344. }
  345. /*********************************************************************//**
  346. * @brief Enables/Disables 3-phase AC motor mode on MCPWM peripheral
  347. * @param[in] MCPWMx Motor Control PWM peripheral selected
  348. * Should be: LPC_MCPWM
  349. * @param[in] acMode State of this command, should be:
  350. * - ENABLE.
  351. * - DISABLE.
  352. * @return None
  353. **********************************************************************/
  354. void MCPWM_ACMode(LPC_MCPWM_TypeDef *MCPWMx, uint32_t acMode)
  355. {
  356. if (acMode)
  357. {
  358. MCPWMx->CON_SET = MCPWM_CON_ACMODE;
  359. }
  360. else
  361. {
  362. MCPWMx->CON_CLR = MCPWM_CON_ACMODE;
  363. }
  364. }
  365. /*********************************************************************//**
  366. * @brief Enables/Disables 3-phase DC motor mode on MCPWM peripheral
  367. * @param[in] MCPWMx Motor Control PWM peripheral selected
  368. * Should be: LPC_MCPWM
  369. * @param[in] dcMode State of this command, should be:
  370. * - ENABLE.
  371. * - DISABLE.
  372. * @param[in] outputInvered Polarity of the MCOB outputs for all 3 channels,
  373. * should be:
  374. * - ENABLE: The MCOB outputs have opposite polarity
  375. * from the MCOA outputs.
  376. * - DISABLE: The MCOB outputs have the same basic
  377. * polarity as the MCOA outputs.
  378. * @param[in] outputPattern A value contains bits that enables/disables the specified
  379. * output pins route to the internal MCOA0 signal, should be:
  380. - MCPWM_PATENT_A0: MCOA0 tracks internal MCOA0
  381. - MCPWM_PATENT_B0: MCOB0 tracks internal MCOA0
  382. - MCPWM_PATENT_A1: MCOA1 tracks internal MCOA0
  383. - MCPWM_PATENT_B1: MCOB1 tracks internal MCOA0
  384. - MCPWM_PATENT_A2: MCOA2 tracks internal MCOA0
  385. - MCPWM_PATENT_B2: MCOB2 tracks internal MCOA0
  386. * @return None
  387. *
  388. * Note: all these outputPatent values above can be ORed together for using as input parameter.
  389. **********************************************************************/
  390. void MCPWM_DCMode(LPC_MCPWM_TypeDef *MCPWMx, uint32_t dcMode,
  391. uint32_t outputInvered, uint32_t outputPattern)
  392. {
  393. if (dcMode)
  394. {
  395. MCPWMx->CON_SET = MCPWM_CON_DCMODE;
  396. }
  397. else
  398. {
  399. MCPWMx->CON_CLR = MCPWM_CON_DCMODE;
  400. }
  401. if (outputInvered)
  402. {
  403. MCPWMx->CON_SET = MCPWM_CON_INVBDC;
  404. }
  405. else
  406. {
  407. MCPWMx->CON_CLR = MCPWM_CON_INVBDC;
  408. }
  409. MCPWMx->CP = outputPattern;
  410. }
  411. /*********************************************************************//**
  412. * @brief Configures the specified interrupt in MCPWM peripheral
  413. * @param[in] MCPWMx Motor Control PWM peripheral selected
  414. * Should be: LPC_MCPWM
  415. * @param[in] ulIntType Interrupt type, should be:
  416. * - MCPWM_INTFLAG_LIM0: Limit interrupt for channel (0)
  417. * - MCPWM_INTFLAG_MAT0: Match interrupt for channel (0)
  418. * - MCPWM_INTFLAG_CAP0: Capture interrupt for channel (0)
  419. * - MCPWM_INTFLAG_LIM1: Limit interrupt for channel (1)
  420. * - MCPWM_INTFLAG_MAT1: Match interrupt for channel (1)
  421. * - MCPWM_INTFLAG_CAP1: Capture interrupt for channel (1)
  422. * - MCPWM_INTFLAG_LIM2: Limit interrupt for channel (2)
  423. * - MCPWM_INTFLAG_MAT2: Match interrupt for channel (2)
  424. * - MCPWM_INTFLAG_CAP2: Capture interrupt for channel (2)
  425. * - MCPWM_INTFLAG_ABORT: Fast abort interrupt
  426. * @param[in] NewState New State of this command, should be:
  427. * - ENABLE.
  428. * - DISABLE.
  429. * @return None
  430. *
  431. * Note: all these ulIntType values above can be ORed together for using as input parameter.
  432. **********************************************************************/
  433. void MCPWM_IntConfig(LPC_MCPWM_TypeDef *MCPWMx, uint32_t ulIntType, FunctionalState NewState)
  434. {
  435. if (NewState)
  436. {
  437. MCPWMx->INTEN_SET = ulIntType;
  438. }
  439. else
  440. {
  441. MCPWMx->INTEN_CLR = ulIntType;
  442. }
  443. }
  444. /*********************************************************************//**
  445. * @brief Sets/Forces the specified interrupt for MCPWM peripheral
  446. * @param[in] MCPWMx Motor Control PWM peripheral selected
  447. * Should be LPC_MCPWM
  448. * @param[in] ulIntType Interrupt type, should be:
  449. * - MCPWM_INTFLAG_LIM0: Limit interrupt for channel (0)
  450. * - MCPWM_INTFLAG_MAT0: Match interrupt for channel (0)
  451. * - MCPWM_INTFLAG_CAP0: Capture interrupt for channel (0)
  452. * - MCPWM_INTFLAG_LIM1: Limit interrupt for channel (1)
  453. * - MCPWM_INTFLAG_MAT1: Match interrupt for channel (1)
  454. * - MCPWM_INTFLAG_CAP1: Capture interrupt for channel (1)
  455. * - MCPWM_INTFLAG_LIM2: Limit interrupt for channel (2)
  456. * - MCPWM_INTFLAG_MAT2: Match interrupt for channel (2)
  457. * - MCPWM_INTFLAG_CAP2: Capture interrupt for channel (2)
  458. * - MCPWM_INTFLAG_ABORT: Fast abort interrupt
  459. * @return None
  460. * Note: all these ulIntType values above can be ORed together for using as input parameter.
  461. **********************************************************************/
  462. void MCPWM_IntSet(LPC_MCPWM_TypeDef *MCPWMx, uint32_t ulIntType)
  463. {
  464. MCPWMx->INTF_SET = ulIntType;
  465. }
  466. /*********************************************************************//**
  467. * @brief Clear the specified interrupt pending for MCPWM peripheral
  468. * @param[in] MCPWMx Motor Control PWM peripheral selected,
  469. * should be: LPC_MCPWM
  470. * @param[in] ulIntType Interrupt type, should be:
  471. * - MCPWM_INTFLAG_LIM0: Limit interrupt for channel (0)
  472. * - MCPWM_INTFLAG_MAT0: Match interrupt for channel (0)
  473. * - MCPWM_INTFLAG_CAP0: Capture interrupt for channel (0)
  474. * - MCPWM_INTFLAG_LIM1: Limit interrupt for channel (1)
  475. * - MCPWM_INTFLAG_MAT1: Match interrupt for channel (1)
  476. * - MCPWM_INTFLAG_CAP1: Capture interrupt for channel (1)
  477. * - MCPWM_INTFLAG_LIM2: Limit interrupt for channel (2)
  478. * - MCPWM_INTFLAG_MAT2: Match interrupt for channel (2)
  479. * - MCPWM_INTFLAG_CAP2: Capture interrupt for channel (2)
  480. * - MCPWM_INTFLAG_ABORT: Fast abort interrupt
  481. * @return None
  482. * Note: all these ulIntType values above can be ORed together for using as input parameter.
  483. **********************************************************************/
  484. void MCPWM_IntClear(LPC_MCPWM_TypeDef *MCPWMx, uint32_t ulIntType)
  485. {
  486. MCPWMx->INTF_CLR = ulIntType;
  487. }
  488. /*********************************************************************//**
  489. * @brief Check whether if the specified interrupt in MCPWM is set or not
  490. * @param[in] MCPWMx Motor Control PWM peripheral selected,
  491. * should be: LPC_MCPWM
  492. * @param[in] ulIntType Interrupt type, should be:
  493. * - MCPWM_INTFLAG_LIM0: Limit interrupt for channel (0)
  494. * - MCPWM_INTFLAG_MAT0: Match interrupt for channel (0)
  495. * - MCPWM_INTFLAG_CAP0: Capture interrupt for channel (0)
  496. * - MCPWM_INTFLAG_LIM1: Limit interrupt for channel (1)
  497. * - MCPWM_INTFLAG_MAT1: Match interrupt for channel (1)
  498. * - MCPWM_INTFLAG_CAP1: Capture interrupt for channel (1)
  499. * - MCPWM_INTFLAG_LIM2: Limit interrupt for channel (2)
  500. * - MCPWM_INTFLAG_MAT2: Match interrupt for channel (2)
  501. * - MCPWM_INTFLAG_CAP2: Capture interrupt for channel (2)
  502. * - MCPWM_INTFLAG_ABORT: Fast abort interrupt
  503. * @return None
  504. **********************************************************************/
  505. FlagStatus MCPWM_GetIntStatus(LPC_MCPWM_TypeDef *MCPWMx, uint32_t ulIntType)
  506. {
  507. return ((MCPWMx->INTF & ulIntType) ? SET : RESET);
  508. }
  509. /**
  510. * @}
  511. */
  512. #endif /*_MCPWM*/
  513. /**
  514. * @}
  515. */
  516. /* --------------------------------- End Of File ------------------------------ */