Friday, January 28, 2011

5.1.2 Rotating Stepper Motor [two direction with LCD]

Hello Readers:

I have started this blog to show you Embedded C programming for 8051 family microcontroller using KEIL compiler. The KISS philosophy is used to write this tutorial. What is KISS? Keep It Simple, Stupid!


5.         Motor Interface

This section teaches you how to write program for stepper motors and dc motors. In this section no flow chart diagrams are provided, so try to figure out the one from source code.


5.1 Stepper Motor
First we see how to write program for stepper motors.

5.1.2   Rotating Stepper Motor [two direction with LCD]  


The stepper motor interface with microcontroller chip is a demanding application. Because all embedded systems usually needs motors, viz., for controlling door, moving vehicles, controlling robotic arms etc. This program rotates the stepper motor in both direction i.e., when switch is pressed in clockwise and when switch is released in anti-clockwise directions. 

Start KEIL V4.01 and close projects, if any are open. Now start new project with Device -> Generic->8051 [all variants] for general 8051 family target chip. Add a new text file, name it Pgm_211.C and add it to above created project as a source file. It is time to add code to Pgm_211.C, so type below shown code in it.
  
Code explanation: All the code blocks used in this program are from previous programs, so explanation is necessary. Two rotate stepper motor in both directions, send signals once is forward form and next in reverse form. You can figure it out from the source code.


After typing the code, press F7 or click Project->Build Target for building the source code. If there are no typical errors file will build successively and shows zero errors and zero warnings.
Now enter into debug mode by pressing Ctrl+F5 or click Debug->Start/Stop Debug Session menu. Our program is sending coil winding energizes signals to Port 2 continuously. So we want to watch the Port 2 pins while running this program for changing values. To get Port 2 tab click Peripherals->I/O Ports->Port 2 text.

Run the program by pressing F5 or clicking Debug->Run. You can see the changing values on Port 2 tab continuously in binary form. Alas you can see only one direction bits change as key press procedure is not simulated here. If you generate HEX file of this program, burn it into your target chip’s memory using suitable uploader and connecting stepper motor to Port 2 you can watch stepper motor rotating in both direction after key press & release. To stop running the program press red ‘x’ mark icon or click Debug->Stop.

To get back the compile mode press Ctrl+F5 or click Debug->Start/Stop Debug Session menu.  
<End of 5.1.2 Rotating Stepper Motor [two direction with LCD]>
 
...till next post bye-bye & take care.

No comments:

Post a Comment