void Encoder::setIndexReset(bool condition) { if(mode == MODE_NOSET || mode == MODE_CAPTURE || mode == MODE_SSI) return; mcsif_Disable(mcn, mdn); if(condition == true) { mcenc_SetResetMode(mcn, mdn, MCENC_RESET_INC_CNTMINIDX + MCENC_RESET_DEC_CNTMAXIDX); if(_setZPol == false) // if you use setInputPolarity() to set Z pin's pol to inverse before setIndexReset() { // In fact, below actions are same as mcenc_SetIdxCond(mcn, mdn, MCENC_PDIR_IDXCOND_Z, MCENC_ICZ1); if(mode == MODE_STEP_DIR || mode == MODE_STEP_DIR_x2) mcenc_SetIdxCond(mcn, mdn, MCENC_PDIR_IDXCOND_Z, MCENC_ICZ1); else if(mode == MODE_CWCCW || mode == MODE_CWCCW_x2) mcenc_SetIdxCond(mcn, mdn, MCENC_CWCCW_IDXCOND_Z, MCENC_ICZ1); else if(mode == MODE_AB_PHASE || mode == MODE_AB_PHASE_x2) mcenc_SetIdxCond(mcn, mdn, MCENC_PAB_IDXCOND_Z, MCENC_ICZ1); } io_DisableINT(); _encmode[mcn] |= INTR_INDEX; io_RestoreINT(); } else { mcenc_SetIdxCond(mcn, mdn, MCENC_PDIR_IDXCOND_DISABLE, 0L); mcenc_SetResetMode(mcn, mdn, MCENC_RESET_INC_CNTMIN + MCENC_RESET_DEC_CNTMAX); io_DisableINT(); _encmode[mcn] &= ~(INTR_INDEX); io_RestoreINT(); } mcsif_Enable(mcn, mdn); }
static void _defaultEncoderSetting(int mc, int md) { mcenc_SetIdxCond(mc, md, MCENC_PDIR_IDXCOND_DISABLE, 0L); mcenc_SetCapMode(mc, md, MCENC_CAP_PCNT_DISABLE + MCENC_CAP_EXTRIG_DISABLE + MCENC_CAP_IDXCOND_DISABLE); mcenc_SetCntMin(mc, md, 0L); mcenc_SetCntMax(mc, md, 0xffffffffL); mcenc_SetResetMode(mc, md, MCENC_RESET_INC_CNTMIN + MCENC_RESET_DEC_CNTMAX); mcenc_SetTrigResetMode(mc, md, MCENC_TRIGRESET_IDXCOND_0TO1); mcenc_SetPulCnt(mc, md, 0L); }
void Encoder::setIndexReset(bool condition) { if(mode == MODE_NOSET || mode == MODE_CAPTURE || mode == MODE_SSI) return; mcsif_Disable(mcn, mdn); if(condition == true) { mcenc_SetResetMode(mcn, mdn, MCENC_RESET_INC_CNTMINIDX + MCENC_RESET_DEC_CNTMAXIDX); mcenc_SetCapMode(mcn, mdn, MCENC_CAP_PCNT_DISABLE + MCENC_CAP_EXTRIG_DISABLE + MCENC_CAP_IDXCOND_ENABLE); // start to use FIFO (mean that capture event will occur) if(_setZPol == false) // if you use setInputPolarity() to set Z pin's pol to inverse before setIndexReset() { // In fact, below actions are same as mcenc_SetIdxCond(mcn, mdn, MCENC_PDIR_IDXCOND_Z, MCENC_ICZ1); if(mode == MODE_STEP_DIR || mode == MODE_STEP_DIR_x2) mcenc_SetIdxCond(mcn, mdn, MCENC_PDIR_IDXCOND_Z, MCENC_ICZ1); else if(mode == MODE_CWCCW || mode == MODE_CWCCW_x2) mcenc_SetIdxCond(mcn, mdn, MCENC_CWCCW_IDXCOND_Z, MCENC_ICZ1); else if(mode == MODE_AB_PHASE || mode == MODE_AB_PHASE_x2) mcenc_SetIdxCond(mcn, mdn, MCENC_PAB_IDXCOND_Z, MCENC_ICZ1); } io_DisableINT(); _encmode[mcn] |= INTR_INDEX; io_RestoreINT(); } else { if((_encmode[mcn] & (INTR_INDEX | INTR_OVERFLOW | INTR_UNDERFLOW)) == 0) mcenc_SetCapMode(mcn, mdn, MCENC_CAP_PCNT_DISABLE + MCENC_CAP_EXTRIG_DISABLE + MCENC_CAP_IDXCOND_DISABLE); mcenc_SetIdxCond(mcn, mdn, MCENC_PDIR_IDXCOND_DISABLE, 0L); mcenc_SetResetMode(mcn, mdn, MCENC_RESET_INC_CNTMIN + MCENC_RESET_DEC_CNTMAX); io_DisableINT(); _encmode[mcn] &= ~(INTR_INDEX); io_RestoreINT(); } mcsif_Enable(mcn, mdn); }