could use a load value of 82, resulting in 32,800 as the divisor, which is 0.09% above 2
14
. In this
case a shift by 15 would be an adequate approximation of the divide in most cases. If absolute
accuracy were required, the microcontroller's divide instruction could be used.
The QEI module can produce a controller interrupt on several events: phase error, direction change,
reception of the index pulse, and expiration of the velocity timer. Standard masking, raw interrupt
status, interrupt status, and interrupt clear capabilities are provided.
24.4
Initialization and Configuration
The following example shows how to configure the Quadrature Encoder module to read back an
absolute position:
1.
Enable the QEI clock using the
RCGCQEI
register in the System Control module (see page 399).
2.
Enable the clock to the appropriate GPIO module via the
RCGCGPIO
register in the System
Control module (see page 382).
3.
In the GPIO module, enable the appropriate pins for their alternate function using the
GPIOAFSEL
register. To determine which GPIOs to configure, see Table 26-4 on page 1797.
4.
Configure the
PMCn
fields in the
GPIOPCTL
register to assign the QEI signals to the appropriate
pins (see page 787 and Table 26-5 on page 1808).
5.
Configure the quadrature encoder to capture edges on both signals and maintain an absolute
position by resetting on index pulses. A 1000-line encoder with four edges per line, results in
4000 pulses per revolution; therefore, set the maximum position to 3999 (0xF9F) as the count
is zero-based.
■ Write the
QEICTL
register with the value of 0x0000.0018.
■ Write the
QEIMAXPOS
register with the value of 0x0000.0F9F.
6.
Enable the quadrature encoder by setting bit 0 of the
QEICTL
register.
Note:
Once the QEI module has been enabled by setting the
ENABLE
bit in the
QEICTL
register, it cannot be disabled. The only way to clear the
ENABLE
bit is to reset the
module using the
Quadrature Encoder Interface Software Reset (SRQEI)
register.
7.
Delay until the encoder position is required.
8.
Read the encoder position by reading the
QEI Position (QEIPOS)
register value.
Note:
If the application requires the quadrature encoder to have a specific initial position, this
value must be programmed in the
QEIPOS
register after the quadrature encoder has been
enabled by setting the
ENABLE
bit in the
QEICTL
register.
24.5
Register Map
Table 24-2 on page 1754 lists the QEI registers. The offset listed is a hexadecimal increment to the
register's address, relative to the module's base address:
■ QEI0: 0x4002.C000
1753
June 18, 2014
Texas Instruments-Production Data
Tiva
™
TM4C1294NCPDT Microcontroller