Hello
Why does not the function work?
I'm use SW-Ver (TivaWare_C_Series-2.1.2.111)
Description in SW-TM4C-DRL-UG-2.1.2.111.pdf
1. QEIPositionGet()
Returns: The current position of the encoder.
2. QEIVelocityGet()
Returns: Returns the number of pulses captured in the given time period.
3. QEIDirectionGet()
Returns: Returns 1 if moving in the forward direction or -1 if moving in the reverse direction.
thanks.
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#include <stdbool.h> #include <stdint.h> #include "inc/tm4c123gh6pge.h" #include "inc/hw_memmap.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" #include "driverlib/qei.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" int qei_position; int qei_velocity; void ConsoleInit() { //UART Init //SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(0, 115200, SysCtlClockGet()); UARTEnable(UART0_BASE); UARTprintf( "UART Init \n" ); } void QEI1IntHandler( void ) { unsigned long status; status = QEIIntStatus(QEI1_BASE, false ); if ((status & QEI_INTTIMER) == QEI_INTTIMER) { QEIIntClear(QEI1_BASE, QEI_INTTIMER); // QEIIntClear(QEI1_BASE, QEI_INTDIR); qei_position = QEIPositionGet(QEI1_BASE); qei_velocity = QEIVelocityGet(QEI1_BASE) * QEIDirectionGet(QEI1_BASE); UARTprintf( "position = %d \n" , qei_position); UARTprintf( "velocity = %d \n\n" , qei_velocity); } } int main( void ) { SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // 40 MHz 200MHz/5 = ? ConsoleInit(); SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); QEIConfigure(QEI1_BASE, QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_SWAP, 0xFFFFFFFF); GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6); GPIOPinConfigure(GPIO_PC5_PHA1); GPIOPinConfigure(GPIO_PC6_PHB1); QEIVelocityConfigure(QEI1_BASE, QEI_VELDIV_2, SysCtlClockGet()/50); //20 ms period QEIVelocityEnable(QEI1_BASE); QEIEnable(QEI1_BASE); QEIIntEnable(QEI1_BASE, QEI_INTTIMER); QEIIntRegister(QEI1_BASE, &QEI1IntHandler); IntEnable(INT_QEI1); IntMasterEnable(); GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD_WPU); while (1) { UARTprintf( "position = %d \n" , qei_position); UARTprintf( "velocity = %d \n\n" , qei_velocity); } } |
* [ illustration ] GPIO Port C, CH1: PC5(PHA1), CH2: PC6(PHB1) input phase
[Result Log message]
- After a few minutes
Position = 2
- After a few minutes
Position = 4
- After a few minutes
8, ........ 29