Stepper Motor Indexer & Decoder
ECE 476: Spring 2005

Daniel Beer, dbb28
Tony Lloyd, aml54
 

Introduction | High Level | Hardware Design | Software Design
Results | Pictures | Conclusion | Appendices
 

 

4.1 Software

Shown below is a structure diagram of our software. There are six interrupts. The first two halt the motor when a hardware limit switch is engaged. The clock interrupt forms the basis for time measurement and is used in task scheduling. The resolution of our clock is 1 millisecond +/- .005 per cent.



 

Note that times for invoking the three tasks: task_serial() = 49 milliseconds, task_lcd() = 249 milliseconds, and task_checkmotor() = 99 milliseconds. These tasks are called by While(1) which constantly monitors Clock Interrupt updates. The Step Interrupt is a state machine interrupt which keeps track of motor position and which updates itself by means of a look up table. The transmit and receive interrupts form the basis of communication with the host computer via RS-485 and are in the file uart.h.

The Init() function sets the USART control registers up, initializes global variables, sets the counter/timers up and finally enables interrupts. Task_serial() is the functions which updates global variables and reports back with status and query data. A motor movement command invokes the function setupmove() which performs the step calculations which then invokes 1.4, the step interrupt in counter/timer1.

Task_lcd() updates the liquid crystal display with communication information while the USART is active and with motor status data relating to the state machine while the motor is running. The decoded position of the optical encoder is also reported. Every 99 milliseconds while the motor is running the motor position as calculated from step pulses executed is compared with the decode position of the motor shaft. In the case where motor slippage is excessive. The commands for communicating with the decoder are in ls7266r1.h.

4.2 State Machine

There are eleven states in the state machine two of which are meta or transient states: states 5 and 8. The motor controller spends most of its time in the OFF state, state 0. When commanded to move state 1 is entered, then state 2 and finally state 3. At his point a decision is made by meta-state 5 as to whether backlash (states 5 and 6) is applied or not. In either case, state 7 is entered for a final reading of the decoder. Once the decoder is read meta-state 8 is entered and a decision is made as whether to apply slip compensation or not. In either case, the state machine ends in state 0, the OFF state. State 10 is for tweaking or jogging the motor in small steps.