uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc17xx_qei.h
Go to the documentation of this file.
1 /***********************************************************************/
21 /* Peripheral group ----------------------------------------------------------- */
27 #ifndef LPC17XX_QEI_H_
28 #define LPC17XX_QEI_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 /* Public Macros -------------------------------------------------------------- */
45 /* QEI Reset types */
46 #define QEI_RESET_POS QEI_CON_RESP
47 #define QEI_RESET_POSOnIDX QEI_CON_RESPI
48 #define QEI_RESET_VEL QEI_CON_RESV
49 #define QEI_RESET_IDX QEI_CON_RESI
51 /* QEI Direction Invert Type Option */
52 #define QEI_DIRINV_NONE ((uint32_t)(0))
53 #define QEI_DIRINV_CMPL ((uint32_t)(1))
55 /* QEI Signal Mode Option */
56 #define QEI_SIGNALMODE_QUAD ((uint32_t)(0))
57 #define QEI_SIGNALMODE_CLKDIR ((uint32_t)(1))
59 /* QEI Capture Mode Option */
60 #define QEI_CAPMODE_2X ((uint32_t)(0))
61 #define QEI_CAPMODE_4X ((uint32_t)(1))
63 /* QEI Invert Index Signal Option */
64 #define QEI_INVINX_NONE ((uint32_t)(0))
65 #define QEI_INVINX_EN ((uint32_t)(1))
67 /* QEI timer reload option */
68 #define QEI_TIMERRELOAD_TICKVAL ((uint8_t)(0))
69 #define QEI_TIMERRELOAD_USVAL ((uint8_t)(1))
71 /* QEI Flag Status type */
72 #define QEI_STATUS_DIR ((uint32_t)(1<<0))
74 /* QEI Compare Position channel option */
75 #define QEI_COMPPOS_CH_0 ((uint8_t)(0))
76 #define QEI_COMPPOS_CH_1 ((uint8_t)(1))
77 #define QEI_COMPPOS_CH_2 ((uint8_t)(2))
79 /* QEI interrupt flag type */
80 #define QEI_INTFLAG_INX_Int ((uint32_t)(1<<0))
81 #define QEI_INTFLAG_TIM_Int ((uint32_t)(1<<1))
82 #define QEI_INTFLAG_VELC_Int ((uint32_t)(1<<2))
83 #define QEI_INTFLAG_DIR_Int ((uint32_t)(1<<3))
84 #define QEI_INTFLAG_ERR_Int ((uint32_t)(1<<4))
85 #define QEI_INTFLAG_ENCLK_Int ((uint32_t)(1<<5))
86 #define QEI_INTFLAG_POS0_Int ((uint32_t)(1<<6))
88 #define QEI_INTFLAG_POS1_Int ((uint32_t)(1<<7))
90 #define QEI_INTFLAG_POS2_Int ((uint32_t)(1<<8))
92 #define QEI_INTFLAG_REV_Int ((uint32_t)(1<<9))
94 #define QEI_INTFLAG_POS0REV_Int ((uint32_t)(1<<10))
95 #define QEI_INTFLAG_POS1REV_Int ((uint32_t)(1<<11))
96 #define QEI_INTFLAG_POS2REV_Int ((uint32_t)(1<<12))
103 /* Private Macros ------------------------------------------------------------- */
104 
108 /* --------------------- BIT DEFINITIONS -------------------------------------- */
109 /* Quadrature Encoder Interface Control Register Definition --------------------- */
110 /*********************************************************************/
113 #define QEI_CON_RESP ((uint32_t)(1<<0))
114 #define QEI_CON_RESPI ((uint32_t)(1<<1))
115 #define QEI_CON_RESV ((uint32_t)(1<<2))
116 #define QEI_CON_RESI ((uint32_t)(1<<3))
117 #define QEI_CON_BITMASK ((uint32_t)(0x0F))
119 /*********************************************************************/
122 #define QEI_CONF_DIRINV ((uint32_t)(1<<0))
123 #define QEI_CONF_SIGMODE ((uint32_t)(1<<1))
124 #define QEI_CONF_CAPMODE ((uint32_t)(1<<2))
125 #define QEI_CONF_INVINX ((uint32_t)(1<<3))
126 #define QEI_CONF_BITMASK ((uint32_t)(0x0F))
128 /*********************************************************************/
131 #define QEI_STAT_DIR ((uint32_t)(1<<0))
132 #define QEI_STAT_BITMASK ((uint32_t)(1<<0))
134 /* Quadrature Encoder Interface Interrupt registers definitions --------------------- */
135 /*********************************************************************/
138 #define QEI_INTSTAT_INX_Int ((uint32_t)(1<<0))
139 #define QEI_INTSTAT_TIM_Int ((uint32_t)(1<<1))
140 #define QEI_INTSTAT_VELC_Int ((uint32_t)(1<<2))
141 #define QEI_INTSTAT_DIR_Int ((uint32_t)(1<<3))
142 #define QEI_INTSTAT_ERR_Int ((uint32_t)(1<<4))
143 #define QEI_INTSTAT_ENCLK_Int ((uint32_t)(1<<5))
144 #define QEI_INTSTAT_POS0_Int ((uint32_t)(1<<6))
146 #define QEI_INTSTAT_POS1_Int ((uint32_t)(1<<7))
148 #define QEI_INTSTAT_POS2_Int ((uint32_t)(1<<8))
150 #define QEI_INTSTAT_REV_Int ((uint32_t)(1<<9))
152 #define QEI_INTSTAT_POS0REV_Int ((uint32_t)(1<<10))
154 #define QEI_INTSTAT_POS1REV_Int ((uint32_t)(1<<11))
156 #define QEI_INTSTAT_POS2REV_Int ((uint32_t)(1<<12))
158 #define QEI_INTSTAT_BITMASK ((uint32_t)(0x1FFF))
160 /*********************************************************************/
163 #define QEI_INTSET_INX_Int ((uint32_t)(1<<0))
164 #define QEI_INTSET_TIM_Int ((uint32_t)(1<<1))
165 #define QEI_INTSET_VELC_Int ((uint32_t)(1<<2))
166 #define QEI_INTSET_DIR_Int ((uint32_t)(1<<3))
167 #define QEI_INTSET_ERR_Int ((uint32_t)(1<<4))
168 #define QEI_INTSET_ENCLK_Int ((uint32_t)(1<<5))
169 #define QEI_INTSET_POS0_Int ((uint32_t)(1<<6))
171 #define QEI_INTSET_POS1_Int ((uint32_t)(1<<7))
173 #define QEI_INTSET_POS2_Int ((uint32_t)(1<<8))
175 #define QEI_INTSET_REV_Int ((uint32_t)(1<<9))
177 #define QEI_INTSET_POS0REV_Int ((uint32_t)(1<<10))
178 #define QEI_INTSET_POS1REV_Int ((uint32_t)(1<<11))
179 #define QEI_INTSET_POS2REV_Int ((uint32_t)(1<<12))
180 #define QEI_INTSET_BITMASK ((uint32_t)(0x1FFF))
182 /*********************************************************************/
185 #define QEI_INTCLR_INX_Int ((uint32_t)(1<<0))
186 #define QEI_INTCLR_TIM_Int ((uint32_t)(1<<1))
187 #define QEI_INTCLR_VELC_Int ((uint32_t)(1<<2))
188 #define QEI_INTCLR_DIR_Int ((uint32_t)(1<<3))
189 #define QEI_INTCLR_ERR_Int ((uint32_t)(1<<4))
190 #define QEI_INTCLR_ENCLK_Int ((uint32_t)(1<<5))
191 #define QEI_INTCLR_POS0_Int ((uint32_t)(1<<6))
193 #define QEI_INTCLR_POS1_Int ((uint32_t)(1<<7))
195 #define QEI_INTCLR_POS2_Int ((uint32_t)(1<<8))
197 #define QEI_INTCLR_REV_Int ((uint32_t)(1<<9))
199 #define QEI_INTCLR_POS0REV_Int ((uint32_t)(1<<10))
200 #define QEI_INTCLR_POS1REV_Int ((uint32_t)(1<<11))
201 #define QEI_INTCLR_POS2REV_Int ((uint32_t)(1<<12))
202 #define QEI_INTCLR_BITMASK ((uint32_t)(0x1FFF))
204 /*********************************************************************/
207 #define QEI_INTEN_INX_Int ((uint32_t)(1<<0))
208 #define QEI_INTEN_TIM_Int ((uint32_t)(1<<1))
209 #define QEI_INTEN_VELC_Int ((uint32_t)(1<<2))
210 #define QEI_INTEN_DIR_Int ((uint32_t)(1<<3))
211 #define QEI_INTEN_ERR_Int ((uint32_t)(1<<4))
212 #define QEI_INTEN_ENCLK_Int ((uint32_t)(1<<5))
213 #define QEI_INTEN_POS0_Int ((uint32_t)(1<<6))
215 #define QEI_INTEN_POS1_Int ((uint32_t)(1<<7))
217 #define QEI_INTEN_POS2_Int ((uint32_t)(1<<8))
219 #define QEI_INTEN_REV_Int ((uint32_t)(1<<9))
221 #define QEI_INTEN_POS0REV_Int ((uint32_t)(1<<10))
222 #define QEI_INTEN_POS1REV_Int ((uint32_t)(1<<11))
223 #define QEI_INTEN_POS2REV_Int ((uint32_t)(1<<12))
224 #define QEI_INTEN_BITMASK ((uint32_t)(0x1FFF))
226 /*********************************************************************/
229 #define QEI_IESET_INX_Int ((uint32_t)(1<<0))
230 #define QEI_IESET_TIM_Int ((uint32_t)(1<<1))
231 #define QEI_IESET_VELC_Int ((uint32_t)(1<<2))
232 #define QEI_IESET_DIR_Int ((uint32_t)(1<<3))
233 #define QEI_IESET_ERR_Int ((uint32_t)(1<<4))
234 #define QEI_IESET_ENCLK_Int ((uint32_t)(1<<5))
235 #define QEI_IESET_POS0_Int ((uint32_t)(1<<6))
237 #define QEI_IESET_POS1_Int ((uint32_t)(1<<7))
239 #define QEI_IESET_POS2_Int ((uint32_t)(1<<8))
241 #define QEI_IESET_REV_Int ((uint32_t)(1<<9))
243 #define QEI_IESET_POS0REV_Int ((uint32_t)(1<<10))
244 #define QEI_IESET_POS1REV_Int ((uint32_t)(1<<11))
245 #define QEI_IESET_POS2REV_Int ((uint32_t)(1<<12))
246 #define QEI_IESET_BITMASK ((uint32_t)(0x1FFF))
248 /*********************************************************************/
251 #define QEI_IECLR_INX_Int ((uint32_t)(1<<0))
252 #define QEI_IECLR_TIM_Int ((uint32_t)(1<<1))
253 #define QEI_IECLR_VELC_Int ((uint32_t)(1<<2))
254 #define QEI_IECLR_DIR_Int ((uint32_t)(1<<3))
255 #define QEI_IECLR_ERR_Int ((uint32_t)(1<<4))
256 #define QEI_IECLR_ENCLK_Int ((uint32_t)(1<<5))
257 #define QEI_IECLR_POS0_Int ((uint32_t)(1<<6))
259 #define QEI_IECLR_POS1_Int ((uint32_t)(1<<7))
261 #define QEI_IECLR_POS2_Int ((uint32_t)(1<<8))
263 #define QEI_IECLR_REV_Int ((uint32_t)(1<<9))
265 #define QEI_IECLR_POS0REV_Int ((uint32_t)(1<<10))
266 #define QEI_IECLR_POS1REV_Int ((uint32_t)(1<<11))
267 #define QEI_IECLR_POS2REV_Int ((uint32_t)(1<<12))
268 #define QEI_IECLR_BITMASK ((uint32_t)(0x1FFF))
271 /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
272 /* Macro check QEI peripheral */
273 #define PARAM_QEIx(n) ((n==LPC_QEI))
274 
275 /* Macro check QEI reset type */
276 #define PARAM_QEI_RESET(n) ((n==QEI_CON_RESP) \
277 || (n==QEI_RESET_POSOnIDX) \
278 || (n==QEI_RESET_VEL) \
279 || (n==QEI_RESET_IDX))
281 /* Macro check QEI Direction invert mode */
282 #define PARAM_QEI_DIRINV(n) ((n==QEI_DIRINV_NONE) || (n==QEI_DIRINV_CMPL))
284 /* Macro check QEI signal mode */
285 #define PARAM_QEI_SIGNALMODE(n) ((n==QEI_SIGNALMODE_QUAD) || (n==QEI_SIGNALMODE_CLKDIR))
286 
287 /* Macro check QEI Capture mode */
288 #define PARAM_QEI_CAPMODE(n) ((n==QEI_CAPMODE_2X) || (n==QEI_CAPMODE_4X))
289 
290 /* Macro check QEI Invert index mode */
291 #define PARAM_QEI_INVINX(n) ((n==QEI_INVINX_NONE) || (n==QEI_INVINX_EN))
292 
293 /* Macro check QEI Direction invert mode */
294 #define PARAM_QEI_TIMERRELOAD(n) ((n==QEI_TIMERRELOAD_TICKVAL) || (n==QEI_TIMERRELOAD_USVAL))
295 
296 /* Macro check QEI status type */
297 #define PARAM_QEI_STATUS(n) ((n==QEI_STATUS_DIR))
299 /* Macro check QEI combine position type */
300 #define PARAM_QEI_COMPPOS_CH(n) ((n==QEI_COMPPOS_CH_0) || (n==QEI_COMPPOS_CH_1) || (n==QEI_COMPPOS_CH_2))
301 
302 /* Macro check QEI interrupt flag type */
303 #define PARAM_QEI_INTFLAG(n) ((n==QEI_INTFLAG_INX_Int) \
304 || (n==QEI_INTFLAG_TIM_Int) \
305 || (n==QEI_INTFLAG_VELC_Int) \
306 || (n==QEI_INTFLAG_DIR_Int) \
307 || (n==QEI_INTFLAG_ERR_Int) \
308 || (n==QEI_INTFLAG_ENCLK_Int) \
309 || (n==QEI_INTFLAG_POS0_Int) \
310 || (n==QEI_INTFLAG_POS1_Int) \
311 || (n==QEI_INTFLAG_POS2_Int) \
312 || (n==QEI_INTFLAG_REV_Int) \
313 || (n==QEI_INTFLAG_POS0REV_Int) \
314 || (n==QEI_INTFLAG_POS1REV_Int) \
315 || (n==QEI_INTFLAG_POS2REV_Int))
320 /* Public Types --------------------------------------------------------------- */
328 typedef struct {
329  uint32_t DirectionInvert :1;
333  uint32_t SignalMode :1;
337  uint32_t CaptureMode :1;
341  uint32_t InvertIndex :1;
345 } QEI_CFG_Type;
346 
350 typedef struct {
351 
352  uint8_t ReloadOption;
356  uint8_t Reserved[3];
357  uint32_t ReloadValue;
361 
370 /* Public Functions ----------------------------------------------------------- */
375 void QEI_Reset(LPC_QEI_TypeDef *QEIx, uint32_t ulResetType);
376 void QEI_Init(LPC_QEI_TypeDef *QEIx, QEI_CFG_Type *QEI_ConfigStruct);
377 void QEI_ConfigStructInit(QEI_CFG_Type *QIE_InitStruct);
378 void QEI_DeInit(LPC_QEI_TypeDef *QEIx);
379 FlagStatus QEI_GetStatus(LPC_QEI_TypeDef *QEIx, uint32_t ulFlagType);
380 uint32_t QEI_GetPosition(LPC_QEI_TypeDef *QEIx);
381 void QEI_SetMaxPosition(LPC_QEI_TypeDef *QEIx, uint32_t ulMaxPos);
382 void QEI_SetPositionComp(LPC_QEI_TypeDef *QEIx, uint8_t bPosCompCh, uint32_t ulPosComp);
384 void QEI_SetIndexComp(LPC_QEI_TypeDef *QEIx, uint32_t ulIndexComp);
385 void QEI_SetTimerReload(LPC_QEI_TypeDef *QEIx, QEI_RELOADCFG_Type *QEIReloadStruct);
386 uint32_t QEI_GetTimer(LPC_QEI_TypeDef *QEIx);
389 void QEI_SetVelocityComp(LPC_QEI_TypeDef *QEIx, uint32_t ulVelComp);
390 void QEI_SetDigiFilter(LPC_QEI_TypeDef *QEIx, uint32_t ulSamplingPulse);
391 FlagStatus QEI_GetIntStatus(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType);
392 void QEI_IntCmd(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType, FunctionalState NewState);
393 void QEI_IntSet(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType);
394 void QEI_IntClear(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType);
395 uint32_t QEI_CalculateRPM(LPC_QEI_TypeDef *QEIx, uint32_t ulVelCapValue, uint32_t ulPPR);
396 
397 
402 #ifdef __cplusplus
403 }
404 #endif
405 
406 #endif /* LPC17XX_QEI_H_ */
407 
412 /* --------------------------------- End Of File ------------------------------ */