コード例 #1
0
void _EncoderInit(){
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
	SysCtlDelay(1);

	HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTD_BASE + GPIO_O_CR) |= 0x80;

	//Set Pins to be PHA0 and PHB0
	GPIOPinConfigure(GPIO_PD6_PHA0);
	GPIOPinConfigure(GPIO_PD7_PHB0);

	GPIOPinTypeQEI(GPIO_PORTD_BASE, GPIO_PIN_6 |  GPIO_PIN_7);


	QEIDisable(QEI0_BASE);
	QEIIntDisable(QEI0_BASE,QEI_INTERROR | QEI_INTDIR | QEI_INTTIMER | QEI_INTINDEX);

	QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B  | QEI_CONFIG_NO_RESET 	| QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 1000);
	QEIVelocityConfigure(QEI0_BASE,	QEI_VELDIV_1,80000000/12);
	QEIEnable(QEI0_BASE);
	QEIVelocityEnable(QEI0_BASE);
	//Set position to a middle value so we can see if things are working
	QEIPositionSet(QEI0_BASE, 500);


	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
	SysCtlDelay(1);

	//Set Pins to be PHA0 and PHB0
	GPIOPinConfigure(GPIO_PC5_PHA1);
	GPIOPinConfigure(GPIO_PC6_PHB1);

	GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5 |  GPIO_PIN_6);


	QEIDisable(QEI1_BASE);
	QEIIntDisable(QEI1_BASE,QEI_INTERROR | QEI_INTDIR | QEI_INTTIMER | QEI_INTINDEX);

	QEIConfigure(QEI1_BASE, (QEI_CONFIG_CAPTURE_A_B  | QEI_CONFIG_NO_RESET 	| QEI_CONFIG_QUADRATURE | QEI_CONFIG_SWAP), 1000);
	QEIVelocityConfigure(QEI1_BASE,	QEI_VELDIV_1,80000000/12);
	QEIEnable(QEI1_BASE);
	QEIVelocityEnable(QEI1_BASE);
	//Set position to a middle value so we can see if things are working
	QEIPositionSet(QEI1_BASE, 500);
}
コード例 #2
0
ファイル: qei.c プロジェクト: francisvalois/design3
void initQEI(void){
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); //PhA sur C4 et PhB sur C6
	SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //PhA sur E3 et PhB sur E2
	SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
	
	//init QEI0 du micro pour moteur 0
    GPIOPinConfigure(GPIO_PC4_PHA0);
    GPIOPinConfigure(GPIO_PC6_PHB0);
	GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_4);  //Ph A
    GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_6);  //Ph B
    QEIDisable(QEI0_BASE);
	QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET|
	QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 1000000); //64 counts par révolution de moteur avec un ratio 100:1 
	QEIEnable(QEI0_BASE);
	QEIPositionSet(QEI0_BASE,0);
	QEIVelocityDisable(QEI0_BASE);
	QEIVelocityConfigure (QEI0_BASE, QEI_VELDIV_1, ROM_SysCtlClockGet()*dt);
	QEIVelocityEnable(QEI0_BASE);
	
	//init QEI1 du micro pour moteur 1
    GPIOPinConfigure(GPIO_PE3_PHA1);
    GPIOPinConfigure(GPIO_PE2_PHB1);
	GPIOPinTypeQEI(GPIO_PORTE_BASE, GPIO_PIN_3);  //Ph A
    GPIOPinTypeQEI(GPIO_PORTE_BASE, GPIO_PIN_2);  //Ph B
    QEIDisable(QEI1_BASE);
	QEIConfigure(QEI1_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET|
	QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 1000000); //64 counts par révolution de moteur avec un ratio 100:1 
	QEIEnable(QEI1_BASE);
	QEIPositionSet(QEI1_BASE,0);
	QEIVelocityDisable(QEI1_BASE);
	QEIVelocityConfigure (QEI1_BASE, QEI_VELDIV_1, ROM_SysCtlClockGet()*dt);
	QEIVelocityEnable(QEI1_BASE);
	
	//init decodeur fait a la mitaine pour moteur 2 et 3 (pins J4 et J5 pour moteur 2, J6 et J7 pour moteur 3)
	GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_6 | GPIO_PIN_7, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPD);
	GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_6 | GPIO_PIN_7);
	GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_6 | GPIO_PIN_7, GPIO_BOTH_EDGES);
	GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_6 | GPIO_PIN_7);
	IntEnable(INT_GPIOE);
	
	position_m0 = 0;
	position_m1 = 0;
	position_m2 = 0;
	position_m3 = 0;
}
コード例 #3
0
//*****************************************************************************
//
// Initializes the speed sensing routines.
//
// This function will initialize the peripherals used determine the speed of
// the motor's rotor.
//
// \return None.
//
//*****************************************************************************
void
SpeedSenseInit(void)
{
    //
    // Configure the encoder A pin for use by the QEI block.  Even though this
    // pin is now used to drive the QEI block, its state is still visible to
    // the GPIO block.
    // Encoder B and Index pins are not used, but should be configured here,
    // for test support.
    //
    GPIOPinTypeQEI(PIN_ENCA_PORT, PIN_ENCA_PIN);
    GPIOPinTypeQEI(PIN_ENCB_PORT, PIN_ENCB_PIN);
    GPIOPinTypeQEI(PIN_INDEX_PORT, PIN_INDEX_PIN);

    //
    // A GPIO interrupt should be generated on rising edges of the encoder A
    // pin.
    //
    GPIOIntTypeSet(PIN_ENCA_PORT, PIN_ENCA_PIN, GPIO_RISING_EDGE);

    //
    // Enable the encoder A pin GPIO interrupt.
    //
    GPIOPinIntEnable(PIN_ENCA_PORT, PIN_ENCA_PIN);
    IntEnable(INT_GPIOC);

    //
    // Configure the QEI block for capturing the velocity of the encoder A pin
    // (which it does by counting the number of edges during a fixed time
    // period).
    //
    QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A | QEI_CONFIG_NO_RESET |
                             QEI_CONFIG_CLOCK_DIR | QEI_CONFIG_NO_SWAP), 0);
    QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, SYSTEM_CLOCK / QEI_INT_RATE);

    //
    // Enable the QEI block and the velocity capture.
    //
    QEIEnable(QEI0_BASE);
    QEIVelocityEnable(QEI0_BASE);

    //
    // Enable the QEI velocity interrupt.
    //
    QEIIntEnable(QEI0_BASE, QEI_INTTIMER);
    IntEnable(INT_QEI0);
}
コード例 #4
0
void qeiInit(void) {
	SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;
	GPIOPinTypeQEI(GPIO_PORTF_BASE, GPIO_PIN_0);
	GPIOPinTypeQEI(GPIO_PORTF_BASE, GPIO_PIN_1);
	GPIOPinConfigure(GPIO_PF0_PHA0);
	GPIOPinConfigure(GPIO_PF1_PHB0);
	QEIConfigure(QEI0_BASE,QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_RESET | QEI_CONFIG_NO_SWAP,3999);
	QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, SysCtlClockGet()/QEIfrequency);
	QEIVelocityEnable(QEI0_BASE);
    QEIIntEnable(QEI0_BASE, QEI_INTTIMER);
    IntEnable(INT_QEI0);
    QEIEnable(QEI0_BASE);
}
コード例 #5
0
ファイル: encoder.c プロジェクト: EranSegal/ek-lm4f230H5QR
//*****************************************************************************
//
// This function prepares the quadrature encoder module for capturing the
// position and speed of the motor.
//
//*****************************************************************************
void
Encoder_Init(unsigned long ulBase)
{

	if(ulBase == QEI0_BASE) // J6 PITCH Encoder 
	{
		//
		// Enable the peripherals QEI example.
		//	
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
		SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0); 
	
	    // unlock GPIO PD7
	    GPIO_PORTD_LOCK_R = GPIO_LOCK_KEY;
		GPIO_PORTD_CR_R = GPIO_PIN_7;

		//Enable GPIO for QEI0
		//PD3-> IDX0 				
		//PD6-> PHA0
		//PD7-> PHB0 
		GPIOPinConfigure(GPIO_PD3_IDX0);		
		GPIOPinConfigure(GPIO_PD6_PHA0);	
		GPIOPinConfigure(GPIO_PD7_PHB0);

		GPIOPinTypeQEI(QEI_PITCH_PHA_PORT,QEI_PITCH_PHA_PIN); 
		GPIOPinTypeQEI(QEI_PITCH_PHB_PORT,QEI_PITCH_PHB_PIN);
		GPIOPinTypeQEI(QEI_PITCH_INDEX_PORT,QEI_PITCH_INDEX_PIN);
		
		
		// Set D 0 and 1 to alternative use 
		GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_DIR_MODE_HW);//GPIO_DIR_MODE_HW	
		GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_DIR_MODE_HW); 
		GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_7, GPIO_DIR_MODE_HW); 
		

		//
		// Configure the QEI module.
		//
		QEIConfigure(QEI0_BASE,
						 (QEI_CONFIG_NO_RESET | QEI_CONFIG_CAPTURE_A_B |
						  QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), QEI0_POSCNT_MAX-1);
		
		
		//Set to 0 
		QEIPositionSet(QEI0_BASE, 0);

		QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, 500000); //Configure the Velocity capture Module //500000 is 10ms at 50MHz 

		QEIVelocityEnable(QEI0_BASE);	//Enable the Velocity capture Module	
		
		QEIIntEnable(QEI0_BASE, QEI_INTDIR | QEI_INTINDEX);   //Enable Interrupt when the Timer is reach 0 on Valocity capture mode 
		
		QEIEnable(QEI0_BASE);
				
		//
		// Configure the encoder input to generate an interrupt on every rising
		// edge.
		//
		//GPIOIntTypeSet(QEI_PITCH_PHA_PORT, QEI_PITCH_PHA_PIN, GPIO_RISING_EDGE);
		//GPIOPinIntEnable(QEI_PITCH_PHA_PORT, QEI_PITCH_PHA_PIN);
		//IntEnable(QEI_PITCH_PHA_INT);			

		//Interrupt Enable 
		//IntEnable(INT_QEI1); 

			
	}
	else
	if(ulBase == QEI1_BASE)		// J8 ROLL Encoder 
	{

		//
		// Enable the peripherals QEI example.
		//	
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
		SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1); 

		//Enable GPIO for QEI1 
		//PC4-> IDX0 				
		//PC5-> PHA0
		//PC6-> PHB0 
		GPIOPinConfigure(GPIO_PC4_IDX1);		
		GPIOPinConfigure(GPIO_PC5_PHA1);	
		GPIOPinConfigure(GPIO_PC6_PHB1);		
			
		GPIOPinTypeQEI(QEI_ROLL_PHA_PORT,QEI_ROLL_PHA_PIN); 
		GPIOPinTypeQEI(QEI_ROLL_PHB_PORT,QEI_ROLL_PHB_PIN);
		GPIOPinTypeQEI(QEI_ROLL_INDEX_PORT,QEI_ROLL_INDEX_PIN);
		
		
		// Set F 0 and 1 to alternative use 
		GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_DIR_MODE_HW);//GPIO_DIR_MODE_HW	
		GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_DIR_MODE_HW); 
		GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_6, GPIO_DIR_MODE_HW); 
		

		//
		// Configure the QEI module.
		//
		QEIConfigure(QEI1_BASE,
						 (QEI_CONFIG_NO_RESET | QEI_CONFIG_CAPTURE_A_B |
						  QEI_CONFIG_QUADRATURE | QEI_CONFIG_SWAP), QEI1_POSCNT_MAX-1);
		
		
		//Set to 0 
		QEIPositionSet(QEI1_BASE, 0);

		QEIVelocityConfigure(QEI1_BASE, QEI_VELDIV_1, 500000); //Configure the Velocity capture Module //500000 is 10ms at 50MHz 

		QEIVelocityEnable(QEI1_BASE);	//Enable the Velocity capture Module	
		
		QEIIntEnable(QEI1_BASE, QEI_INTDIR | QEI_INTINDEX);   //Enable Interrupt when the Timer is reach 0 on Valocity capture mode 
		
		QEIEnable(QEI1_BASE);
				
		//
		// Configure the encoder input to generate an interrupt on every rising
		// edge.
		//
		//GPIOIntTypeSet(QEI_ROLL_PHA_PORT, QEI_ROLL_PHA_PIN, GPIO_RISING_EDGE);
		//GPIOPinIntEnable(QEI_ROLL_PHA_PORT, QEI_ROLL_PHA_PIN);
		//IntEnable(QEI_ROLL_PHA_INT);			

		//Interrupt Enable 
		//IntEnable(INT_QEI1); 

	}
}
コード例 #6
0
int main(void)
{
    long dir;
    unsigned long vel, pos;



    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);



    //
    // Set up low level I/O for printf()
    //
    llio_init(115200);


    //
    // Set up GPIO for LED
    //
    LED_INIT();



    //
    // Set up QEI peripheral
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

    GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_6);
    QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET |
                QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 0xffffffff);
    QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, SysCtlClockGet() / 10);

    QEIEnable(QEI0_BASE);
    QEIVelocityEnable(QEI0_BASE);



    //
    // Set up GPIO for encoder push switch
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_5);
    GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE);
    GPIOPortIntRegister(GPIO_PORTC_BASE, SW_IntHandler);
    GPIOPinIntEnable(GPIO_PORTC_BASE, GPIO_PIN_5);




    //
    // Set up the period for the SysTick timer.
    //
    SysTickPeriodSet(SysCtlClockGet() / 10);   // 10Hz SysTick timer


    //
    // Enable the SysTick Interrupt.
    //
    SysTickIntEnable();
    SysTickIntRegister(SysTickIntHandler);

    //
    // Enable SysTick.
    //
    SysTickEnable();

    printf("\r\nEncoder example\r\n");


    //
    // Loop forever.
    //
    while(1)
    {
        SysCtlSleep();              // sleep here till interrupt

        LED_TOGGLE();

        dir = QEIDirectionGet(QEI0_BASE);
        vel = QEIVelocityGet(QEI0_BASE);
        pos = QEIPositionGet(QEI0_BASE);
        printf("%d,%d,%d\r\n", dir, vel, pos);
    }
}