1 /**********************************************************************
\r
2 * $Id$ lpc18xx_mcpwm.h 2011-06-02
\r
4 * @file lpc18xx_mcpwm.h
\r
5 * @brief Contains all macro definitions and function prototypes
\r
6 * support for Motor Control PWM firmware library on LPC18XX
\r
8 * @date 02. June. 2011
\r
9 * @author NXP MCU SW Application Team
\r
11 * Copyright(C) 2011, NXP Semiconductor
\r
12 * All rights reserved.
\r
14 ***********************************************************************
\r
15 * Software that is described herein is for illustrative purposes only
\r
16 * which provides customers with programming information regarding the
\r
17 * products. This software is supplied "AS IS" without any warranties.
\r
18 * NXP Semiconductors assumes no responsibility or liability for the
\r
19 * use of the software, conveys no license or title under any patent,
\r
20 * copyright, or mask work right to the product. NXP Semiconductors
\r
21 * reserves the right to make changes in the software without
\r
22 * notification. NXP Semiconductors also make no representation or
\r
23 * warranty that such application will be suitable for the specified
\r
24 * use without further testing or modification.
\r
25 **********************************************************************/
\r
27 /* Peripheral group ----------------------------------------------------------- */
\r
28 /** @defgroup MCPWM MCPWM (Motor Control PWM)
\r
29 * @ingroup LPC1800CMSIS_FwLib_Drivers
\r
33 #ifndef LPC18XX_MCPWM_H_
\r
34 #define LPC18XX_MCPWM_H_
\r
36 /* Includes ------------------------------------------------------------------- */
\r
37 #include "LPC18xx.h"
\r
38 #include "lpc_types.h"
\r
47 /* Private Macros ------------------------------------------------------------- */
\r
48 /** @defgroup MCPWM_Private_Macros MCPWM Private Macros
\r
51 /** Edge aligned mode for channel in MCPWM */
\r
52 #define MCPWM_CHANNEL_EDGE_MODE ((uint32_t)(0))
\r
53 /** Center aligned mode for channel in MCPWM */
\r
54 #define MCPWM_CHANNEL_CENTER_MODE ((uint32_t)(1))
\r
56 /** Polarity of the MCOA and MCOB pins: Passive state is LOW, active state is HIGH */
\r
57 #define MCPWM_CHANNEL_PASSIVE_LO ((uint32_t)(0))
\r
58 /** Polarity of the MCOA and MCOB pins: Passive state is HIGH, active state is LOW */
\r
59 #define MCPWM_CHANNEL_PASSIVE_HI ((uint32_t)(1))
\r
61 /* Output Patent in 3-phase DC mode, the internal MCOA0 signal is routed to any or all of
\r
62 * the six output pins under the control of the bits in this register */
\r
63 #define MCPWM_PATENT_A0 ((uint32_t)(1<<0)) /**< MCOA0 tracks internal MCOA0 */
\r
64 #define MCPWM_PATENT_B0 ((uint32_t)(1<<1)) /**< MCOB0 tracks internal MCOA0 */
\r
65 #define MCPWM_PATENT_A1 ((uint32_t)(1<<2)) /**< MCOA1 tracks internal MCOA0 */
\r
66 #define MCPWM_PATENT_B1 ((uint32_t)(1<<3)) /**< MCOB1 tracks internal MCOA0 */
\r
67 #define MCPWM_PATENT_A2 ((uint32_t)(1<<4)) /**< MCOA2 tracks internal MCOA0 */
\r
68 #define MCPWM_PATENT_B2 ((uint32_t)(1<<5)) /**< MCOB2 tracks internal MCOA0 */
\r
70 /* Interrupt type in MCPWM */
\r
71 /** Limit interrupt for channel (0) */
\r
72 #define MCPWM_INTFLAG_LIM0 MCPWM_INT_ILIM(0)
\r
73 /** Match interrupt for channel (0) */
\r
74 #define MCPWM_INTFLAG_MAT0 MCPWM_INT_IMAT(0)
\r
75 /** Capture interrupt for channel (0) */
\r
76 #define MCPWM_INTFLAG_CAP0 MCPWM_INT_ICAP(0)
\r
78 /** Limit interrupt for channel (1) */
\r
79 #define MCPWM_INTFLAG_LIM1 MCPWM_INT_ILIM(1)
\r
80 /** Match interrupt for channel (1) */
\r
81 #define MCPWM_INTFLAG_MAT1 MCPWM_INT_IMAT(1)
\r
82 /** Capture interrupt for channel (1) */
\r
83 #define MCPWM_INTFLAG_CAP1 MCPWM_INT_ICAP(1)
\r
85 /** Limit interrupt for channel (2) */
\r
86 #define MCPWM_INTFLAG_LIM2 MCPWM_INT_ILIM(2)
\r
87 /** Match interrupt for channel (2) */
\r
88 #define MCPWM_INTFLAG_MAT2 MCPWM_INT_IMAT(2)
\r
89 /** Capture interrupt for channel (2) */
\r
90 #define MCPWM_INTFLAG_CAP2 MCPWM_INT_ICAP(2)
\r
92 /** Fast abort interrupt */
\r
93 #define MCPWM_INTFLAG_ABORT MCPWM_INT_ABORT
\r
95 /*********************************************************************//**
\r
96 * Macro defines for MCPWM Control register
\r
97 **********************************************************************/
\r
98 /* MCPWM Control register, these macro definitions below can be applied for these
\r
100 * - MCPWM Control read address
\r
101 * - MCPWM Control set address
\r
102 * - MCPWM Control clear address
\r
104 /**< Stops/starts timer channel n */
\r
105 #define MCPWM_CON_RUN(n) (((n>=0)&&(n<=2)) ? ((uint32_t)(1<<((n*8)+0))) : (0))
\r
106 /**< Edge/center aligned operation for channel n */
\r
107 #define MCPWM_CON_CENTER(n) (((n<=2)) ? ((uint32_t)(1<<((n*8)+1))) : (0))
\r
108 /**< Select polarity of the MCOAn and MCOBn pin */
\r
109 #define MCPWM_CON_POLAR(n) (((n<=2)) ? ((uint32_t)(1<<((n*8)+2))) : (0))
\r
110 /**< Control the dead-time feature for channel n */
\r
111 #define MCPWM_CON_DTE(n) (((n<=2)) ? ((uint32_t)(1<<((n*8)+3))) : (0))
\r
112 /**< Enable/Disable update of functional register for channel n */
\r
113 #define MCPWM_CON_DISUP(n) (((n<=2)) ? ((uint32_t)(1<<((n*8)+4))) : (0))
\r
114 /**< Control the polarity for all 3 channels */
\r
115 #define MCPWM_CON_INVBDC ((uint32_t)(1<<29))
\r
116 /**< 3-phase AC mode select */
\r
117 #define MCPWM_CON_ACMODE ((uint32_t)(1<<30))
\r
118 /**< 3-phase DC mode select */
\r
119 #define MCPWM_CON_DCMODE (((uint32_t)1<<31))
\r
121 /*********************************************************************//**
\r
122 * Macro defines for MCPWM Capture Control register
\r
123 **********************************************************************/
\r
124 /* Capture Control register, these macro definitions below can be applied for these
\r
126 * - MCPWM Capture Control read address
\r
127 * - MCPWM Capture Control set address
\r
128 * - MCPWM Capture control clear address
\r
130 /** Enables/Disable channel (cap) capture event on a rising edge on MCI(mci) */
\r
131 #define MCPWM_CAPCON_CAPMCI_RE(cap,mci) (((cap<=2)&&(mci<=2)) ? ((uint32_t)(1<<((cap*6)+(mci*2)+0))) : (0))
\r
132 /** Enables/Disable channel (cap) capture event on a falling edge on MCI(mci) */
\r
133 #define MCPWM_CAPCON_CAPMCI_FE(cap,mci) (((cap<=2)&&(mci<=2)) ? ((uint32_t)(1<<((cap*6)+(mci*2)+1))) : (0))
\r
134 /** TC(n) is reset by channel (n) capture event */
\r
135 #define MCPWM_CAPCON_RT(n) (((n<=2)) ? ((uint32_t)(1<<(18+(n)))) : (0))
\r
136 /** Hardware noise filter: channel (n) capture events are delayed */
\r
137 #define MCPWM_CAPCON_HNFCAP(n) (((n<=2)) ? ((uint32_t)(1<<(21+(n)))) : (0))
\r
139 /*********************************************************************//**
\r
140 * Macro defines for MCPWM Interrupt register
\r
141 **********************************************************************/
\r
142 /* Interrupt registers, these macro definitions below can be applied for these
\r
144 * - MCPWM Interrupt Enable read address
\r
145 * - MCPWM Interrupt Enable set address
\r
146 * - MCPWM Interrupt Enable clear address
\r
147 * - MCPWM Interrupt Flags read address
\r
148 * - MCPWM Interrupt Flags set address
\r
149 * - MCPWM Interrupt Flags clear address
\r
151 /** Limit interrupt for channel (n) */
\r
152 #define MCPWM_INT_ILIM(n) (((n>=0)&&(n<=2)) ? ((uint32_t)(1<<((n*4)+0))) : (0))
\r
153 /** Match interrupt for channel (n) */
\r
154 #define MCPWM_INT_IMAT(n) (((n>=0)&&(n<=2)) ? ((uint32_t)(1<<((n*4)+1))) : (0))
\r
155 /** Capture interrupt for channel (n) */
\r
156 #define MCPWM_INT_ICAP(n) (((n>=0)&&(n<=2)) ? ((uint32_t)(1<<((n*4)+2))) : (0))
\r
157 /** Fast abort interrupt */
\r
158 #define MCPWM_INT_ABORT ((uint32_t)(1<<15))
\r
160 /*********************************************************************//**
\r
161 * Macro defines for MCPWM Count Control register
\r
162 **********************************************************************/
\r
163 /* MCPWM Count Control register, these macro definitions below can be applied for these
\r
165 * - MCPWM Count Control read address
\r
166 * - MCPWM Count Control set address
\r
167 * - MCPWM Count Control clear address
\r
169 /** Counter(tc) advances on a rising edge on MCI(mci) pin */
\r
170 #define MCPWM_CNTCON_TCMCI_RE(tc,mci) (((tc<=2)&&(mci<=2)) ? ((uint32_t)(1<<((6*tc)+(2*mci)+0))) : (0))
\r
171 /** Counter(cnt) advances on a falling edge on MCI(mci) pin */
\r
172 #define MCPWM_CNTCON_TCMCI_FE(tc,mci) (((tc<=2)&&(mci<=2)) ? ((uint32_t)(1<<((6*tc)+(2*mci)+1))) : (0))
\r
173 /** Channel (n) is in counter mode */
\r
174 #define MCPWM_CNTCON_CNTR(n) (((n<=2)) ? ((uint32_t)(1<<(29+n))) : (0))
\r
176 /*********************************************************************//**
\r
177 * Macro defines for MCPWM Dead-time register
\r
178 **********************************************************************/
\r
179 /** Dead time value x for channel n */
\r
180 #define MCPWM_DT(n,x) (((n<=2)) ? ((uint32_t)((x&0x3FF)<<(n*10))) : (0))
\r
182 /*********************************************************************//**
\r
183 * Macro defines for MCPWM Communication Pattern register
\r
184 **********************************************************************/
\r
185 #define MCPWM_CP_A0 ((uint32_t)(1<<0)) /**< MCOA0 tracks internal MCOA0 */
\r
186 #define MCPWM_CP_B0 ((uint32_t)(1<<1)) /**< MCOB0 tracks internal MCOA0 */
\r
187 #define MCPWM_CP_A1 ((uint32_t)(1<<2)) /**< MCOA1 tracks internal MCOA0 */
\r
188 #define MCPWM_CP_B1 ((uint32_t)(1<<3)) /**< MCOB1 tracks internal MCOA0 */
\r
189 #define MCPWM_CP_A2 ((uint32_t)(1<<4)) /**< MCOA2 tracks internal MCOA0 */
\r
190 #define MCPWM_CP_B2 ((uint32_t)(1<<5)) /**< MCOB2 tracks internal MCOA0 */
\r
192 /*********************************************************************//**
\r
193 * Macro defines for MCPWM Capture clear address register
\r
194 **********************************************************************/
\r
195 /** Clear the MCCAP (n) register */
\r
196 #define MCPWM_CAPCLR_CAP(n) (((n<=2)) ? ((uint32_t)(1<<n)) : (0))
\r
204 /* Public Types --------------------------------------------------------------- */
\r
205 /** @defgroup MCPWM_Public_Types MCPWM Public Types
\r
209 /*********************************************************************//**
\r
210 * @brief MCPWM enumeration
\r
211 **********************************************************************/
\r
213 * @brief MCPWM channel identifier definition
\r
217 MCPWM_CHANNEL_0 = 0, /**< MCPWM channel 0 */
\r
218 MCPWM_CHANNEL_1, /**< MCPWM channel 1 */
\r
219 MCPWM_CHANNEL_2 /**< MCPWM channel 2 */
\r
220 } en_MCPWM_Channel_Id;
\r
223 /*********************************************************************//**
\r
224 * @brief MCPWM structure definitions
\r
225 **********************************************************************/
\r
227 * @brief Motor Control PWM Channel Configuration structure type definition
\r
230 uint32_t channelType; /**< Edge/center aligned mode for this channel,
\r
232 - MCPWM_CHANNEL_EDGE_MODE: Channel is in Edge mode
\r
233 - MCPWM_CHANNEL_CENTER_MODE: Channel is in Center mode
\r
235 uint32_t channelPolarity; /**< Polarity of the MCOA and MCOB pins, should be:
\r
236 - MCPWM_CHANNEL_PASSIVE_LO: Passive state is LOW, active state is HIGH
\r
237 - MCPWM_CHANNEL_PASSIVE_HI: Passive state is HIGH, active state is LOW
\r
239 uint32_t channelDeadtimeEnable; /**< Enable/Disable DeadTime function for channel, should be:
\r
243 uint32_t channelDeadtimeValue; /**< DeadTime value, should be less than 0x3FF */
\r
244 uint32_t channelUpdateEnable; /**< Enable/Disable updates of functional registers,
\r
249 uint32_t channelTimercounterValue; /**< MCPWM Timer Counter value */
\r
250 uint32_t channelPeriodValue; /**< MCPWM Period value */
\r
251 uint32_t channelPulsewidthValue; /**< MCPWM Pulse Width value */
\r
252 } MCPWM_CHANNEL_CFG_Type;
\r
255 * @brief MCPWM Capture Configuration type definition
\r
258 uint32_t captureChannel; /**< Capture Channel Number, should be in range from 0 to 2 */
\r
259 uint32_t captureRising; /**< Enable/Disable Capture on Rising Edge event, should be:
\r
263 uint32_t captureFalling; /**< Enable/Disable Capture on Falling Edge event, should be:
\r
267 uint32_t timerReset; /**< Enable/Disable Timer reset function an capture, should be:
\r
271 uint32_t hnfEnable; /**< Enable/Disable Hardware noise filter function, should be:
\r
275 } MCPWM_CAPTURE_CFG_Type;
\r
279 * @brief MCPWM Count Control Configuration type definition
\r
282 uint32_t counterChannel; /**< Counter Channel Number, should be in range from 0 to 2 */
\r
283 uint32_t countRising; /**< Enable/Disable Capture on Rising Edge event, should be:
\r
287 uint32_t countFalling; /**< Enable/Disable Capture on Falling Edge event, should be:
\r
291 } MCPWM_COUNT_CFG_Type;
\r
298 /* Public Functions ----------------------------------------------------------- */
\r
299 /** @defgroup MCPWM_Public_Functions MCPWM Public Functions
\r
303 void MCPWM_Init(LPC_MCPWM_Type *MCPWMx);
\r
304 void MCPWM_ConfigChannel(LPC_MCPWM_Type *MCPWMx, uint32_t channelNum,
\r
305 MCPWM_CHANNEL_CFG_Type * channelSetup);
\r
306 void MCPWM_WriteToShadow(LPC_MCPWM_Type *MCPWMx, uint32_t channelNum,
\r
307 MCPWM_CHANNEL_CFG_Type *channelSetup);
\r
308 void MCPWM_ConfigCapture(LPC_MCPWM_Type *MCPWMx, uint32_t channelNum,
\r
309 MCPWM_CAPTURE_CFG_Type *captureConfig);
\r
310 void MCPWM_ClearCapture(LPC_MCPWM_Type *MCPWMx, uint32_t captureChannel);
\r
311 uint32_t MCPWM_GetCapture(LPC_MCPWM_Type *MCPWMx, uint32_t captureChannel);
\r
312 void MCPWM_CountConfig(LPC_MCPWM_Type *MCPWMx, uint32_t channelNum,
\r
313 uint32_t countMode, MCPWM_COUNT_CFG_Type *countConfig);
\r
314 void MCPWM_Start(LPC_MCPWM_Type *MCPWMx,uint32_t channel0, uint32_t channel1, uint32_t channel2);
\r
315 void MCPWM_Stop(LPC_MCPWM_Type *MCPWMx,uint32_t channel0, uint32_t channel1, uint32_t channel2);
\r
316 void MCPWM_ACMode(LPC_MCPWM_Type *MCPWMx,uint32_t acMode);
\r
317 void MCPWM_DCMode(LPC_MCPWM_Type *MCPWMx, uint32_t dcMode,
\r
318 uint32_t outputInvered, uint32_t outputPattern);
\r
319 void MCPWM_IntConfig(LPC_MCPWM_Type *MCPWMx, uint32_t ulIntType, FunctionalState NewState);
\r
320 void MCPWM_IntSet(LPC_MCPWM_Type *MCPWMx, uint32_t ulIntType);
\r
321 void MCPWM_IntClear(LPC_MCPWM_Type *MCPWMx, uint32_t ulIntType);
\r
322 FlagStatus MCPWM_GetIntStatus(LPC_MCPWM_Type *MCPWMx, uint32_t ulIntType);
\r
332 #endif /* LPC18XX_MCPWM_H_ */
\r
338 /* --------------------------------- End Of File ------------------------------ */
\r