//***************************************************************************** // // This function prepares the quadrature encoder module for capturing the // position and speed of the motor. // //***************************************************************************** void EncoderInit(void) { // // Configure the QEI pins. // ROM_GPIOPinTypeQEI(QEI_PHA_PORT, QEI_PHA_PIN); ROM_GPIOPinTypeQEI(QEI_PHB_PORT, QEI_PHB_PIN); ROM_GPIOPinTypeQEI(QEI_INDEX_PORT, QEI_INDEX_PIN); // // Configure the QEI module. // ROM_QEIConfigure(QEI0_BASE, (QEI_CONFIG_RESET_IDX | QEI_CONFIG_CAPTURE_A | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 0xffffffff); // // Initialize the QEI position to zero. // ROM_QEIPositionSet(QEI0_BASE, 0); // // Enable the QEI module. // ROM_QEIEnable(QEI0_BASE); // // Configure the encoder input to generate an interrupt on every rising // edge. // ROM_GPIOIntTypeSet(QEI_PHA_PORT, QEI_PHA_PIN, GPIO_RISING_EDGE); ROM_GPIOPinIntEnable(QEI_PHA_PORT, QEI_PHA_PIN); ROM_IntEnable(QEI_PHA_INT); }
// * enc_init ***************************************************************** // * Setup pins and hardware to read quadrture encoders. Setup causes each * // * encoder line to result in 4 pulses, i.e. a 100line encoder would yield * // * 400 pulses/revolution. * // * Assumes system clock already configured * // **************************************************************************** void enc_init(void) { unsigned long config_temp; // used when assembling configuration values // setup pins for QEI // ENC_1------------------------------- ROM_SysCtlPeripheralEnable(ENC_1_PORT); // enable clock to GPIO port //ROM_SysCtlPeripheralReset(ENC_1_PORT); // reset to clear any previous configuration // configure input pads ROM_GPIOPinConfigure(ENC_1_B_MUX); // select mux for qei input ROM_GPIOPinConfigure(ENC_1_A_MUX); // select mux for qei input ROM_GPIOPinConfigure(ENC_1_INDEX_MUX); // select mux for qei input // copy and pasted from GPIOPinTypeQEI, // modified to have no pull up/down resistors. GPIODirModeSet(ENC_1_PORT_BASE, ENC_1_PINS, GPIO_DIR_MODE_HW); // QEI pin tristates under HW control. GPIOPadConfigSet(ENC_1_PORT_BASE, ENC_1_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); // Note, output drive config only configs // pull up/down resistors when pin is input. // ENC_2------------------------------- ROM_SysCtlPeripheralEnable(ENC_2_PORT); // enable clock to GPIO port //ROM_SysCtlPeripheralReset(ENC_2_PORT); // reset to clear any previous configuration // configure input pads ROM_GPIOPinConfigure(ENC_2_B_MUX); // select mux for qei input //ROM_GPIOPinConfigure(ENC_2_A_MUX); // select mux for qei input WORKAROUND FOR DEAD PIN ROM_GPIOPinConfigure(ENC_2_INDEX_MUX); // select mux for qei input // copy and pasted from GPIOPinTypeQEI, // modified to have no pull up/down resistors. GPIODirModeSet(ENC_2_PORT_BASE, ENC_2_PINS, GPIO_DIR_MODE_HW); // QEI pin tristates under HW control. GPIOPadConfigSet(ENC_2_PORT_BASE, ENC_2_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); //GPIODirModeSet(ENC_2_PORT_BASE, ENC_2_PINS, GPIO_DIR_MODE_IN);//DEBUG //DEBUG // Note, output drive config only configs // pull up/down resistors when pin is input. // ENC_2 DEAD PIN WORKAROUND SETUP----- ROM_SysCtlPeripheralEnable(ENC_2_PORT_2); // enable clock to GPIO port // configure input pads ROM_GPIOPinConfigure(ENC_2_A_MUX); // select mux for qei input WORKAROUND FOR DEAD PIN // copy and pasted from GPIOPinTypeQEI, // modified to have no pull up/down resistors. GPIODirModeSet(ENC_2_PORT_BASE_2, ENC_2_PINS_2, GPIO_DIR_MODE_HW); // QEI pin tristates under HW control. GPIOPadConfigSet(ENC_2_PORT_BASE_2, ENC_2_PINS_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); // setup QEI modules // ENC_1------------------------------- ROM_SysCtlPeripheralEnable(ENC_1_MODULE); // enable clock to QEI ROM_QEIConfigure(ENC_1_BASE, (QEI_CONFIG_CAPTURE_A_B | // configure QEI QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), ENC_MAX_POSITION); ROM_QEIVelocityConfigure(ENC_1_BASE,QEI_VELDIV_1, // configure hardware velocity capture ENC_VEL_PERIOD); ROM_QEIVelocityEnable(ENC_1_BASE); // enable velocity capture // enable digital filter on input config_temp = HWREG(ENC_1_BASE + QEI_O_CTL); // grab copy of the QEI's control register config_temp |= ENC_FILT_ENA_BITS; // configure and enable digital persistence filter HWREG(ENC_1_BASE + QEI_O_CTL) = config_temp; // write modified value back to register // ENC_2------------------------------- ROM_SysCtlPeripheralEnable(ENC_2_MODULE); // enable clock to QEI ROM_QEIConfigure(ENC_2_BASE, (QEI_CONFIG_CAPTURE_A_B | // configure QEI QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), ENC_MAX_POSITION); ROM_QEIVelocityConfigure(ENC_2_BASE,QEI_VELDIV_1, // configure hardware velocity capture ENC_VEL_PERIOD); ROM_QEIVelocityEnable(ENC_2_BASE); // enable velocity capture // enable digital filter on input config_temp = HWREG(ENC_2_BASE + QEI_O_CTL); // grab copy of the QEI's control register config_temp |= ENC_FILT_ENA_BITS; // configure and enable digital persistence filter HWREG(ENC_2_BASE + QEI_O_CTL) = config_temp; // write modified value back to register ROM_QEIEnable(ENC_1_BASE); // Enable one QEI after the other. ROM_QEIEnable(ENC_2_BASE); // Try to keep sync, later we will assume ENC_2 // velocity capture finishes just after ENC_1, // so we will interrupt off ENC_2's velocity timer. }