Esempio n. 1
0
void Encoder::_ssiInit(unsigned long bits, unsigned long clk, unsigned long wtime, bool gray2bin) {
  	_filterAndSampleWindowInit(mcn, mdn);
	
	mcsif_SetMode(mcn, mdn, MCSIF_SSI);

    if(clk == 0L) clk = 1000000L; // default value
    if(wtime == 0L) wtime = 20L; // default value
	if(bits > 32) bits = 32L; // default value
	
    clk = ((100000000L)/(clk))/2L; // = ((1/clk)x1000000x100)/2
    wtime = wtime * 100L;
    if(wtime <= clk) return;
    
	mcssi_SetClock(mcn, mdn, clk-1L);
	mcssi_SetWaitTime(mcn, mdn, wtime-1L);
	mcssi_SetLatchPhase(mcn, mdn, MCSSI_LATCH_PHASE0);
    mcssi_SetLatchTime(mcn, mdn, 0L);
	mcssi_SetNumberBITS(mcn, mdn, bits-1L);
	mcssi_SetCntMode(mcn, mdn, MCSSI_CONTINUE);

    if(gray2bin == true) mcssi_SetGAY2BINBit(mcn, mdn);
    
	io_DisableINT();
	_mcmode[mcn] = MODE_SSI;
	io_RestoreINT();
}
Esempio n. 2
0
void Encoder::_pabInit(int samplerate) {
  	_filterAndSampleWindowInit(mcn, mdn);
	
	mcsif_SetMode(mcn, mdn, MCSIF_ENC_PAB);
    
    _defaultEncoderSetting(mcn, mdn);
    
#if defined (DMP_DOS_BC) || (DMP_DOS_DJGPP)
    io_DisableINT();
#elif defined (DMP_LINUX)
	OSSPINLOCK(encvar);
#endif

    if(samplerate == 1)
    {
		mcenc_SetCntMode(mcn, mdn, MCENC_PAB_DIR0_INCA + MCENC_PAB_DIR1_DECA);
		_mcmode[mcn] = MODE_AB_PHASE;
	}
	else
	{
		mcenc_SetCntMode(mcn, mdn, MCENC_PAB_DIR0_INCAB + MCENC_PAB_DIR1_DECAB);
		_mcmode[mcn] = MODE_AB_PHASE_x2;
	}
	
#if defined (DMP_DOS_BC) || (DMP_DOS_DJGPP)
	io_RestoreINT();
#elif defined (DMP_LINUX)
	OSSPINUNLOCK(encvar);
#endif
}                                                   
Esempio n. 3
0
void Encoder::_cwccwInit(int samplerate) {
  	_filterAndSampleWindowInit(mcn, mdn);
	
	mcsif_SetMode(mcn, mdn, MCSIF_ENC_CWCCW);
    
    _defaultEncoderSetting(mcn, mdn);
    
#if defined (DMP_DOS_BC) || (DMP_DOS_DJGPP)
    io_DisableINT();
#elif defined (DMP_LINUX)
	OSSPINLOCK(encvar);
#endif

    if(samplerate == 1)
    {
    	mcenc_SetCntMode(mcn, mdn, MCENC_CWCCW_CW_INC0TO1 + MCENC_CWCCW_CCW_DEC0TO1);
		_mcmode[mcn] = MODE_CWCCW;
	}
    else
    {
    	mcenc_SetCntMode(mcn, mdn, MCENC_CWCCW_CW_INCBOTH + MCENC_CWCCW_CCW_DECBOTH);
    	_mcmode[mcn] = MODE_CWCCW_x2;
    }
	
#if defined (DMP_DOS_BC) || (DMP_DOS_DJGPP)
	io_RestoreINT();
#elif defined (DMP_LINUX)
	OSSPINUNLOCK(encvar);
#endif
}
Esempio n. 4
0
void Encoder::_pcapInit(void) {
	_filterAndSampleWindowInit(mcn, mdn);
	
	mcsif_SetMode(mcn, mdn, MCSIF_PFAU);
	
    mcpfau_SetCapMode1(mcn, mdn, MCPFAU_CAP_BOTH_CLEAR);
    mcpfau_SetCapInterval1(mcn, mdn, 1L);             
    mcpfau_SetCap1INT(mcn, mdn, 0L);
    mcpfau_SetPolarity1(mcn, mdn, MCPFAU_POL_NORMAL);
    mcpfau_SetMask1(mcn, mdn, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG1(mcn, mdn, MCPFAU_RLDTRIG_DISABLE);
    mcpfau_SetFAU1TRIG(mcn, mdn, MCPFAU_FAUTRIG_INPUT1);
    mcpfau_SetFAU1RELS(mcn, mdn, MCPFAU_FAURELS_INPUT0);
	
    mcpfau_SetCapMode2(mcn, mdn, MCPFAU_CAP_BOTH_CLEAR);     
    mcpfau_SetCapInterval2(mcn, mdn, 1L);
    mcpfau_SetCap2INT(mcn, mdn, 0L);
    mcpfau_SetPolarity2(mcn, mdn, MCPFAU_POL_NORMAL);
    mcpfau_SetMask2(mcn, mdn, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG2(mcn, mdn, MCPFAU_RLDTRIG_DISABLE);
    mcpfau_SetFAU2TRIG(mcn, mdn, MCPFAU_FAUTRIG_INPUT1);
    mcpfau_SetFAU2RELS(mcn, mdn, MCPFAU_FAURELS_INPUT0);

    mcpfau_SetCapMode3(mcn, mdn, MCPFAU_CAP_BOTH_CLEAR);
    mcpfau_SetCapInterval3(mcn, mdn, 1L);
    mcpfau_SetCap3INT(mcn, mdn, 0L);
    mcpfau_SetPolarity3(mcn, mdn, MCPFAU_POL_NORMAL);
    mcpfau_SetMask3(mcn, mdn, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG3(mcn, mdn, MCPFAU_RLDTRIG_DISABLE);          
	mcpfau_SetFAU3TRIG(mcn, mdn, MCPFAU_FAUTRIG_INPUT1);
	mcpfau_SetFAU3RELS(mcn, mdn, MCPFAU_FAURELS_INPUT0);
	
#if defined (DMP_DOS_BC) || (DMP_DOS_DJGPP)
    io_DisableINT();
#elif defined (DMP_LINUX)
	OSSPINLOCK(encvar);
#endif

	_mcmode[mcn] = MODE_CAPTURE;

#if defined (DMP_DOS_BC) || (DMP_DOS_DJGPP)
	io_RestoreINT();
#elif defined (DMP_LINUX)
	OSSPINUNLOCK(encvar);
#endif
}
Esempio n. 5
0
DMP_INLINE(void) mcmsif_init(int32_t mc)
{
    mcsif_SetInputFilter(mc, MCSIF_MODULEB, 20L);
    mcsif_SetSWDeadband(mc, MCSIF_MODULEB, 0L);
    mcsif_SetSWPOL(mc, MCSIF_MODULEB, MCSIF_SWPOL_REMAIN);
    mcsif_SetSamplWin(mc, MCSIF_MODULEB, MCSIF_SWSTART_DISABLE + MCSIF_SWEND_NOW);
    mcsif_SetSamplWin(mc, MCSIF_MODULEB, MCSIF_SWSTART_NOW + MCSIF_SWEND_DISABLE);

    mcsif_SetMode(mc, MCSIF_MODULEB, MCSIF_PFAU);               // enable MC2 SIFA

    mcpfau_SetCapMode1(mc, MCSIF_MODULEB, MCPFAU_CAP_DISABLE);
    mcpfau_SetCapInterval1(mc, MCSIF_MODULEB, 1L);              // pin1 for FAUTRIG
    mcpfau_SetCap1INT(mc, MCSIF_MODULEB, 1L);
    mcpfau_SetPolarity1(mc, MCSIF_MODULEB, MCPFAU_POL_NORMAL);
    mcpfau_SetMask1(mc, MCSIF_MODULEB, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG1(mc, MCSIF_MODULEB, MCPFAU_RLDTRIG_DISABLE);
    mcpfau_SetFAU1TRIG(mc, MCSIF_MODULEB, MCPFAU_FAUTRIG_INPUT1);
    mcpfau_SetFAU1RELS(mc, MCSIF_MODULEB, MCPFAU_FAURELS_INPUT0);

    mcpfau_SetCapMode2(mc, MCSIF_MODULEB, MCPFAU_CAP_DISABLE);     // pin2 for RLDTRIG
    mcpfau_SetCapInterval2(mc, MCSIF_MODULEB, 1L);
    mcpfau_SetCap2INT(mc, MCSIF_MODULEB, 1L);
    mcpfau_SetPolarity2(mc, MCSIF_MODULEB, MCPFAU_POL_NORMAL);
    mcpfau_SetMask2(mc, MCSIF_MODULEB, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG2(mc, MCSIF_MODULEB, MCPFAU_RLDTRIG_DISABLE);
    mcpfau_SetFAU2TRIG(mc, MCSIF_MODULEB, MCPFAU_FAUTRIG_INPUT1);
    mcpfau_SetFAU2RELS(mc, MCSIF_MODULEB, MCPFAU_FAURELS_INPUT0);

    mcpfau_SetCapMode3(mc, MCSIF_MODULEB, MCPFAU_CAP_DISABLE);
    mcpfau_SetCapInterval3(mc, MCSIF_MODULEB, 1L);              // pin3 for FAUTRIG
    mcpfau_SetCap3INT(mc, MCSIF_MODULEB, 1L);
    mcpfau_SetPolarity3(mc, MCSIF_MODULEB, MCPFAU_POL_NORMAL);
    mcpfau_SetMask3(mc, MCSIF_MODULEB, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG3(mc, MCSIF_MODULEB, MCPFAU_RLDTRIG_DISABLE);
    mcpfau_SetFAU3TRIG(mc, MCSIF_MODULEB, MCPFAU_FAUTRIG_INPUT1);
    mcpfau_SetFAU3RELS(mc, MCSIF_MODULEB, MCPFAU_FAURELS_INPUT0);
#if defined (DMP_DOS_DJGPP)
    io_DisableINT();
#endif
    mcm_init[mc] = true;
#if defined (DMP_DOS_DJGPP)
    io_RestoreINT();
#endif
}
Esempio n. 6
0
static void mcmsif_init(void) {
    if(mcm_init[mc] == true) return;
    
    mcsif_SetInputFilter(mc, md, 20L);
    mcsif_SetSWDeadband(mc, md, 0L);
    mcsif_SetSWPOL(mc, md, MCSIF_SWPOL_REMAIN);
    mcsif_SetSamplWin(mc, md, MCSIF_SWSTART_DISABLE + MCSIF_SWEND_NOW);  // stop the current sampling window first
    mcsif_SetSamplWin(mc, md, MCSIF_SWSTART_NOW + MCSIF_SWEND_DISABLE);

	mcsif_SetMode(mc, md, MCSIF_PFAU);               // enable MC2 SIFA
    
    mcpfau_SetCapMode1(mc, md, MCPFAU_CAP_DISABLE);
    mcpfau_SetCapInterval1(mc, md, 1L);              // pin1 for FAUTRIG
    mcpfau_SetCap1INT(mc, md, 1L);
    mcpfau_SetPolarity1(mc, md, MCPFAU_POL_NORMAL);
    mcpfau_SetMask1(mc, md, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG1(mc, md, MCPFAU_RLDTRIG_DISABLE);
    mcpfau_SetFAU1TRIG(mc, md, MCPFAU_FAUTRIG_INPUT1);
    mcpfau_SetFAU1RELS(mc, md, MCPFAU_FAURELS_INPUT0);
	
    mcpfau_SetCapMode2(mc, md, MCPFAU_CAP_DISABLE);     // pin2 for RLDTRIG
    mcpfau_SetCapInterval2(mc, md, 1L);
    mcpfau_SetCap2INT(mc, md, 1L);
    mcpfau_SetPolarity2(mc, md, MCPFAU_POL_NORMAL);
    mcpfau_SetMask2(mc, md, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG2(mc, md, MCPFAU_RLDTRIG_DISABLE);
    mcpfau_SetFAU2TRIG(mc, md, MCPFAU_FAUTRIG_INPUT1);
    mcpfau_SetFAU2RELS(mc, md, MCPFAU_FAURELS_INPUT0);

    mcpfau_SetCapMode3(mc, md, MCPFAU_CAP_DISABLE);
    mcpfau_SetCapInterval3(mc, md, 1L);              // pin3 for FAUTRIG 
    mcpfau_SetCap3INT(mc, md, 1L);
    mcpfau_SetPolarity3(mc, md, MCPFAU_POL_NORMAL);
    mcpfau_SetMask3(mc, md, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG3(mc, md, MCPFAU_RLDTRIG_DISABLE);          
	mcpfau_SetFAU3TRIG(mc, md, MCPFAU_FAUTRIG_INPUT1);
	mcpfau_SetFAU3RELS(mc, md, MCPFAU_FAURELS_INPUT0);
	
	io_DisableINT();
	mcm_init[mc] = true;
	io_RestoreINT();
}
Esempio n. 7
0
void Encoder::_pabInit(int samplerate) {
  	_filterAndSampleWindowInit(mcn, mdn);
	
	mcsif_SetMode(mcn, mdn, MCSIF_ENC_PAB);
    
    _defaultEncoderSetting(mcn, mdn);
    
    io_DisableINT();
    if(samplerate == 1)
    {
		mcenc_SetCntMode(mcn, mdn, MCENC_PAB_DIR0_INCA + MCENC_PAB_DIR1_DECA);
		_mcmode[mcn] = MODE_AB_PHASE;
	}
	else
	{
		mcenc_SetCntMode(mcn, mdn, MCENC_PAB_DIR0_INCAB + MCENC_PAB_DIR1_DECAB);
		_mcmode[mcn] = MODE_AB_PHASE_x2;
	}
	io_RestoreINT();
}                                                   
Esempio n. 8
0
void Encoder::_cwccwInit(int samplerate) {
  	_filterAndSampleWindowInit(mcn, mdn);
	
	mcsif_SetMode(mcn, mdn, MCSIF_ENC_CWCCW);
    
    _defaultEncoderSetting(mcn, mdn);
    
    io_DisableINT();
    if(samplerate == 1)
    {
    	mcenc_SetCntMode(mcn, mdn, MCENC_CWCCW_CW_INC0TO1 + MCENC_CWCCW_CCW_DEC0TO1);
		_mcmode[mcn] = MODE_CWCCW;
	}
    else
    {
    	mcenc_SetCntMode(mcn, mdn, MCENC_CWCCW_CW_INCBOTH + MCENC_CWCCW_CCW_DECBOTH);
    	_mcmode[mcn] = MODE_CWCCW_x2;
    }
	io_RestoreINT();
}
Esempio n. 9
0
void Encoder::_pdirInit(int samplerate) {
  	_filterAndSampleWindowInit(mcn, mdn);
	
	mcsif_SetMode(mcn, mdn, MCSIF_ENC_PDIR);
    
    _defaultEncoderSetting(mcn, mdn);
    
    io_DisableINT();
	if(samplerate == 1)
	{
    	mcenc_SetCntMode(mcn, mdn, MCENC_PDIR_DIR0_INC0TO1 + MCENC_PDIR_DIR1_DEC0TO1);
    	_mcmode[mcn] = MODE_STEP_DIR;
    }
    else
    {
    	mcenc_SetCntMode(mcn, mdn, MCENC_PDIR_DIR0_INCBOTH + MCENC_PDIR_DIR1_DECBOTH);
    	_mcmode[mcn] = MODE_STEP_DIR_x2;
    }
	io_RestoreINT();
}
Esempio n. 10
0
void Encoder::_pcapInit(void) {
	_filterAndSampleWindowInit(mcn, mdn);
	
	mcsif_SetMode(mcn, mdn, MCSIF_PFAU);
	
    mcpfau_SetCapMode1(mcn, mdn, MCPFAU_CAP_BOTH_CLEAR);
    mcpfau_SetCapInterval1(mcn, mdn, 1L);             
    mcpfau_SetCap1INT(mcn, mdn, 0L);
    mcpfau_SetPolarity1(mcn, mdn, MCPFAU_POL_NORMAL);
    mcpfau_SetMask1(mcn, mdn, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG1(mcn, mdn, MCPFAU_RLDTRIG_DISABLE);
    mcpfau_SetFAU1TRIG(mcn, mdn, MCPFAU_FAUTRIG_INPUT1);
    mcpfau_SetFAU1RELS(mcn, mdn, MCPFAU_FAURELS_INPUT0);
	
    mcpfau_SetCapMode2(mcn, mdn, MCPFAU_CAP_BOTH_CLEAR);     
    mcpfau_SetCapInterval2(mcn, mdn, 1L);
    mcpfau_SetCap2INT(mcn, mdn, 0L);
    mcpfau_SetPolarity2(mcn, mdn, MCPFAU_POL_NORMAL);
    mcpfau_SetMask2(mcn, mdn, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG2(mcn, mdn, MCPFAU_RLDTRIG_DISABLE);
    mcpfau_SetFAU2TRIG(mcn, mdn, MCPFAU_FAUTRIG_INPUT1);
    mcpfau_SetFAU2RELS(mcn, mdn, MCPFAU_FAURELS_INPUT0);

    mcpfau_SetCapMode3(mcn, mdn, MCPFAU_CAP_BOTH_CLEAR);
    mcpfau_SetCapInterval3(mcn, mdn, 1L);
    mcpfau_SetCap3INT(mcn, mdn, 0L);
    mcpfau_SetPolarity3(mcn, mdn, MCPFAU_POL_NORMAL);
    mcpfau_SetMask3(mcn, mdn, MCPFAU_MASK_NONE);
    mcpfau_SetRLDTRIG3(mcn, mdn, MCPFAU_RLDTRIG_DISABLE);          
	mcpfau_SetFAU3TRIG(mcn, mdn, MCPFAU_FAUTRIG_INPUT1);
	mcpfau_SetFAU3RELS(mcn, mdn, MCPFAU_FAURELS_INPUT0);
	
	io_DisableINT();
	_mcmode[mcn] = MODE_CAPTURE;
	io_RestoreINT();
}