Guest User

Stelaris QEI

a guest
Jun 5th, 2012
219
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int main(void)
  2. {    
  3.     SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_8MHZ | SYSCTL_OSC_MAIN); //setting clock
  4.    
  5.  
  6.     SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0); //enable qei0
  7.  
  8.     SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);//enable qei1
  9.  
  10.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //enable GPIO
  11.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
  12.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  13.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
  14.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
  15.    
  16.     GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_4); //config qei0
  17.     GPIOPinTypeQEI(GPIO_PORTH_BASE, GPIO_PIN_3);
  18.     QEIConfigure(QEI0_BASE, ( QEI_CONFIG_CAPTURE_A | QEI_CONFIG_NO_RESET| QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP ),0xFFFFFFFF );
  19.    
  20.     GPIOPinTypeQEI(GPIO_PORTG_BASE, GPIO_PIN_6 | GPIO_PIN_7); //config qei1
  21.     QEIConfigure(QEI1_BASE, ( QEI_CONFIG_CAPTURE_A | QEI_CONFIG_NO_RESET| QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP ),0xFFFFFFFF );
  22.  
  23.     QEIEnable(QEI0_BASE); //enable qie0
  24.     QEIPositionSet(QEI0_BASE, 2000);
  25.  
  26.     QEIEnable(QEI1_BASE); //enable qie1
  27.     QEIPositionSet(QEI1_BASE, 2000);
  28. ...
  29.  
  30. position1 = QEIPositionGet(QEI1_BASE); //get position
  31. position2 = QEIPositionGet(QEI0_BASE);
  32. ...
  33.  
  34. }
RAW Paste Data