Sunday, April 17, 2011


The motor controller is the interface to the stepper motor. Stepper motor has four coils. The coils of the stepper motor are to be energized as follows for it to rotate forward.
Stepper motor operation

So to rotate the stepper motor in the “forward direction”, the sequence 1100 is to be right shifted by one bit for each step. A step is defined as the linear distance traveled when the sequence is shifted right by one bit. To rotate the stepper motor in the “reverse direction”, the sequence 1100 is to be shifted left by one bit for each step. Thus the operation involving rotation of the stepper motor is shifting the sequence 1100 right or left onto the coils of the stepper motor. An encoder provides feedback upon completion of one step rotation. The feedback signal is used as an indicator to shift the next pattern in.

Step Angle:
There are 4 steps in 360 degrees. Hence the step angle is 90 degrees
step angle = 360/4 = 90
if the diameter of the wheel is 5 cm, the distance moved in one step is approx (2*pi*r/4) =  4 cms.

Thus when both the wheels are rotated by a step, the motor moves forward by 4 cms.

The robot has two wheels. The wheels are connected to the stepper motor. To move the robot forward, both wheels are to be rotated at the same time in the forward direction. To turn the robot right we can either
1.Rotate the left wheel while keeping the right wheel stationary.
2. Rotate the left wheel forward and right wheel backward (tight turn).
Thus using these maneuvering techniques, we can make the robot move in forward, reverse directions and also make it turn left and right. Tight turn is not implemented.

Angle of Turn per step
The method of turning is rotate one wheel while keeping the other stationary.
The width of the robot is taken to be 15 cm.
The linear distance moved per step is 4cm
we know s = r * Ɵ
4 = 15 *  Ɵ =>  Ɵ = 15 degrees

Thus for turning, rotate one wheel and do not rotate the other. each step turns the robot by 15 degrees.

The motor  controller is provided with a control word from the open8 micro controller. The control word is 8 bits wide, bits 3 down to 0 represents the number of steps that is to be moved. Bits 5,4 selects the motor that is to be rotated and bit 6 is used to select the direction of rotation (forward or reverse). Bit 7 is used for selecting between interrupting or not interrupting the microcontroller after task is completed.

Contorl word (8 bits)
1.Bits 3 down to 0 – Number of steps to be rotated (step_counter)
1.“1111” - 15 steps (example)
2.Bits 5 down to 4 – (select) The Motor that is to be rotated (Motor_select)
1.Control_word(5) = 1, left motor is selected
2.Control_word(4) = 1, right motor is selected
3.Control_word(5,4) = “11”, both motors are selected
4.Control_word(5,4) = “00”, No motor is selected
3.Bit 6 – Direction of rotation of the selected motor(s) (Motor_direction)
1.Control_word(6) =  0, forward direction of rotation
2.Control_word(6) =  1, reverse direction of rotation
4.Bit 7 – Interrupt upon task completion
1.Control_word(7) = 1, interrupt the MC upon completion of task
2.Control_word(7) = 0, do not interrupt the MC upon completion of task, execute the previous control word again.

Two modes of operations:

Depending on the bit 7, the motor controller can operate in
       1.autonomous mode
       2.slave mode
Autonomous mode – control_word(7) = '0'
The motor controller, loads the control word that is available in the control_word_register after completing a task and continues to execute it. It doesnt interrupt the micro controller after completion of the task. This frees the MC from servicing the motor controller when there is no need for it.

Slave mode – control_word(7) = '1'
The motor controller interrupts the MC after completion of the task. The microcontroller can load a new control word into the motor controller upon interrupt. This gives a greater controllability in terms of the number of steps to be rotated. 

The entity used to interface with the motor is shown below

entity motor_interface is
  port (
    enable                 : in  std_logic;
    motor_feedback : in  std_logic;
    rst                       : in  std_logic;
    control_word     : in  std_logic_vector(7 downto 0);
    wr_en                : in  std_logic; 
    motor_output1   : out std_logic_vector(3 downto 0);
    motor_output2   : out std_logic_vector(3 downto 0);
    task_completed  : out std_logic;
    int_ack               : in  std_logic);
