C:/nxpdrv/LPC1700CMSIS/Drivers/include/lpc17xx_qei.h
Go to the documentation of this file.00001 /***********************************************************************/ 00021 /* Peripheral group ----------------------------------------------------------- */ 00027 #ifndef LPC17XX_QEI_H_ 00028 #define LPC17XX_QEI_H_ 00029 00030 /* Includes ------------------------------------------------------------------- */ 00031 #include "LPC17xx.h" 00032 #include "lpc_types.h" 00033 00034 00035 #ifdef __cplusplus 00036 extern "C" 00037 { 00038 #endif 00039 00040 00041 /* Private Macros ------------------------------------------------------------- */ 00050 /* Quadrature Encoder Interface Control Register Definition --------------------- */ 00051 /* QEI Control register */ 00052 #define QEI_CON_RESP ((uint32_t)(1<<0)) 00053 #define QEI_CON_RESPI ((uint32_t)(1<<1)) 00054 #define QEI_CON_RESV ((uint32_t)(1<<2)) 00055 #define QEI_CON_RESI ((uint32_t)(1<<3)) 00056 #define QEI_CON_BITMASK ((uint32_t)(0x0F)) 00058 /* QEI Configuration register */ 00059 #define QEI_CONF_DIRINV ((uint32_t)(1<<0)) 00060 #define QEI_CONF_SIGMODE ((uint32_t)(1<<1)) 00061 #define QEI_CONF_CAPMODE ((uint32_t)(1<<2)) 00062 #define QEI_CONF_INVINX ((uint32_t)(1<<3)) 00063 #define QEI_CONF_BITMASK ((uint32_t)(0x0F)) 00065 /* QEI Status register */ 00066 #define QEI_STAT_DIR ((uint32_t)(1<<0)) 00067 #define QEI_STAT_BITMASK ((uint32_t)(1<<0)) 00069 /* Quadrature Encoder Interface Position, index and timer Register Definitions --- */ 00070 /* QEI Position register */ 00071 00072 /* QEI Maximum Position register */ 00073 00074 /* QEI Position Compare register 0 */ 00075 00076 /* QEI Position Compare register 1 */ 00077 00078 /* QEI Position Compare register 2 */ 00079 00080 /* QEI Index Count register */ 00081 00082 /* QEI Index Compare register */ 00083 00084 /* QEI Timer Reload register */ 00085 00086 /* QEI Timer register */ 00087 00088 /* QEI Velocity register */ 00089 00090 /* QEI Velocity Capture register */ 00091 00092 /* QEI Velocity Compare register */ 00093 00094 /* QEI Digital Filter register */ 00095 00096 /* Quadrature Encoder Interface Interrupt registers definitions --------------------- */ 00097 /* QEI Interrupt Status register */ 00098 #define QEI_INTSTAT_INX_Int ((uint32_t)(1<<0)) 00099 #define QEI_INTSTAT_TIM_Int ((uint32_t)(1<<1)) 00100 #define QEI_INTSTAT_VELC_Int ((uint32_t)(1<<2)) 00101 #define QEI_INTSTAT_DIR_Int ((uint32_t)(1<<3)) 00102 #define QEI_INTSTAT_ERR_Int ((uint32_t)(1<<4)) 00103 #define QEI_INTSTAT_ENCLK_Int ((uint32_t)(1<<5)) 00104 #define QEI_INTSTAT_POS0_Int ((uint32_t)(1<<6)) 00106 #define QEI_INTSTAT_POS1_Int ((uint32_t)(1<<7)) 00108 #define QEI_INTSTAT_POS2_Int ((uint32_t)(1<<8)) 00110 #define QEI_INTSTAT_REV_Int ((uint32_t)(1<<9)) 00112 #define QEI_INTSTAT_POS0REV_Int ((uint32_t)(1<<10)) 00114 #define QEI_INTSTAT_POS1REV_Int ((uint32_t)(1<<11)) 00116 #define QEI_INTSTAT_POS2REV_Int ((uint32_t)(1<<12)) 00118 #define QEI_INTSTAT_BITMASK ((uint32_t)(0x1FFF)) 00120 /* QEI Interrupt Set register */ 00121 #define QEI_INTSET_INX_Int ((uint32_t)(1<<0)) 00122 #define QEI_INTSET_TIM_Int ((uint32_t)(1<<1)) 00123 #define QEI_INTSET_VELC_Int ((uint32_t)(1<<2)) 00124 #define QEI_INTSET_DIR_Int ((uint32_t)(1<<3)) 00125 #define QEI_INTSET_ERR_Int ((uint32_t)(1<<4)) 00126 #define QEI_INTSET_ENCLK_Int ((uint32_t)(1<<5)) 00127 #define QEI_INTSET_POS0_Int ((uint32_t)(1<<6)) 00129 #define QEI_INTSET_POS1_Int ((uint32_t)(1<<7)) 00131 #define QEI_INTSET_POS2_Int ((uint32_t)(1<<8)) 00133 #define QEI_INTSET_REV_Int ((uint32_t)(1<<9)) 00135 #define QEI_INTSET_POS0REV_Int ((uint32_t)(1<<10)) 00136 #define QEI_INTSET_POS1REV_Int ((uint32_t)(1<<11)) 00137 #define QEI_INTSET_POS2REV_Int ((uint32_t)(1<<12)) 00138 #define QEI_INTSET_BITMASK ((uint32_t)(0x1FFF)) 00140 /* QEI Interrupt Clear register */ 00141 #define QEI_INTCLR_INX_Int ((uint32_t)(1<<0)) 00142 #define QEI_INTCLR_TIM_Int ((uint32_t)(1<<1)) 00143 #define QEI_INTCLR_VELC_Int ((uint32_t)(1<<2)) 00144 #define QEI_INTCLR_DIR_Int ((uint32_t)(1<<3)) 00145 #define QEI_INTCLR_ERR_Int ((uint32_t)(1<<4)) 00146 #define QEI_INTCLR_ENCLK_Int ((uint32_t)(1<<5)) 00147 #define QEI_INTCLR_POS0_Int ((uint32_t)(1<<6)) 00149 #define QEI_INTCLR_POS1_Int ((uint32_t)(1<<7)) 00151 #define QEI_INTCLR_POS2_Int ((uint32_t)(1<<8)) 00153 #define QEI_INTCLR_REV_Int ((uint32_t)(1<<9)) 00155 #define QEI_INTCLR_POS0REV_Int ((uint32_t)(1<<10)) 00156 #define QEI_INTCLR_POS1REV_Int ((uint32_t)(1<<11)) 00157 #define QEI_INTCLR_POS2REV_Int ((uint32_t)(1<<12)) 00158 #define QEI_INTCLR_BITMASK ((uint32_t)(0x1FFF)) 00160 /* QEI Interrupt Enable register */ 00161 #define QEI_INTEN_INX_Int ((uint32_t)(1<<0)) 00162 #define QEI_INTEN_TIM_Int ((uint32_t)(1<<1)) 00163 #define QEI_INTEN_VELC_Int ((uint32_t)(1<<2)) 00164 #define QEI_INTEN_DIR_Int ((uint32_t)(1<<3)) 00165 #define QEI_INTEN_ERR_Int ((uint32_t)(1<<4)) 00166 #define QEI_INTEN_ENCLK_Int ((uint32_t)(1<<5)) 00167 #define QEI_INTEN_POS0_Int ((uint32_t)(1<<6)) 00169 #define QEI_INTEN_POS1_Int ((uint32_t)(1<<7)) 00171 #define QEI_INTEN_POS2_Int ((uint32_t)(1<<8)) 00173 #define QEI_INTEN_REV_Int ((uint32_t)(1<<9)) 00175 #define QEI_INTEN_POS0REV_Int ((uint32_t)(1<<10)) 00176 #define QEI_INTEN_POS1REV_Int ((uint32_t)(1<<11)) 00177 #define QEI_INTEN_POS2REV_Int ((uint32_t)(1<<12)) 00178 #define QEI_INTEN_BITMASK ((uint32_t)(0x1FFF)) 00180 /* QEI Interrupt Enable Set register */ 00181 #define QEI_IESET_INX_Int ((uint32_t)(1<<0)) 00182 #define QEI_IESET_TIM_Int ((uint32_t)(1<<1)) 00183 #define QEI_IESET_VELC_Int ((uint32_t)(1<<2)) 00184 #define QEI_IESET_DIR_Int ((uint32_t)(1<<3)) 00185 #define QEI_IESET_ERR_Int ((uint32_t)(1<<4)) 00186 #define QEI_IESET_ENCLK_Int ((uint32_t)(1<<5)) 00187 #define QEI_IESET_POS0_Int ((uint32_t)(1<<6)) 00189 #define QEI_IESET_POS1_Int ((uint32_t)(1<<7)) 00191 #define QEI_IESET_POS2_Int ((uint32_t)(1<<8)) 00193 #define QEI_IESET_REV_Int ((uint32_t)(1<<9)) 00195 #define QEI_IESET_POS0REV_Int ((uint32_t)(1<<10)) 00196 #define QEI_IESET_POS1REV_Int ((uint32_t)(1<<11)) 00197 #define QEI_IESET_POS2REV_Int ((uint32_t)(1<<12)) 00198 #define QEI_IESET_BITMASK ((uint32_t)(0x1FFF)) 00200 /* QEI Interrupt Enable Clear register */ 00201 #define QEI_IECLR_INX_Int ((uint32_t)(1<<0)) 00202 #define QEI_IECLR_TIM_Int ((uint32_t)(1<<1)) 00203 #define QEI_IECLR_VELC_Int ((uint32_t)(1<<2)) 00204 #define QEI_IECLR_DIR_Int ((uint32_t)(1<<3)) 00205 #define QEI_IECLR_ERR_Int ((uint32_t)(1<<4)) 00206 #define QEI_IECLR_ENCLK_Int ((uint32_t)(1<<5)) 00207 #define QEI_IECLR_POS0_Int ((uint32_t)(1<<6)) 00209 #define QEI_IECLR_POS1_Int ((uint32_t)(1<<7)) 00211 #define QEI_IECLR_POS2_Int ((uint32_t)(1<<8)) 00213 #define QEI_IECLR_REV_Int ((uint32_t)(1<<9)) 00215 #define QEI_IECLR_POS0REV_Int ((uint32_t)(1<<10)) 00216 #define QEI_IECLR_POS1REV_Int ((uint32_t)(1<<11)) 00217 #define QEI_IECLR_POS2REV_Int ((uint32_t)(1<<12)) 00218 #define QEI_IECLR_BITMASK ((uint32_t)(0x1FFF)) 00230 /* Public Types --------------------------------------------------------------- */ 00231 00238 typedef struct { 00239 uint32_t DirectionInvert :1; 00243 uint32_t SignalMode :1; 00247 uint32_t CaptureMode :1; 00251 uint32_t InvertIndex :1; 00255 } QEI_CFG_Type; 00256 00260 typedef struct { 00261 00262 uint8_t ReloadOption; 00266 uint8_t Reserved[3]; 00267 uint32_t ReloadValue; 00270 } QEI_RELOADCFG_Type; 00271 00277 /* Public Macros -------------------------------------------------------------- */ 00282 #define PARAM_QEIx(n) ((n==LPC_QEI)) 00283 00284 /* QEI Reset types */ 00285 #define QEI_RESET_POS QEI_CON_RESP 00286 #define QEI_RESET_POSOnIDX QEI_CON_RESPI 00287 #define QEI_RESET_VEL QEI_CON_RESV 00288 #define QEI_RESET_IDX QEI_CON_RESI 00290 #define PARAM_QEI_RESET(n) ((n==QEI_CON_RESP) \ 00291 || (n==QEI_RESET_POSOnIDX) \ 00292 || (n==QEI_RESET_VEL) \ 00293 || (n==QEI_RESET_IDX)) 00294 00295 /* QEI Direction Invert Type Option */ 00296 #define QEI_DIRINV_NONE ((uint32_t)(0)) 00297 #define QEI_DIRINV_CMPL ((uint32_t)(1)) 00299 #define PARAM_QEI_DIRINV(n) ((n==QEI_DIRINV_NONE) || (n==QEI_DIRINV_CMPL)) 00300 00301 /* QEI Signal Mode Option */ 00302 #define QEI_SIGNALMODE_QUAD ((uint32_t)(0)) 00303 #define QEI_SIGNALMODE_CLKDIR ((uint32_t)(1)) 00305 #define PARAM_QEI_SIGNALMODE(n) ((n==QEI_SIGNALMODE_QUAD) || (n==QEI_SIGNALMODE_CLKDIR)) 00306 00307 /* QEI Capture Mode Option */ 00308 #define QEI_CAPMODE_2X ((uint32_t)(0)) 00309 #define QEI_CAPMODE_4X ((uint32_t)(1)) 00311 #define PARAM_QEI_CAPMODE(n) ((n==QEI_CAPMODE_2X) || (n==QEI_CAPMODE_4X)) 00312 00313 /* QEI Invert Index Signal Option */ 00314 #define QEI_INVINX_NONE ((uint32_t)(0)) 00315 #define QEI_INVINX_EN ((uint32_t)(1)) 00317 #define PARAM_QEI_INVINX(n) ((n==QEI_INVINX_NONE) || (n==QEI_INVINX_EN)) 00318 00319 /* QEI timer reload option */ 00320 #define QEI_TIMERRELOAD_TICKVAL ((uint8_t)(0)) 00321 #define QEI_TIMERRELOAD_USVAL ((uint8_t)(1)) 00322 #define PARAM_QEI_TIMERRELOAD(n) ((n==QEI_TIMERRELOAD_TICKVAL) || (n==QEI_TIMERRELOAD_USVAL)) 00323 00324 /* QEI Flag Status type */ 00325 #define QEI_STATUS_DIR ((uint32_t)(1<<0)) 00326 #define PARAM_QEI_STATUS(n) ((n==QEI_STATUS_DIR)) 00327 00328 /* QEI Compare Position channel option */ 00329 #define QEI_COMPPOS_CH_0 ((uint8_t)(0)) 00330 #define QEI_COMPPOS_CH_1 ((uint8_t)(1)) 00331 #define QEI_COMPPOS_CH_2 ((uint8_t)(2)) 00332 #define PARAM_QEI_COMPPOS_CH(n) ((n==QEI_COMPPOS_CH_0) || (n==QEI_COMPPOS_CH_1) || (n==QEI_COMPPOS_CH_2)) 00333 00334 /* QEI interrupt flag type */ 00335 #define QEI_INTFLAG_INX_Int ((uint32_t)(1<<0)) 00336 #define QEI_INTFLAG_TIM_Int ((uint32_t)(1<<1)) 00337 #define QEI_INTFLAG_VELC_Int ((uint32_t)(1<<2)) 00338 #define QEI_INTFLAG_DIR_Int ((uint32_t)(1<<3)) 00339 #define QEI_INTFLAG_ERR_Int ((uint32_t)(1<<4)) 00340 #define QEI_INTFLAG_ENCLK_Int ((uint32_t)(1<<5)) 00341 #define QEI_INTFLAG_POS0_Int ((uint32_t)(1<<6)) 00343 #define QEI_INTFLAG_POS1_Int ((uint32_t)(1<<7)) 00345 #define QEI_INTFLAG_POS2_Int ((uint32_t)(1<<8)) 00347 #define QEI_INTFLAG_REV_Int ((uint32_t)(1<<9)) 00349 #define QEI_INTFLAG_POS0REV_Int ((uint32_t)(1<<10)) 00350 #define QEI_INTFLAG_POS1REV_Int ((uint32_t)(1<<11)) 00351 #define QEI_INTFLAG_POS2REV_Int ((uint32_t)(1<<12)) 00353 #define PARAM_QEI_INTFLAG(n) ((n==QEI_INTFLAG_INX_Int) \ 00354 || (n==QEI_INTFLAG_TIM_Int) \ 00355 || (n==QEI_INTFLAG_VELC_Int) \ 00356 || (n==QEI_INTFLAG_DIR_Int) \ 00357 || (n==QEI_INTFLAG_ERR_Int) \ 00358 || (n==QEI_INTFLAG_ENCLK_Int) \ 00359 || (n==QEI_INTFLAG_POS0_Int) \ 00360 || (n==QEI_INTFLAG_POS1_Int) \ 00361 || (n==QEI_INTFLAG_POS2_Int) \ 00362 || (n==QEI_INTFLAG_REV_Int) \ 00363 || (n==QEI_INTFLAG_POS0REV_Int) \ 00364 || (n==QEI_INTFLAG_POS1REV_Int) \ 00365 || (n==QEI_INTFLAG_POS2REV_Int)) 00366 00372 /* Public Functions ----------------------------------------------------------- */ 00377 void QEI_Reset(LPC_QEI_TypeDef *QEIx, uint32_t ulResetType); 00378 void QEI_Init(LPC_QEI_TypeDef *QEIx, QEI_CFG_Type *QEI_ConfigStruct); 00379 void QEI_ConfigStructInit(QEI_CFG_Type *QIE_InitStruct); 00380 void QEI_DeInit(LPC_QEI_TypeDef *QEIx); 00381 FlagStatus QEI_GetStatus(LPC_QEI_TypeDef *QEIx, uint32_t ulFlagType); 00382 uint32_t QEI_GetPosition(LPC_QEI_TypeDef *QEIx); 00383 void QEI_SetMaxPosition(LPC_QEI_TypeDef *QEIx, uint32_t ulMaxPos); 00384 void QEI_SetPositionComp(LPC_QEI_TypeDef *QEIx, uint8_t bPosCompCh, uint32_t ulPosComp); 00385 uint32_t QEI_GetIndex(LPC_QEI_TypeDef *QEIx); 00386 void QEI_SetIndexComp(LPC_QEI_TypeDef *QEIx, uint32_t ulIndexComp); 00387 void QEI_SetTimerReload(LPC_QEI_TypeDef *QEIx, QEI_RELOADCFG_Type *QEIReloadStruct); 00388 uint32_t QEI_GetTimer(LPC_QEI_TypeDef *QEIx); 00389 uint32_t QEI_GetVelocity(LPC_QEI_TypeDef *QEIx); 00390 uint32_t QEI_GetVelocityCap(LPC_QEI_TypeDef *QEIx); 00391 void QEI_SetVelocityComp(LPC_QEI_TypeDef *QEIx, uint32_t ulVelComp); 00392 void QEI_SetDigiFilter(LPC_QEI_TypeDef *QEIx, uint32_t ulSamplingPulse); 00393 FlagStatus QEI_GetIntStatus(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType); 00394 void QEI_IntCmd(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType, FunctionalState NewState); 00395 void QEI_IntSet(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType); 00396 void QEI_IntClear(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType); 00397 uint32_t QEI_CalculateRPM(LPC_QEI_TypeDef *QEIx, uint32_t ulVelCapValue, uint32_t ulPPR); 00398 00399 00404 #ifdef __cplusplus 00405 } 00406 #endif 00407 00408 #endif /* LPC17XX_QEI_H_ */ 00409 00414 /* --------------------------------- End Of File ------------------------------ */
Generated on Mon Feb 8 10:01:37 2010 for LPC1700CMSIS Standard Peripheral Firmware Library by
