//*****************************************************************************
//
// 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);
}
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);
}
Example #3
0
//*****************************************************************************
//
// 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); 

	}
}