uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc17xx_pwm.h
Go to the documentation of this file.
1 /***********************************************************************/
21 /* Peripheral group ----------------------------------------------------------- */
27 #ifndef LPC17XX_PWM_H_
28 #define LPC17XX_PWM_H_
29 
30 /* Includes ------------------------------------------------------------------- */
31 #include "LPC17xx.h"
32 #include "lpc_types.h"
33 
34 
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39 
40 
41 /* Private Macros ------------------------------------------------------------- */
46 /* --------------------- BIT DEFINITIONS -------------------------------------- */
47 /**********************************************************************
48 * IR register definitions
49 **********************************************************************/
51 #define PWM_IR_PWMMRn(n) ((uint32_t)((n<4)?(1<<n):(1<<(n+4))))
52 
53 #define PWM_IR_PWMCAPn(n) ((uint32_t)(1<<(n+4)))
54 
55 #define PWM_IR_BITMASK ((uint32_t)(0x0000073F))
56 
57 /**********************************************************************
58 * TCR register definitions
59 **********************************************************************/
61 #define PWM_TCR_BITMASK ((uint32_t)(0x0000000B))
62 #define PWM_TCR_COUNTER_ENABLE ((uint32_t)(1<<0))
63 #define PWM_TCR_COUNTER_RESET ((uint32_t)(1<<1))
64 #define PWM_TCR_PWM_ENABLE ((uint32_t)(1<<3))
66 /**********************************************************************
67 * CTCR register definitions
68 **********************************************************************/
69 
70 #define PWM_CTCR_BITMASK ((uint32_t)(0x0000000F))
71 
72 #define PWM_CTCR_MODE(n) ((uint32_t)(n&0x03))
73 
74 #define PWM_CTCR_SELECT_INPUT(n) ((uint32_t)((n&0x03)<<2))
75 
76 /**********************************************************************
77 * MCR register definitions
78 **********************************************************************/
80 #define PWM_MCR_BITMASK ((uint32_t)(0x001FFFFF))
81 
82 #define PWM_MCR_INT_ON_MATCH(n) ((uint32_t)(1<<(((n&0x7)<<1)+(n&0x07))))
83 
84 #define PWM_MCR_RESET_ON_MATCH(n) ((uint32_t)(1<<(((n&0x7)<<1)+(n&0x07)+1)))
85 
86 #define PWM_MCR_STOP_ON_MATCH(n) ((uint32_t)(1<<(((n&0x7)<<1)+(n&0x07)+2)))
87 
88 /**********************************************************************
89 * CCR register definitions
90 **********************************************************************/
92 #define PWM_CCR_BITMASK ((uint32_t)(0x0000003F))
93 
94 #define PWM_CCR_CAP_RISING(n) ((uint32_t)(1<<(((n&0x2)<<1)+(n&0x1))))
95 
96 #define PWM_CCR_CAP_FALLING(n) ((uint32_t)(1<<(((n&0x2)<<1)+(n&0x1)+1)))
97 
98 #define PWM_CCR_INT_ON_CAP(n) ((uint32_t)(1<<(((n&0x2)<<1)+(n&0x1)+2)))
99 
100 /**********************************************************************
101 * PCR register definitions
102 **********************************************************************/
104 #define PWM_PCR_BITMASK (uint32_t)0x00007E7C
105 
106 #define PWM_PCR_PWMSELn(n) ((uint32_t)(((n&0x7)<2) ? 0 : (1<<n)))
107 
108 #define PWM_PCR_PWMENAn(n) ((uint32_t)(((n&0x7)<1) ? 0 : (1<<(n+8))))
109 
110 /**********************************************************************
111 * LER register definitions
112 **********************************************************************/
114 #define PWM_LER_BITMASK ((uint32_t)(0x0000007F))
115 
116 #define PWM_LER_EN_MATCHn_LATCH(n) ((uint32_t)((n<7) ? (1<<n) : 0))
117 
118 /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
120 #define PARAM_PWMx(n) (((uint32_t *)n)==((uint32_t *)LPC_PWM1))
121 
123 #define PARAM_PWM1_MATCH_CHANNEL(n) ((n>=0) && (n<=6))
124 
126 #define PARAM_PWM1_CHANNEL(n) ((n>=1) && (n<=6))
127 
129 #define PARAM_PWM1_EDGE_MODE_CHANNEL(n) ((n>=2) && (n<=6))
130 
132 #define PARAM_PWM1_CAPTURE_CHANNEL(n) ((n==0) || (n==1))
133 
135 #define PARAM_PWM_INTSTAT(n) ((n==PWM_INTSTAT_MR0) || (n==PWM_INTSTAT_MR1) || (n==PWM_INTSTAT_MR2) \
136 || (n==PWM_INTSTAT_MR3) || (n==PWM_INTSTAT_MR4) || (n==PWM_INTSTAT_MR5) \
137 || (n==PWM_INTSTAT_MR6) || (n==PWM_INTSTAT_CAP0) || (n==PWM_INTSTAT_CAP1))
138 
143 /* Public Types --------------------------------------------------------------- */
149 typedef struct {
150 
151  uint8_t PrescaleOption;
155  uint8_t Reserved[3];
156  uint32_t PrescaleValue;
160 
162 typedef struct {
163 
164  uint8_t CounterOption;
173  uint8_t Reserved[2];
175 
177 typedef struct {
178  uint8_t MatchChannel;
180  uint8_t IntOnMatch;
184  uint8_t StopOnMatch;
188  uint8_t ResetOnMatch;
193 
194 
196 typedef struct {
197  uint8_t CaptureChannel;
199  uint8_t RisingEdge;
203  uint8_t FallingEdge;
207  uint8_t IntOnCaption;
212 
213 /* Timer/Counter in PWM configuration type definition -----------------------------------*/
214 
216 typedef enum {
220 
221 #define PARAM_PWM_TC_MODE(n) ((n==PWM_MODE_TIMER) || (n==PWM_MODE_COUNTER))
222 
223 
225 typedef enum
226 {
230 
231 #define PARAM_PWM_TIMER_PRESCALE(n) ((n==PWM_TIMER_PRESCALE_TICKVAL) || (n==PWM_TIMER_PRESCALE_USVAL))
232 
233 
235 typedef enum {
239 
240 #define PARAM_PWM_COUNTER_INPUTSEL(n) ((n==PWM_COUNTER_PCAP1_0) || (n==PWM_COUNTER_PCAP1_1))
241 
243 typedef enum {
248 
249 #define PARAM_PWM_COUNTER_EDGE(n) ((n==PWM_COUNTER_RISING) || (n==PWM_COUNTER_FALLING) \
250 || (n==PWM_COUNTER_ANY))
251 
252 
253 /* PWM configuration type definition ----------------------------------------------------- */
255 typedef enum {
259 
260 #define PARAM_PWM_CHANNEL_EDGE(n) ((n==PWM_CHANNEL_SINGLE_EDGE) || (n==PWM_CHANNEL_DUAL_EDGE))
261 
262 
264 typedef enum {
269 
270 #define PARAM_PWM_MATCH_UPDATE(n) ((n==PWM_MATCH_UPDATE_NOW) || (n==PWM_MATCH_UPDATE_NEXT_RST))
271 
272 
275 typedef enum
276 {
287 
288 
294 /* Public Functions ----------------------------------------------------------- */
299 void PWM_PinConfig(LPC_PWM_TypeDef *PWMx, uint8_t PWM_Channel, uint8_t PinselOption);
300 IntStatus PWM_GetIntStatus(LPC_PWM_TypeDef *PWMx, uint32_t IntFlag);
301 void PWM_ClearIntPending(LPC_PWM_TypeDef *PWMx, uint32_t IntFlag);
302 void PWM_ConfigStructInit(uint8_t PWMTimerCounterMode, void *PWM_InitStruct);
303 void PWM_Init(LPC_PWM_TypeDef *PWMx, uint32_t PWMTimerCounterMode, void *PWM_ConfigStruct);
304 void PWM_DeInit (LPC_PWM_TypeDef *PWMx);
305 void PWM_Cmd(LPC_PWM_TypeDef *PWMx, FunctionalState NewState);
306 void PWM_CounterCmd(LPC_PWM_TypeDef *PWMx, FunctionalState NewState);
308 void PWM_ConfigMatch(LPC_PWM_TypeDef *PWMx, PWM_MATCHCFG_Type *PWM_MatchConfigStruct);
309 void PWM_ConfigCapture(LPC_PWM_TypeDef *PWMx, PWM_CAPTURECFG_Type *PWM_CaptureConfigStruct);
310 uint32_t PWM_GetCaptureValue(LPC_PWM_TypeDef *PWMx, uint8_t CaptureChannel);
311 void PWM_MatchUpdate(LPC_PWM_TypeDef *PWMx, uint8_t MatchChannel, \
312  uint32_t MatchValue, uint8_t UpdateType);
313 void PWM_ChannelConfig(LPC_PWM_TypeDef *PWMx, uint8_t PWMChannel, uint8_t ModeOption);
314 void PWM_ChannelCmd(LPC_PWM_TypeDef *PWMx, uint8_t PWMChannel, FunctionalState NewState);
315 
320 #ifdef __cplusplus
321 }
322 #endif
323 
324 #endif /* LPC17XX_PWM_H_ */
325 
330 /* --------------------------------- End Of File ------------------------------ */