A step motor is the easiest to control. Its handling simplicity is hard to deny – all there is to do is to bring the sequence of rectangle impulses to one input of the step controller and direction information to another input. Direction information is very simple and comes down to "left" for the logical one on that pin and "right" for logical zero. Motor control is also very simple every impulse makes the motor operate for one step and if there is no impulse the motor won't start. Pause between impulses can be shorter or longer and it defines the revolution rate.

This rate cannot be infinite because the motor won't be able to "catch up" with all the impulses (documentation on a specific motor should contain such information). The picture below represents the scheme for connecting the step motor to the microcontroller and the appropriate program code follows.

The key to driving a stepper is realizing how the motor is constructed. A diagram shows the representation of a 4 coil motor, so named because 4 coils are used to cause the revolution of the drive shaft. Each coil must be energized in the correct order for the motor to spin.

### Step angle

It is the angle through which the motor shaft rotates in one step. step angle is different for different motors. selection of motor according to step angle depends on the application, simply if you require small increments in rotation choose a motor having a smaller step angle. No of the steps require rotating one complete rotation = 360 deg. / step angle in deg.

### INTERFACING TO 8051.

To cause the stepper to rotate, we have to send a pulse to each coil in turn. The 8051 does

not have sufficient drive capability on its output to drive each coil, so there are several ways to drive a stepper, Stepper motors are usually controlled by a transistor or driver IC like ULN2003. The driving current for each coil is then needed to about 60mA at +5V supply.

### Servo Motor

Servos are DC motors with built-in gearing and feedback control loop circuitry. And no motor drivers are required. They are extremely popular with robots, RC planes, and RC boat builders. Most servo motors can rotate about 90 to 180 degrees. Some rotate through a full 360degreesormore.

However, servos are unable to continually rotate, meaning they can't be used for driving wheels unless they are modified (how to modify), but their precision positioning makes them ideal for robot legs and arms, rack and pinion steering, and sensor scanners to name a few. Since servos are fully self-contained, the velocity and angle control loops are very easy to implement, while prices remain very affordable. To use a servo, simply connect the black wire to the ground, the red to a 4.8-6V source, and the yellow/white wire to a signal generator (such as from your microcontroller). Vary the square wave pulse width from 1-2 ms and your servo is now position/velocity controlled.

Pulse width modulation (PWM) is a powerful technique for controlling analog circuits with a processor's digital outputs. PWM is employed in a wide variety of applications, ranging from measurement and communications to power control and conversion. The general concept is to simply send an ordinary logic square wave to your servo at a specific wavelength, and your servo goes to a particular angle (or velocity if your servo is modified). The wavelength directly maps to the servo angle.

### PWM

Pulse width modulation (PWM) is a powerful technique for controlling analog circuits with a processor's digital outputs. PWM is employed in a wide variety of applications, ranging from measurement and communications to power control and conversion. The general concept is to simply send an ordinary logic square wave to your servo at a specific wavelength, and your servo goes to a particular angle (or velocity if your servo is modified). The wavelength directly maps to the servo angle.

### Programmable Counter Array (PCA)

The PCA is a special module in Philips P89V51RD2 which includes a special 16-bit Timer that has five 16-bit capture/compare modules associated with it. Each of the modules can be programmed to operate in one of four modes: rising and/or falling edge capture, software timer, high-speed output, or pulse width modulator. Each module has a pin associated with it in port 1. Module 0 is connected to P1.3 (CEX0), module 1 to P1.4 (CEX1), etc. Registers CH and CL contain the current value of the free running up counting 16-bit PCA timer. The PCA timer is a common time base for all five modules and can be programmed to run at 1/6 the oscillator frequency, 1/2 the oscillator frequency, the Timer 0 overflow, or the input on the ECI pin (P1.2). The timer count source is determined from the CPS1 and CPS0 bits in the CMOD SFR. In the CMOD SFR, there are three additional bits associated with the PCA. They are CIDL which allows the PCA to stop during idle mode, WDTE which enables or disables the Watchdog function on module 4, and ECF which when set causes an interrupt and the PCA overflow flag CF (in the CCON SFR) to be set when the PCA timer overflows. The Watchdog timer function is implemented in module 4 of PCA. Here, we are interested only in PWM mode.

### 8051 Pulse width modulator mode

All of the PCA modules can be used as PWM outputs. Output frequency depends on the source of the PCA timer. All of the modules will have the same frequency of output because they all share one and only PCA timer. The duty cycle of each module is independently variable using the module's capture register CCAPnL.When the value of the PCA CL SFR is less than the value in the module's CCAPnL SFR the output will be low, when it is equal to or greater than the output will be high. When CL overflows from FF to 00, CCAPnL is reloaded with the value in CCAPnH. this allows updating the PWM without glitches. The PWM and ECOM bits in the module's CCAPMn register must be set to enable the PWM mode. For more details see the P89V51RD2 datasheet. This is an example of how to control servos with 8051 by using PWM. The schematic is shown below. I use P1.4 (CEX1) to control the left servo and P1.2 (CEX2) to control the right servo. Here, I use GWS servo motor model S03T STD. I need three states of duty cycle:

