Date: March 20, 2011 This library is created from "LPC17xx CMSIS-Compliant Standard Peripheral Firmware Driver Library (GNU, Keil, IAR) (Jan 28, 2011)", available from NXP's website, under "All microcontrollers support documents" [[http://ics.nxp.com/support/documents/microcontrollers/?type=software]] You will need to follow [[/projects/libraries/svn/mbed/trunk/LPC1768/LPC17xx.h]] while using this library Examples provided here [[/users/frank26080115/programs/LPC1700CMSIS_Examples/]] The beautiful thing is that NXP does not place copyright protection on any of the files in here Only a few modifications are made to make it compile with the mbed online compiler, I fixed some warnings as well. This is untested as of March 20, 2011 Forum post about this library: [[/forum/mbed/topic/2030/]]

Committer:
frank26080115
Date:
Sun Mar 20 18:45:15 2011 +0000
Revision:
0:84d7747641aa

        

Who changed what in which revision?

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