This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ME 461 Laboratory #6
Parallel Interfacing with the LS7266 Quadrature Counter Goals: 1. Become familiar with the new 3‐wheel robot hardware. 2. Write a driver for controlling the parallel interface between the microcontroller and the LS7266. NOTE: From this point forward in the lab, you will no longer use your breakout board as the hardware for completing lab exercises. Your TA will introduce you to the MSP430F2272‐based 3‐wheeled robots in lab. You are going to carry out the remainder of the lab assignments using these robots. They are programmed in the same way as your breakout boards, but the hardware setup of the robots is fixed. Also, they are equipped with wireless modems, so no wires are needed for serial communication with the PC. These robots are to remain in lab at all times. Exercise 1: (100 points) In this lab you are going to write a complete driver for communicating with the LS7266 dual‐axis quadrature encoder counter. By now, you should be familiar with quadrature encoder signals and how they are decoded. You should also be familiar with the LS7266 chip from homework 6. For clarity, we provide a brief review of communication with the LS7266. The chip has a bidirectional (I/O) data bus for writing to and reading from control and data registers. It contains two independent counter axes, X and Y, which can be selected by the X/Y pin. To select control registers for read/write, set the C/D pin high; for data registers, set the pin low. To read, set the RD pin low and read the state of the bus. To write, generate a low pulse on WR; the data will be written on the rising edge of the pulse. Control registers are addressed by the 3 most significant bits of the byte written to the LS7266. The most significant bit, when set, overrides the X/Y pin and applies changes to both the X‐ and Y‐axis control registers. See the datasheet for control register descriptions. When writing to data registers on the LS7266, the byte is placed in one of three 8‐bit segments of the 24‐bit preset register PR. The preset register may be transferred to the counter, or the least significant 8‐bit segment may be transferred to the filter clock prescaler register. When reading data from the LS7266, one of three 8‐bit segments of the 24‐bit output latch OL is presented on the data bus. The counter value must be transferred to the output latch in order to read the count. The specific segment of PR or OL to be accessed is indexed by the byte pointer BP. The byte pointer is automatically incremented (modulo‐3) when a data write or read takes place. In summary, three consecutive reads from or writes to the chip are necessary to access the counter (in addition to any appropriate control register accesses). The figure below shows the hardware configuration of the LS7266 on the robot board. The pins not shown on the LS7266 are left unconnected. MCU to LS7266 Hardware Configuration The digital I/O function should be chosen for all pins connected to the LS7266 with the exception of P2.1, which should be used to provide the SMCLK signal to the LS7266. Remember that the data bus on the LS7266 is bidirectional, so you will have to configure the direction of port 1 in your program based on whether you are writing to or reading from the chip. You are expected to perform most of the configuration on your own. However, the following guidelines will help you complete the exercise. 1. Write two functions, e.g. Read_LS7266 and Write_LS7266, for performing single‐byte read and write operations. The write function should accept three parameters (all of char type), one for specifying the counter axis to write (X/Y), one for control/data register selection, and one byte of data to write. The read function should accept only two parameters, which are the same as the first two for the write function, but it should return a byte of data read from the LS7266. These two functions are the fundamental building blocks of the interface. In writing these functions you should avail yourself of the read and write cycle timing diagrams in the datasheet. 2. Write two functions for reading from and writing to the 24‐bit counter of the LS7266. These functions should call the functions described above several times to complete the task of setting or reading the counter. Also, keep in mind that on the microcontroller the smallest data container for a 24‐bit number is a long. The read function should be passed one parameter, the encoder axis to read from, and it should return a long containing the encoder count. The write function should be passed two parameters, the encoder axis to write to, and the (long) counter value to write. You should use sign extension in these functions to convert between the 24‐bit counters and the corresponding 32‐bit signed representations in your program. Use the most significant (23rd) bit of the counters as the “sign” bit. 3. Write an initialization routine, e.g. Init_LS7266, that configures the pins connected to the LS7266 and initializes the chip itself. Initialization of the chip comprises setting all control registers to their desired states, setting the filter clock prescaler, and clearing the X and Y axis counters. You should call this function in your main function in the configuration area before setting the GIE bit. You may find it helpful to use #define macros liberally in your program. For instance, #define can be used to name bit patterns in control registers, thus eliminating the need to continually reference the datasheet for bit positions, etc. See the example below using the index control register // Index Control Register
// IDR address
Index polarity (0-negative,1-positive)
Indexed pin (0-LCNTR/LOL, 1-RCNTR/ABG) Using these macro definitions, we can tell the LS7266 to enable indexing on the LCNTR/LOL pin with positive polarity by writing IDR + IDXEN + IDXPOL to the data bus (while the C/D pin is high). This example demonstrates the fact that control bytes sent to the LS7266 contain the register address (in our case bit 5 = 0 and bit 6 = 1) and the data to be written. You may also use #define to name the pins and bit positions on the microcontroller. See the example below. // Control pin configurations
// Etc. // Control/Data pin
// Write pin
// Chip select Using these macros, a command like P4OUT &= ~CS; will enable the chip for read/write access and a command like P4OUT |= CD; will choose control registers to read/write. Test your driver by reading both counter axes and printing their values to the terminal every 0.1 seconds. If the driver is working correctly, you should see a signed integer representing the quadrature count. There should be 564 counts per revolution of the wheel. Demonstrate to your TA. ...
View Full Document
This note was uploaded on 11/07/2011 for the course ME 461 taught by Professor Staff during the Spring '08 term at University of Illinois, Urbana Champaign.
- Spring '08