20 ms to Stop the servo

1 ms to Rotate Clockwise

Initial PWM Period = 20mS (18.432MHz /6-Cycle Mode)

Initial PCA Count From Timer0 Overflow

1 Cycle of Timer0 = (1/18.432MHz)x6 = 0.326 uS

Timer0 AutoReload = 240 Cycle = 78.125 uS

1 Cycle PCA = [(1/18.432MHz)x6]x240 = 78.125 uS

Period 20mS of PCA = 20ms/78.125us = 256 (CL Reload)

CL (20mS) = 256 Cycle Auto Reload

Load CCAPxH (1.0mS) = 256-13 = 243 (243,244,...,255 = 13 Cycle)

Load CCAPxH (2.0mS) = 255-26 = 230 (230,231,...,255 = 26 Cycle)

2 ms to Rotate Counter-clockwise

### Washing Machine Control

Many washing m/c shells in the market have a mechanically controlled sequence for activating the timer and the sequence back and forth for their motor; washing motor or spinning motor. Spinning motor control only has one direction, and its simple could be changed to the discrete mechanical timer which sells on the market. But washing motor control has 2 directions for this purpose, which means to squeeze the clothes, it must go forward and then reverse. The sequence is like this :

First, go in the forward direction for about a few seconds

Then stop, while the chamber is still rotating

Second, go back to reverse direction for about a few seconds

Then stop, while the chamber is still rotating

And so on, back and forth, until the timer elapsed

### SCHEMATIC

Timing sequences like the above description can be implemented in many ways, by using discrete electronic components, a timer, using a program or a microcontroller or microprocessor, etc. Because I am learning the PIC microcontroller right now, I will implement this function using this microcontroller, but for those who are familiar with another kind of microcontroller, I adapted it to your purpose. By using PIC micro, it can be made more compact. First I plan to make 2 buttons, 1 for setting the timer and another for resetting the timer or the emergency stop push button. Then to know the timer works or not, I need a visual display. For this purpose, I will use a 7-segment display showing the rest of the timer. To run the motor sequence of course I need a pair of relays (power relays, about 3 Amperes output), one for forward and another for reverse option. I will use the very common family of PIC micro, ie: 16F84A, because this is the most popular type and very simples used and very much used. Also can be obtained easily in the market. But this is the medium type of PIC micro family. It has 1kByte of memory (EEPROM type) and 13 I/O pins. It can be reprogrammable thousands of times. Because the I/O just only 13 pins, I used a BCD to 7-segment chip. So it will leave a few I/O pins for expansion in the future.

You can omit this chip for timing sequence purposes and save one IC price because the I/O is just exactly enough.

I/O port A-0 = SET push button

I/O port A-1 = RST push button

I/O port A-2 = Reserved

I/O port A-3 = Reserved

I/O port A-4 = Reserved

I/O port B-0 = Forward Relay (Run motor forward)

I/O port B-1 = Reverse Relay (Run motor reverse)

I/O port B-2 = Activated unit 7-segment (multiplexed)

I/O port B-3 = Activated ten 7-segment (multiplexed)

I/O port B-4 = BCD data A (for 7-segment)

I/O port B-5 = BCD data B (for 7-segment)

I/O port B-6 = BCD data C (for 7-segment)

I/O port B-7 = BCD data D (for 7-segment)

Also integrated power supply to run it modularly

The I/O can be configured as an input pin or output pin bit-ly. It is up to you to choose the I/O PIN that goes to what function, but it infects the program firmware of course. Once you choose, then it is just like that, except you also change both, the program and the hardware.

### Working on Washing Machine

The direction of rotation can be controlled When switchS1 is in position A, coil L1 of the motor receives the current directly, whereas coil L2 receives the current with a phase shift due to capacitor C. So the rotor rotates in a clockwise direction (see Fig. 2(a)). When switch S1 is in position B, the reverse happens and the rotor rotates in an anti-clockwise direction Thus switch S1 can change the rotation direction. The motor cannot be reversed instantly. It needs a brief pause between switching directions, or else it may get damaged. For this purpose, another spin direction control timer (IC2) is employed. It is realized with an IC 555. This timer gives an alternate „on‟ and „off‟ time duration of 10 seconds and 3 seconds, respectively. So after every l0 seconds of running (either clockwise or anticlockwise direction), the motor stops for a brief duration of 3 seconds. The values of R3 and R4 are calculated accordingly. The master timer is realized with monostable IC555 (IC1) and its „on‟ time is decided by the resistance of 1-megaohm potmeterVR. A 47-kilo-ohm resistor is added in series so that even when the VR knob is in a zero resistance position, the net series resistance is not zero.