-
Notifications
You must be signed in to change notification settings - Fork 29
/
QEI_config.c
43 lines (37 loc) · 1.68 KB
/
QEI_config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*!
* @author Yash Bansod
* @date 29th September 2017
*
* @brief Source containing function definitions for QEI configuration
* @file QEI_config.c
*/
/* ----------------------- Include Files --------------------- */
#include "QEI_config.h"
/* ----------------------- Function Definition --------------------- */
// Function for Initializing QEI1 Peripheral
void QEI1_init(void){
// Enable the clock for peripherals PortC and QEI1
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
// Configure the PC5 and PC6 as PhaseA and PhaseB of QEI1
ROM_GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6);
ROM_GPIOPinConfigure(GPIO_PC5_PHA1);
ROM_GPIOPinConfigure(GPIO_PC6_PHB1);
// Configure the QEI1 to increment for both PhA and PhB with maximum count of 0xFFFFFFFF
ROM_QEIConfigure(QEI1_BASE, QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_QUADRATURE, 4294967295);
// Configure the QEI1 for Velocity Calculation, Predivide Velocity by 1 at "VEL_INT_FREQ" Hz
ROM_QEIVelocityConfigure(QEI1_BASE, QEI_VELDIV_1, ROM_SysCtlClockGet() >> VEL_INT_FREQ);
ROM_QEIVelocityEnable(QEI1_BASE);
// Enable the Interrupts for Velocity Timer Expiration of QEI1
void (*QEI1IntHandler_ptr)(void) = &QEI1IntHandler;
QEIIntRegister(QEI1_BASE, *QEI1IntHandler_ptr);
ROM_QEIIntEnable(QEI1_BASE, QEI_INTTIMER);
}
// Function for Enabling QEI1 Peripheral
void QEI1_enable(void){
// Enable the QEI1
ROM_QEIEnable(QEI1_BASE);
ROM_QEIPositionSet(QEI1_BASE, CENTER_POSITION);
// Update the position reading of the encoder
ui32Qei1Pos = ROM_QEIPositionGet(QEI1_BASE);
}