end motor_interface;

The motor_feedback is the feedback signal from the motor encoders after it has rotated a step. Rst is the reset signal, control_word is the control word loaded from the micro controller. Whenever enable signal is made high, the control word is loaded into the internal registers. The motor_output1 and motor_output2 are the wires connected to the coils of the stepper motor through proper driving circuitry.  The task_completed output is used to interrupt the micro controller upon task completion.

The motor controller has an internal control_word_register. This control word register is initialized to “00111111” . This means that the robot moves forward. The is a step counter which keeps track of the number of steps moved. The model used here is the control word loads the pattern (“1100”) onto the coils of the motor. The motor rotates by a step and sends a feed back signal (motor_feedback) upon completion. Upon receiving the feedback signal, the motor controller decrements the step counter by 1, loads the next shifted pattern.

Upon reset, the control word is set to “00111111”. The step counter is set to control_word(3 downto 0)=“1111”(15 steps). The Motor_select is set to control_word(5 downto 4) = “11”(select both motors). The Motor_direction is set to control_word(6) = '0' (forward direction). 

As you can see in the waveforms, the rst signal is made high, The control word is loaded with the default value and the pattern “1100” is applied to the motors (motor_output1, motor_output2). There is no need for a control word to be loaded by the micro controller to load a control word and the motor controller can operate autonomously. Once the patterns are applied, the motor controller waits for the feed back form the motor (motor_feedback). 

Feedback from the motor
Upon receiving a feedback from the motor that movement by a step is complete, the next pattern is loaded into the motor_outputs wires depending on the direction of rotation. 

In the figure, you can see that upon receiving a feedback, the start shifting depending on the motor_direction. In this case, the motor_direction is '0' which is moving in the forward direction and hence the patterns are shifted right. As you can see, both the motor_outputs are shifted because the motor_select is “11” (both motors are selected). You can also see that upon receive of feedback from the motor, the step_counter decrements by 1. Shifting continues till the step counter becomes 0. The motor controller then starts the entire process again by loading the internal control registers with the value in the control_word_reg. Hence intervention by the micro controller is not necessary.

Loading a control word by the microcontroller

The control word to be loaded is put in the control_word input of the motor controller and the enable signal is made high. 
Control_word <= control word from MC
enable             <= '1' from the microcontroller

This loads the control registers with the values of the control word. As you can see in the waveform, the new control word (00110011) is loaded into the step_counter, motor_select and motor_direction. After enable goes low, execution of the new control word starts after receiving a feedback from the motor for the previous operation. 

In the waveform you can also see the step counter decreasing after each step. Since control_word(7) = '0', the motor controller is in the autonomous mode of operation. When the step counter expires, the control word is reloaded into the registers and the micro controller is not interrupted in the process. 
This control word moves both the motors forward by 3 steps autonomously. 

Finer control of motion
For finer control over the distance moved, the slave mode of operation is useful. The slave mode interrupts the micro controller after completion of each task. Consider rotating the motor right by 30 degrees. The method is rotate the left motor “forward” by “2 steps” while keeping the “right motor stationary”. (The resolution for a turn is 15 degrees per step). The “micro controller must be interrupted” after operation to load in the next word. The control word to be loaded is “10100010”. 

It can be seen in the waveform that after loading control word, motor_output1(left motor) shifts for 2 steps while the motor_output2(right motor) remains stationary. After 2 steps, the interrupt (task_completed) goes high and the motor controller waits for the next control word from the micro controller. When the micro controller loads in the next word, the motor controller resumes operation.

As you can see in the above waveform, the control word “10100010” interrupts the micro controller after completing its task through the task_completed signal. The micro controller acknowledges the interrupt, loads in a new control word “0011111”. This control word moves the robot forward without interrupting the micro controller. The robot moves forward until a new control word is loaded by the micro controller. 
Thus the operation of the motor controller is described in detail.
Abishek Ramdas
NYU Poly

1 comment:

  1. That's great.Now, I am very much clear about Motor Controller. It will control the signal which are comes from a machine.

    Stepper Motor Driver