Pages

Wednesday, March 31, 2010

undrstanding the stepper motor programming

As you have seen that the initial value is taken as 66
This is because of the following reasons 1)66 can be written as 0110 0110 ;
Hence either p1.0-p1.3 is utilized or p1.4-p1.7 giving the same result .
Among the four connections of stepper except the two red wires connected with Vcc.Two pins at a time should be 0 and other two should be 1.
i.e. The program written above would give 1) 0110 0110 2) 0011 00113) 1001 1001 4)1100 1100 5) 0110 0110  you can check the result by multimeter

stepper motor control or driving

To know about the connection click on the following -circuit diagram for beginners
http://www.electro-tech-online.com/attachments/general-electronics-chat/30993d1246553037-stepper-motor-wiring-breadboard-uln2803et-step.jpg



1>usb stepper motor controller
2>stepper motor control using uln2003 diagram












                                                                                         links:-http://www.datasheetcatalog.com/datasheets.../ULN2003.shtml

stepper motor : an introduction

stepper motor is the motor moves in steps .
where the steps are being measured in angles viz. 1.5 degree or likewise.


it's of three types . but only two finds application  today are 1)PM-permanent magnet stepper motors
2) hybrid stepper motors

 PM steppers are of low cost ,low performance meaning that they produce much low torque.
Hybrid steppers are the best of three widely used today..-high cost,good performance.
for more details you must go through the following links:
1) http://en.wikipedia.org/wiki/Stepper_motor

2) stepper motor system basics

3)http://www.motiongroup.com/steppermotors_basics.shtml

stepper motor programming (assembly language)

org 0
mov a,#66h
back:
mov p0,a
rr a
acall delay
sjmp back
delay:
mov r2,#100
h1:
mov r3,#255
h2:
djnz r3,h2
djnz r2,#h1
ret
end


Having problem with the program?? plz click on the following
undrstanding-stepper-motor-programming.

Monday, March 22, 2010

MOBILE COMMUNICATION BY SCHILLER

MOBILE COMMUNICATION BY SCHILLER

Toshiba Satellite E205-S1904: Cool 'Wi-Di' Capability, Good Display, Terrible Ergnomics

APPLE I-PAD PPT

Hey!  click HERE to get ppt. on I-pad

http://www.box.net/shared/55mmof7cn7

APPLE I-PAD PPT

Hey!  click HERE to get ppt. on I-pad

http://www.box.net/shared/55mmof7cn7

Friday, March 19, 2010

Thursday, March 18, 2010

Tuesday, March 16, 2010

SERVOMOTOR CONTROL PROGRAM


Picservo Fig 4


Picservo Fig 2


1490 Digital Compass

Servomotor Control Program

In our first program , wewill simply sweep the servomotor from CCW to CW and then sweep back.The program will be kept simple as to demonstrate the priniciples ofcontrolling a servo with a the PIC Basic language. The schematic can beseen in figure 2 (below).


Thevariable pw controls the pulsewidth, and is started at 100 (extremeleft, -45 degrees). The program sends the pulse out to the servo, andthen is increased by a value of 1 until it reaches 200 (extreme right,45 degrees), at which point it will reverese the rotation.

Listing 1

' First servomotor program
' Sweeps left to right, then reverses
Symbol B1 = pw
pw = 100
sweep: pulsout 0,pw
pause 18
pw = pw + 1
if pw > 200 then back
goto sweep
back: pulsout 0,pw
pause 18
pw = pw - 1
if pw < 100 then sweep
goto back


' create a variable pw
' start at extreme left
' send pulse to motor
' set frequency to about 50 Hz
' increase pw by 1
' at extreme right, turn CCW
' otherwise, continue
' send pulse to motor
' set frequency to about 50 Hz
' decrease pw by 1
' at extreme left, turn CW
' otherwise, continue

End of Listing 1

Ifdesired, we could extend the rotation of the servomotor to a full 180degrees (-90 to 90 degrees) rotation by decreasing the minimumpulsewidth to below 1 ms and increasing the maximum pulsewidth to over2 ms. This can be accomplished with our previous program by modifyingthe occurances of 100 and 200 to your desired minimum and maximumpulsewidths, respectivly.
However, a note of caution: thepulsewidth required for servos varies from brand to brand. One motormay require a 2.8 ms pulsewidth for maximum rotation, while another mayonly need 2.4 ms.
Furthermore, servomotors have end stopsthat limit its rotation. If you send the motor a pulsewidth that isbeyond the end stops, the motor will keep trying to turn. A motor inthis stalled condition not only draws more current, but also puts wearon the internal gears, shortening the lifespan of the motor.

Manual Servo Control

Our next program will allow youto control the direction of the servo manually via a SPDT switch (witha center-off position) connected to ports B1 and B2. Without acenter-off position, you will have to use two switches. A schematic isshown in figure 3 (below).


Withthe switch in the center position, the servo will not turn. When it ismoved into forward, it will turn one way. Moving the switch down willmake it turn the opposite direction. This program as-is will limitrotation to 45 degrees off-center, but can be modified to extendrotation through the aforementioned methods.

Listing 2

' Manual control of servo direction via
' an SPDT switch.
Symbol B1=pw
pw = 150
check: if pin1 = 0 then left
if pin2 = 0 then right
Pulsout 0,pw
pause 18
goto check
left: pw = pw + 1
pulsout 0,pw
pause 18
if pw > 200 then max
goto check
right: pw = pw - 1
pulsout 0,pw
pause 18
if pw < 100 then min
goto check
max: pw = 200
goto check
min: pw = 100
goto check


' create a variable pw
' begin at center position
' is pin 1 active?
' is pin 2 active?
' send current pw
' set frequency to about 50 Hz
' check again
' increase pulsewidth
' send current pw
' set frequency to about 50 Hz
' dont go over 2 ms
' go back and check again
' decrease pulsewidth
' send current pw
' set frequency to about 50 Hz
' dont go under 1 ms
' check again
' cap pw at 2 ms
' check again
' cap at 1 ms
' check again

End of Listing 2

Multiple Servomotors

Using a modified version of thelast program, we can control as many servomotors as we have I/O lineson port B. In the next listing, we will control two servos in the samemanner as we controlled a single servo in the previous program. Thecircuit is shown in figure 4 (below).


Theprogram uses two pulsewidth variables, pw1 and pw2; and two sets ofroutines, left1 and left2, right1 and right2; one for each motor. Asyou can see in the schematic, the first servo is wired as per theprevious circuit. The second servo is now using B3 as it's pulse out,and B4 and B5 for the SPDT switch.

Listing 3

'Manual control of two servomotors using 2 SPDT switches
'Use B1 to hold pulsewidth variable for servo 1
'Use B2 to hold pulsewidth variable for servo 2
'Initialize Variables
B1 = 150
B2 = 150
'start servo 1 at center position
'start servo 2 at center position

start:
   IF pin1 = 0 Then left1
   IF pin2 = 0 Then right1
   IF pin4 = 0 Then left2
   IF pin5 = 0 Then right2
   PulsOut 0, B1
   PulsOut 3, B2
   Pause 18
   GoTo start
'check for switch closures
'is sw1 left active?
'is sw1 right active?
'is sw2 left active?
'is sw2 right active?
'send current servo 1 position out
'send current servo 2 position out

'Routines for Servomotor 1
left1:
   B1 = B1 + 1
   PulsOut 0, B1
   PulsOut 3, B2
   Pause 18
   IF B1 > 225 Then max1
   GoTo start
right1:
   B1 = B1 - 1
   PulsOut 0, B1
   PulsOut 3, B2
   Pause 18
   IF B1 < 75 Then min1
GoTo start
max1:
   B1 = 225
   GoTo start
min1:
   B1 = 75
   GoTo start


'increase the pulse width
'send current B1
'send current B2
'set frequency update about 50 hz
'maximum 2.25 millisecond


'decrease the pulse width
'send current B1
'send current B2
'set frequency update about 50 hz
'minimum .75 millisecond


'cap max B1 at 2.25 milliseconds


'cap min B1 at .75 millisecond

'Routines for Servomotor 2
left2:
   B2 = B2 + 1
   PulsOut 0, B1
   PulsOut 3, B2
   Pause 18
   IF B2 > 225 Then max2
   GoTo start
right2:
   B2 = B2 - 1
   PulsOut 0, B1
   PulsOut 3, B2
   Pause 18
   IF B2 < 75 Then min2
   GoTo start
max2:
   B2 = 225
   GoTo start
min2:
   B2 = 75
   GoTo start


'increase the pulse width
'send current B1
'send current B2
'set frequency update about 50 hz
'maximum 2.25 millisecond


'decrease the pulse width
'send current B1
'send current B2
'set frequency update about 50 hz
'minimum .75 millisecond


'cap max B2 at 2.25 milliseconds


'cap min B2 at .75 millisecond



End of Listing 3

Catalog Page for PIC Microcontrollers
(a kit containing all necessary parts is available)
Catalog Page for Servo Motors

 

robotic air muscle actuator (biorobotics)



Biorobotics - Build Your Own Robotic Air Muscle Actuator

Anair muscle is a simple pneumatic device developed in the 1950's by J.L.McKibben. Like biological muscles, air muscles contract when activated.Robotists find it interesting that air muscles provide a reasonableworking copy of biological muscles. So much so that researchers can usea human skeleton with air muscles attached to the skeleton at primarybiological muscle locations to study biomechanics and low level neuralproperties of biological muscles. (See Internet sources)


SIN-COS Compass Resolution
Thisfeature is utilized by the research in many "Bio-Robotics" projectsinstitute by numerous researchers. In published papers air muscles arealso referred to as; McKibben Air Muscles, McKibben PneumaticArtificial Muscle, Rubbertuator and as I refer to them simply as airmuscle(s).

Applications

Air muscles haveapplications in robotics, biorobotics, biomechanics, artificial limbreplacement and industry. The principle reasons experimenters andhobbyists will like air muscles are ease of use (as compared tostandard pneumatic cylinders) and simple construction. Air muscles aresoft, lightweight and compliant, have a high power to weight ratio(400:1), can be twisted axially and used on unaligned mounting andprovide contractive force around bends, (see robot wars near the end ofthis article). Air muscles may also be used underwater.

How Air Muscles Work

TThere are two primary componentsto the air muscle are a soft stretchable inner rubber tube and abraided polyester mesh sleeve, see Figure 1. The rubber tube is calledan internal bladder and is positioned inside the braided mesh sleeve.


SIN-COS Compass Resolution
Figure 1
Allthat is left to complete the air muscle picture is an air fitting onone end and two mechanical fittings (loops) on each end of the airmuscle that allow one to attach the air muscle to devices. The clampsin Figure 1 are made from 24-gauge wire tightly wrapped and twistedaround the ends of the air muscle.
When the internalbladder is pressurized it expands and pushes against the inside ofbraided mesh sleeve, forcing the diameter of the braided mesh toexpand. The physical characteristic of the mesh sleeve is that itcontracts in proportion to the degree its diameter is forced toincrease. This produces the contractive force of the air muscle.
Tooperate properly, it is important that the air muscle be in a stretchedor loaded position when it's inactive or in a resting state. If notthere will little if any contraction when activated. So the air musclemust be stretched in order for it to produce contraction when it isactivated, see Figure 2. Typically the air muscle can contract toapproximately 25 percent of its length.
The illustrationof the contracted air muscle in figure 2 is greatly exaggerated. Whenthe air muscle contracts, its diameter thickens equally along it'slength and contracts (shortens) as described. Air muscles typically donot develop a large bulge in the center when it is contracted, howeverfor purposes of illustration we will shown it this way.




SIN-COS Compass Resolution
Figure 2

Air Pressure

Airmuscles require a source of compressed gas (usually air). The airmuscle we will build operates at approximately 50 psi. Air pressure canbe generated by the easiest mean available to the experimenterincluding a small bicycle pump with an air pressure gauge. Aninexpensive automobile tire air pump that operates using 12 VDC. Othersources are a small air tank that can be filled up at a local gasstation that has an air pump for inflating automobile tires. If you usean air tank make sure it is equipped with an adjustable air pressureregulator, this will prevent pressurizing the air muscle with too muchair.

Making an Air Muscle

Air muscles are availablecommercially from Shadow Robotics in the U.K. in a variety of sizes.For experimental purposes its pretty easy to make your own air musclein whatever size you require.
The inner tube is made from soft silicone tubing, approximately ¼"OD and 1/8" ID, see suppliers index. Go to a local pet shop that sellsaquarium supplies. Purchase a small quantity of PVC clear tubing. (Samesize as the silicone tubing, but less flexible and tougher) Pick up afew aquarium air valves and couplings too.
Many electronic distributors sell the polyester braided mesh sleeve.The braided sleeve is used as a flexible conduit for electrical wiring.Purchase a small quantity (6 feet) of 3/8" diameter.
Finish the materials purchase with a few 3/8" long 10-24 screws anda small quantity of 24 gauge galvanized wire available at a localhardware store.
Cut a 4-inch length of silicon tubing. Insert the 10-24 screw in oneend of the tube. Insert an aquarium air coupling in the other end ofthe tube, see Figure 3.


SIN-COS Compass Resolution
Figure 3
Cut a 7 inch length of 3/8" braided mesh sleeve. To prevent the ends ofthe sleeve from fraying and coming apart we singe the ends with a matchor candle flame, see Figure 4. The idea here is to just singe the endsof the polyester sleeve, its easy to go too far and melt too much ofthe sleeve. In that case cut another piece and start over.

SIN-COS Compass Resolution
Figure 4
Insertthe rubber tube inside the braided sleeve. Align one end of the sleevewith the bottom of the head on the 10-24 screw in the rubber tube. Wrapa piece of 24-gauge wire three or four times around the end, capturingthe sleeve, tubing and threaded portion of the 10-24 screw. Then twistthe ends of the wire together. Use a pair of pliers to make this astight as possible. Cut of any excess wire. See Figure 5.

SIN-COS Compass Resolution
Figure 5
Tofinish the other side, push down the sleeve until it is aligned withthe rubber tube on the air coupling. Wrap a piece of 24-gauge wirearound this end, tighten wire with pliers then cut off any excess wire.See Figure 6. At this point you may want to pressurize the air muscleto insure the two fittings do not leak. Since the air muscle is notloaded only use a pressure of 20 psi. If any air leaks, try tighteningthe 24-gauge wire.

SIN-COS Compass Resolution
Figure 6
Cuttwo 14-inch lengths of the galvanized wire. These we will use to makethe mechanical loops. Fold the wire in half to double. Form a 1-inchloop from the middle of the wire and twist the wire at the bottom ofthe loop, see figure 7. Next wire wrap the loop to the end of the airmuscle as shown in figure 8. Do the same to the other side. Pull on theloops to insure that they are secure.

SIN-COS Compass Resolution
Figure 7
SIN-COS Compass Resolution
Figure 8

Testing the Air Muscle

Thefirst test to perform is a simple static test. Wear eye protection whenpressurizing the air muscle. Attach one end of the air muscle to astationary object using the loop. At the other end hang about 5-6 lbs.of material to the air muscle using the other loop. This weight willload the air muscle (cause the air muscle to stretch). Pressurize theair muscle with approximately 50-psi. The air muscle should contractand easily lift the weight. While pressurized, listen for any airleakage. Repair any air leak, by tightening the 24-gauge wire.

First Mechanical Device

This first device illustrations the function and measures thecontract obtained with the air muscle, see figure 9. The air muscle ismounted to a piece of 1" x 2" lumber approximately 16" long. One end ofthe air muscle loop is looped over a wood screw secured into the wood.A thick rubber band is looped through the air muscle loop on the otherend. The rubber band is pulled until the air muscle is just fullyextended. Do not extend or pull the rubber band any further as thiswill just added additional resistance to the air muscle and notcontribute to its function. A woodscrew is secured into the wood atthis point and the rubber band is looped over the screw. When youpressurize the air muscle you can measure its contraction. Release theair pressure from the muscle and it should extend into its relaxedposition.


SIN-COS Compass Resolution


Figure 9

Second Mechanical Device

Alever is a simple mechanical device. A mechanical drawing is shown infigure 10 and photograph of a lever is shown in figure 11. Activatingthe air muscle causes the lever to rise. In the lever we are using anumber of rubber bands to load the air muscle.


Figure 10
Compass component


Figure 11
Compass component
Figure 12 illustrates how two air muscles may be configured to provide a counter force or load for each other.


SIN-COS Compass Resolution
Figure 12

Controlling the Air Muscle

Typically 3-way air valves are used to control the air muscle see figure 13.
Toactivate the air muscle, valve labeled #2 is opened. This causes theair muscle to contract. Once activated the #2 valve may be closedwithout impacting on the state of the air muscle. The air muscle staysin a contracted state. To relax the air muscle, the air pressure mustbe vented by opening valve labeled #1.

SIN-COS Compass Resolution
Figure 13

Electronic Control System

Athree-way stopcock air valve may be purchased, see figure 14. Thestopcock air valve allows you to control the air muscle manually. Athree-way valve may be simulated or constructed using two one-way airvalves. Small plastic aquarium valves purchased at a local pet shophave work quite well. However they are not rated for work at 50 psi andthat's a good reason to wear eye protection, just in case they popapart from the air pressure.

SIN-COS Compass Resolution
Figure 14


Usingmanual valves are fine for testing air muscles, to build a robot orindustrial device we must provide a way for electronic control.Fortunately this is not difficult. There are a number of solenoid airvalves available. I prefer the Isonic valves from Mead Fluid Dynamics.These are 3-way air valves that are activated using 5 Volts see Figure14.
The 3-way Isonic values automatically vent the airmuscle (through the back) when it is deactivated. To see how thisparticular valve works look back to figure 13, in the Isonic valve, thevalve labeled #1 is normally open, this is the vent, through the backof the valve. The valve #2 is normally closed, this is labeled "In" onfigure 14. The air stream to the air muscle is labeled "Out" in figure14. When the electronic valve is activated valve # 2 opens allowing airpressure to the air muscle and valve #1 closes. When deactivated eachvalve changes state; valve #1 opens, venting the air muscles airpressure and valve #2 closes separating the air supply from the airmuscle.
The front of the Isonic air valve has two quickconnects-disconnects for air tubing. This particular air valve connectshandles semi-ridge 4mm tubing, which is a good size for running air tothe air muscle. To use the quick connect simply push the air tubinginto the hole, it will lock in. To disconnect, hold the valve flange tothe valve body with your fingers and pull the tubing out.
MulitpleIsonic air valves may also be mounted onto a common manifold that makemaking multiple air muscle control that much easier.
Figure 15 is a simple manual control schematic for a 5-volt control circuit for the Isonic valve.
SIN-COS Compass Resolution
Figure 15

Going Further

Using pressurized air is aninconvenience, but one that may be overcome. For instance at CaseWestern Reserve University a team of faculty and students are buildinga cricket micro-robot that utilizes air muscles for walking andjumping. The micro-robot will walk and jump just like its biologicalcounterpart. What makes this project so interesting is that themicro-robot is no larger than 5 cm (2 inches) in any dimension. Topower the air muscles the team made a micro-pump that supplies 35 psifor the muscles.

Robot Wars

Many ofthe robots used in the Robot Wars series use pneumatic devices andflippers to over turn competitive robots. It is quite conceivable tosubstitute air muscles for pneumatic cylinders in these robots andthereby improve the strength to weight ration. In addition alignmentfor these flexible pneumatic devices are very forgiving. Therebyallowing the builder an easier construction since the robot may bebuilt with far more open tolerances.
Internet WEB Sites to visit for more information on air muscles are:
Cricket Micro-robot
http://biorobots.cwru.edu/projects/c_mrobot/c_mrobot.htm
Construction of McKibben Artificial Muscles:
http://brl.ee.washington.edu/Research_Past/Biologically_Based/Device_01_McKibben/Mckibben_Costruction.html
Powered Prosthetics Project:
http://brl.ee.washington.edu/Research_Past/Biologically_Based/Project_02_Prosthetics/Powered_Prosthetics.html
Pneumatic Robot Home Page:
http://www.ks.uiuc.edu/Research/Neural/robot.html
Anthroform Arm Project:
http://brl.ee.washington.edu/Research_Past/Biologically_Based/Project_01_Arm/Anthroform_Arm.html

Suppliers Index:

Soft Silicon tubing PN# 75-300-016

Barnant Company
Dept 77-3397
Chicago, IL 60678-3397
847-381-7050 Telephone

Local Suppliers:

polyester braided mesh, air tubing, air valves, air couplings, 24 Gauge galvanized wire

Manual Electric Control:

5VDC Mead Isonic three way solenoid air valve
10K ¼ watt resistor
220 ohm ¼ watt resistor
Push Button Switch (Normally Open)

Commercial air muscles available from:

Images Company U.S. 718-966.3694
Shadow Robot Group U.K. 44 207700 2487
 

how to do the microservomotor programming

here u will see find all the details regarding microsevomotor use...
plz click on the following link.


microservomotor program

HAPPY NEW YEAR

आप सब देशवासियों को भारतीय नव सृष्टि संवत्सर १,९६,०८,५३,१११ ( एक अरब , छियानवे करोड़ , आठ लाख , तरेपन हज़ार , एक सौ ग्यारह ) वें वर्ष में प्रवेश करने पर बहुत बहुत शुभकामनायें और बधाई. = विक्रम संवत्सर २०६७. चैत्र शुक्ल प्रतिपदा मंगलवार  . तदनुसार १६ मार्च ईस्वी सन  २०१०.

THE SYSTEM THAT DIVIDES CHINA

Growing popular pressure pushes for deep reform of the Chinese household registration, or hukou, system.

By Carl Minzner


The language was blunt; the tone direct. "We hope that decades of Chinese government maladministration can end with this generation. . . . Let the next generation enjoy the sacred constitutional guarantees of freedom, democracy and equality."



A press statement by overseas Chinese dissident groups? A human rights report by the U.S. State Department? No. This was a unique joint editorial published March 1 by 13 independent-leaning Chinese media outlets, spread across 11 provinces and cities, in the lead-up to the annual session of the national legislature, which concluded Sunday. The target of their criticism: the Chinese household registration, or hukou, system. The editorial is but one sign of the growing popular pressure for deep reform of the system.



Established in the 1950s, the household registration system originally served Maoist goals of population control and state economic planning. It locked Chinese citizens to a particular place of residence. It classified them as urban or rural, agricultural or nonagricultural. And it granted preferential treatment -- on food rations, housing and education -- to urban industrial workers.



Post-1978 economic liberalization has eroded many of these restrictions, such as travel. As anyone who has ever attempted to shove their way onto an overcrowded train in China during the Lunar New Year travel season can attest, average Chinese citizens enjoy (and exercise) massive freedom of physical movement throughout the country.



But residency status remains tightly linked to a range of rights and privileges, particularly urban social benefits. Most rural migrants to Chinese cities are unable to obtain equal public services such as healthcare and schooling for their children. And because residency status is hereditary, with limited channels to change one's status, this disparity risks hardening into a permanent divide. Generations of migrant children born and raised in Chinese cities might grow up as a legally excluded urban underclass.



MORE AT  http://www.latimes.com/news/opinion/la-oe-minzner16-2010mar16,0,4178259.story

AUTONOMOUS CAR PARKING


Autonomous Parallel Parking RC Car
Arjun Nagappan (asn28)
Arjun Prakash (asp36)

Introduction

We created an RC Car that can identify a parking space and parallel park by itself. The RC Car drives down a street searching for a parking space to its right using a distance sensor. When the car has identified a space, the car checks to see whether that space is large enough to park in. If it determines that there is sufficient space, the car will begin parallel parking into that space. It uses information from sensors placed on the front, right, and rear of the car to direct the car into the parking space. Once the car has parked, it will remain in that position until it is reset.

High Level Design

Rationale
Logical Structure
Hardware/Software Tradeoffs

Rationale

After discussing various project ideas, we eventually stumbled onto the subject of cars. So we started brainstorming possible projects related driving. When brainstorming, we saw something in the ECE lounge that reminded us of a garage. This led us to parking. Parallel parking is something that many drivers struggle with, yet there are very few tools available to help with parallel parking. Though a few auto manufacturers have developed systems that can parallel park cars autonomously, these solutions are very expensive. We thought this would be both a fun and interesting problem to tackle using an RC Car as a proxy for a real car.

Logical Structure

Our project is broken down into two major components: the control system and the move car algorithm. The move car algorithm directs the car and the control system implements the directions of the move car algorithm.



Figure 1: Logical Structure of High Level Design

Control System

The control system contains all the hardware and its associated software. It allows the parking and parking detection algorithms to interface with the car. The software in this module is broken up into three major sections: the Left-Right/Front-Back (LR/FB) state machines, master state machine, and distance calculations. The LR/FB state machines determines which direction to move the car based on flags set by the detect parking space and park car algorithms. Once the LR/FB state machines decides which direction to move the car, the master state machine implements this movement by sending the correct input and enable signals to the H-Bridge. The distance calculations implemented independently every millisecond.

Move Car

Move car contains the detect parking space and parallel parking algorithms. All functions in move car interface with the control module by setting movement flags. The parking space detection and parking algorithms use information from the distance sensors to set these movement flags and guide the car.

Move car works by initializing the movement flags of the car. It sets the car on a default trajectory and then calls detect parking space. Once a parking space has been detected, the parking algorithm is called. After the car has successfully parked, it idles until it is reset.

Hardware/Software Tradeoffs:

Distance Sensors

1. When selecting infrared distance sensors there was always a tradeoff between the sensors ability to measure close range and long range. We tried to minimize this problem by using sensors designed for varying ranges.

2. Using accurate sensors cost significant time. Every measurement from our distance sensors is approximately 40ms delayed. This affected our ability to start and stop the motors of the car at the correct times.

3. We used integer calculations rather than floating point to calculate distances. We decided the increased accuracy would not significantly improve our ability to park the car because we cannot control the movement of the car with that degree of accuracy.

4. Each sensor draws a maximum of 50mA. To accommodate for this, we needed to use a 5v regulator that could source up to 1A.

Batteries

1. We decided to power our car using batteries rather than using a steady power source. This gave us increased mobility but was very inconsistent in the current it supplied to the motors. As the batteries wore out, they supplied less and less current to the motors. This made calibrating the velocity of the car very difficult.

2. In order to best utilize the mobile power resources we have, we power the motors using four AA batteries, which are stored in the battery compartment of the RC car. These batteries supply the Supply Voltage to the H-bridge, which in turn powers the motor. We use a 9V battery to power the PCB.

Software

1. 1. Our code requires the motor control software, parking algorithm software, and distance sensor software to run in parallel. However, this is not possible in the Atmega644. We got around this issue by making every important task a state machine. By breaking up each function into small pieces, we can execute one piece of function one, then one piece of function two, followed by one piece of function3, and then another piece of function one, etc. This enables us to emulate a multi-tasking architecture.

Hardware

RC Car
H-Bridge
Distance Sensors

Hardware consists of three main components:

· RC Car

· H-Bridge

· Distance Sensors

All hardware used the following color convention:

Color Connected To

Red Vss

Green Ground

Purple Input

Yellow Output

Orange Enable

Table 1: Wire Color Convention

RC Car

The first step of our hardware design involved fully understanding the mechanics our RC car. We took apart the car and rebuilt it multiple times to fully understand how it was built, what every part in the car is used for, and how those parts contribute to the control of the car.

After understanding the mechanics of the car, we decided the easiest way to control our car would be to directly control the inputs to the DC brush motors controlling the front and rear wheels, bypassing all of the car’s internal circuitry. To do this, we scoped the control signals of the car. We found that the control signals were very simple. There is one motor for the reverse and forward movement of the rear wheels and one motor to turn the front wheels left and right. These motors are controlled by a simple 5V DC input. A +5V turns the rear wheels forward and the front wheel to the left. A -5V input turns the rear wheels backwards and turns the front wheels to the right. To more easily control the motors we soldered wires to their plus and minus terminals. This allows us to easily apply a +/-5V without opening up the car again.

H-Bridge

We use an ST Micro L298HN H-Bridge to control the motors of the RC Car. It allows us to switch between +/-5V across the motor. It also allows us to source the power from the batteries while using the processor to control the transistors in the H-Bridge. The control algorithm turns the appropriate transistors on/off, applying the proper voltage across the brush motor. The H-Bridge is connected using the following configuration:



Figure 2: H-Bridge Schematic

The first H-Bridge (to the left) is used to control the front motor of the car. This motor turns the front wheels either left or right. The second H-Bridge (the the right) is used to control the rear motor, which is used for the forward and reverse functionality of the car. The inputs and enables of the H-Bridge are connected to port B.

Front Motor (Left/Right) Rear Motor (Forward/Reverse)

Pin Connected To Pin Connected To

In 1 Port B7 In 3 Port B3

In 2 Port B6 In 4 Port B2

En A Port B5 En B Port B1

Out 1 + Motor Terminal Out 3 + Motor Terminal

Out 2 - Motor Terminal Out 4 - Motor Terminal

Table 2: H-Bridge Pin Configuration

In addition configuring the H-Bridge to control the motors, we also had to protect the H-Bridge from inductive spikes caused by turning the DC brush motors on and off. We used diodes on the output to protect from these spikes. The H-Bridge was wired as follows:



Figure 3: Inductive Current Protection on H-Bridge Outputs

Distance Sensors

We used three Sharp infrared distance sensors to determine the distance between our car and nearby objects. We placed a sensor on the front, the right side, and the rear of the car. For the front and rear, we used 4-30cm sensors. For the right side, we used we used a 10-80cm sensor. We decided to use a sensor with a larger range for the side so that we could more easily detect a parking space. However, this made aligning the parking the car more difficult, so we rely more heavily on the front and rear sensors to park the car. To slightly improve the short distance range of our sensors, we placed the sensors as far back on the car as possible.

The challenge with using these sensors is that their voltage output is nonlinear (inverse function) and each sensor varies slightly. Therefore, we scoped the output of each sensor at various distance values, linearized the plot, curve fit the line, and implemented an analog to digital conversion so that we had reliable distance values.

Measurements and Linearization

Distance (cm) Front Sensor Output (V) Rear Sensor Output (V)

4 2.78 2.6

5 2.36 2.22

6 2.06 1.92

8 1.6 1.52

10 1.32 1.26

12 1.12 1.08

15 .92 .88

18 .776 .76

21 .664 .656

24 .567 .576

27 .536 .52

30 .476 .48

Table 3: Front and Rear Sensor Measurements





Figure 4: Front Sensor Plots of Distance vs. Voltage and Distance-1 vs. Voltage





Figure 5: Rear Sensor Plots of Distance vs. Voltage and Distance-1 vs. Voltage

After taking the inverse of the distance versus voltage plots, we determined it would be best to fit the curve using two linear lines rather than one. The equations of the lines are:

Front Sensor Rear Sensor

voltage=9.759*[1/distance]+0.381, >1.5V voltage=8.963*[1/distance]+0.395, >1.25V

voltage=12.738*[1/distance]+0.057, <1.5V voltage=11.806*[1/distance]+0.09, <1.25V

Table 4: Front and Rear Distance Sensor Equations

The analog to digital conversion uses a different equation depending on the value of the measure voltage. If the measured voltage is above a certain threshold, the ADC will use the equation in the top row. If it is below a certain threshold, the ADC will use the equation in the bottom row. The threshold for the front sensor is 1.5v and 1.25v for the rear sensor.

Distance (cm) Side Sensor Output (V)

10 2.28

15 1.64

20 1.28

25 1.08

30 .808

35 .728

45 .672

50 .612

55 .556

60 .516

65 .488

70 .452

75 .432

80 .42

Table 5: Side Sensor Measurements





Figure 6: Rear Sensor Plots of Distance vs. Voltage and Distance-1 vs. Voltage

When looking at the data for the 10-80cm side sensor plot, we determined that one linear line would be sufficient to accurately capture the output voltage vs. distance characteristics of the sensor. The equation of this line is:

voltage=21.592*[distance]^(-1)+0.173

Analog to Digital Conversion

For the analog to digital conversion we used the built in ADC function of the MCU. Because we had three distance sensors, we had to rotate which sensor was connected to the ADC. This was simply done by changing the value of ADMUX. One of the three sensors is sampled every millisecond.

We take the value from the ADCH register and perform the appropriate calculation to convert this value to a distance. We decided to use only the ADCH register because the value represented by the bottom two bits of the ADC is on the same order of magnitude as noise. Therefore, these two bits are not important to our calculation. To do this, the ADC is left adjusted. By using the value in the ADCH register, we are using the upper eight bits of the ten ADC bits. We use the internal reference voltage of 2.56V for comparison, so our calculation is:











Software

Control Module
Algorithm Module

The software for this project has been partitioned into 2 files based on functionality. There are 2 files, ControlModule.c and AlgorithmModule.c.

The state machines in ControlModule control the motors, and are:

· fbStateMachine

· lrStateMachine

· masterStateMachine

The state machines in the AlgorithmModule use the sensor data and various algorithms to determine what should be the next movement the car must make. They assert flags which tell the ControlModule state machines to actually move the motors. The state machines in AlgorithmModule are:

· moveCar

· detectParking

· parkCar

Below we have explained the various state machines we have used in our project.

Control Module

fbStateMachine()

Function:

The fbStateMachine controls the motor for Forward-Backward operations. It is controlled by the isForward and isReverse flags. These flags serve as indicators as to whether the car should be traveling forward or reverse. In order to control the velocity of the forward-backward motion we anded the enable bit with a a PWM signal.

Working:

In State 0, the motor is at rest. The corresponding FB control bits are 00. When the algorithm requires the car to go forward or reverse, the corresponding flags (isForward and isReverse) are set, and the FB state machine switches states to 1 or 3 respectively.

In State 1, the motor rotates to drive the car forward. The state machine remains in this state while isForward is equal to 1. Once isForward is de-asserted, the state machine moves to a buffer state to stop the car from moving forward due to inertia.

After isForward is set to 0, leaving state 1 and stopping the motor isn’t enough. The wheels might continue to rotate due to inertia, and so a buffer state, State 2, is required. It makes the motor go in Reverse for 1 cycle (50ms) of the FB State Machine, before going back to the rest state, State 0.

If isReverse is asserted, the state machine jumps to State 3. The state machine remains in this state while isReverse is equal to 1. Once isReverse is de-asserted, the state machine moves to a buffer state to stop the car from moving in reverse due to inertia.

After State 3, a buffer state, State 4, is needed to stop the wheels from continuing to rotate in reverse due to inertia. This is a 1 cycle Forward motion, similar in function to State 2’s reverse functionality. Once done, the FB State Machine goes back to its rest state, State 0.

Timing:

The fbStateMachine is called upon every 50ms. This is enough time to evaluate the flags set in the AlgorithmModule, but at the same time fast enough to make the motor motion very accurate.

lrStateMachine()

The lrStateMachine() works the same way are the fbStatemachine. A forward corresponds to a left turn and a right corresponds to a reverse. The diagram for both are:



Figure 7: FB/LR Motor State Machine

masterStateMachine()

Function:

This uses the FB and LR control bits to call the required functions in order to send the appropriate input signals to the H-Bridge and make the motors rotate in the appropriate direction.

Working:

In this function, the 2 FB and LR control bits are combined to create 4 master control bits by left shifting the FW bits by 2 and adding it to the LR bits.

Therefore,

fbBits = fb.controlBits; // (FB FB)

lrBits = lr.controlBits; // (LR LR)

masterBits = (fbBits<<2) + (lrBits); // (FB FB)(LR LR)

As a result, each of the 7 car movements (stop, forward, forward-left, forward-right, reverse, reverse-left, reverse-right) have a unique masterBits combination associated with them. The master control bits are then used in the function to decide which motor control function is to be called.

Timing

This state machine is invoked in each iteration of the infinite while loop in main. In other words, it can be considered to be executing continuously and not at intervals. This is essential because parking requires a great deal of accuracy when controlling the motors. Therefore, we want to update the motors as often as possible, which would require us to call masterStateMachine as often as possible.

Algorithm Module

moveCar()

Function:

This is the master state machine of the algorithm module. It decides which mode the car is in, i.e., whether the car is moving forward to detect a parking spot, aligning itself once a parking spot has been detected, or actually going through the motion of parking.

Diagram:



Figure 8: Move Car Motor State Machine

Working:

This is a 5 state linear state machine, as can be seen in the diagram above.

It starts off in State 0. In this state, the car is at rest. It gives enough time for all transients in the car to stabilize. Once everything is stable, it moves to State 1.

In State 1, car moves forward till it detects a parking spot. While in this state, the car invokes the detectParking state machine each time the moveCar state machine is called in the Control Module. Details of how the detectParking state machine works are explained in the next section.

Once a parking lot has been detected, the state machine moves into State 2. It remains in State 2 until the car has parked itself. The parkCar state machine is invoked for each cycle that the moveCar state machine is in State 2. Once the car has been parked by parkCar state machine, the isParked flag is asserted, and moveCar moves onto state 3.

When we reach State 3, the car parked itself. The car will eternally remain in this state hereafter, since the car has parked itself and is at rest.

In addition to serving as a state machine as described above, moveCar also makes available 2 values – rsDist and rrsDist – to its sub-state machines, detectParking and parkCar. rsDist stores the values of the side distance in the previous clock tick of the moveCar state machine, while rrsDist stores the value 2 clock cycles earlier.

Timing:

The moveCar state machine is invoked every 100ms. The moveCar state machine also serves as a clock for the detectParking and parkCar state machines. When in State 1, each clock tick of the moveCar state machine serves as a clock tick for the detectParking machine. When in State 3, each clock tick of the moveCar state machine serves as a clock tick for the parkCar machine.

detectParking

Function:

The function of detectParking state machine is, as its name suggests, to detect a parking space to park in. It accomplishes this by continuously polling the distance values from the side distance sensor.

Diagram:



Figure 9: Detect Parking Space State Machine

Working:

detectParking is a 6 state state machine, as can be seen in the diagram above.

State 0 serves as a start-up. This is essential because the first few cycles of the detectParking take place while the side distance sensor is still calibrating itself. Once the wait state is done, the state machine enters state 1.

State 1, essentially, searches for a sudden increase in the side distance value. A sudden increase corresponds to the beginning of a parking space. It does this by checking the (sDistance – rsDist) value. If there is a sudden depression, sDistance will increase and so it’s difference from its own previous value (rsDist) will be a large number. When this does occur, the state machine goes onto State 2.

In State 2 it attempts to confirm that it indeed is detecting a valid depression, by calculating (sDistance – rrsDist). Since State 2 is invoked 1 clock tick after the depression was last detected in State 1, rrsDist will store the value of the side distance before the depression began, i.e., from 2 clock cycles earlier. If (side distance – rrsDist) is still a large number, we can confirm that a depression has been detected, and we move to State 3.

In State 3, we keep track of how long the depression is. This is done by incrementing the detect.controlBits for each state machine clock tick that we are still in the depression. When there is a sudden decrease in the value of the side distance, we move to state 4, since it signals a probable end of the parking lot.

State 4 confirms that the possible end of the parking space, as detected in State 3, is indeed the end of the space. This is done in a manner similar to the confirmation done in State 2 using the rrsDist variable.

Once a parking space has been detected by the above states, the state machine moves into State 5 wherein it checks the control Bits (which kept track of how long the parking space was by incrementing for each cock tick while in the depression) to make sure the parking space is large enough. If large enough, then the isParkingLot flag is asserted which would direct moveCar to stop and start the parking sequence.

Timing

Each tick of the detectParking state machine corresponds to a tick of the moveCar function. When moveCar is in State 1, it calls detectParking on each of its ticks. Therefore, detectParking is called every 100ms until a parking space has been located.

parkCar()

Function:

The function of the parkCar state machine is to park the car once a parking spot has been identified. The algorithm to park the car continuously interacts with its surroundings through the forward, side and rear sensors.

Diagram:



Figure 10: Park Car State Machine



Figure 11: Parking Motion of Car, colors correspond to state of the Park Car State Machine

Working:

The parkCar function tries to simulate how a human would parallel park. It is, essentially, just the following 4 motions:

1. Reverse Right until you are inside the parking lot.

2. Go Forward and redo 1. if the car is not aligned.

3. Reverse Left until the car is fairly straight and close to the back wall.

4. Forward Right until the car is straight and close to the front wall.

The above routine is accomplished using a 7 state machine.

State 0 makes the car move forward by a certain amount. The idea is to give the car enough space to move and rotate into the parking space.

State 1 simply turns the front wheels to the right. We turn the wheel before reversing the car so as to not lose turning radius by turning as the car reverses. Once the wheel is turned, the state machine moves onto state 2.

State 2 commands the car to go reverse right for a specified amount of time until the car has passed the edge of the parking space. Once past the edge of the space, it moves to state 3.

In State 3, the car continues in reverse right until it is either a certain distance from inside of the parking space, or the rear distance is close to the edge. These conditions, as can be seen from the figure above, are checks to verify that the car is deep enough inside the parking lot to be able execute the reverse left maneuver. Once the conditions are met, the car stops and the state machine moves to state 4.

NOTE: If at any point in states 1, 2 or 3 the car’s AI decides it is not in a position to go through with the parking, it will go back to State 0, and redo the whole procedure.

In State 4, the car moves reverse left. It does this until the rear of the car is close to the side wall of the parking space, which can be judged by the rear distance sensor value. Once close enough to the rear value, it stops and moves to state 5.

State 5 commands the car to go forward right. This attempts to straighten out the car completely and to align it nicely inside the spot. It goes forward right until it is close to the side wall of the parking space, as judged by the forward distance sensor. Once aligned, the car is parked and it moves to state 6.

State 6 is a 1 cycle stop before progressing back to state 0. Also, here the isParked variable is set so that the moveCar state machine can move out of parking mode to rest mode.

Timing:

Each tick of the parkCar state machine corresponds to a tick of the moveCar function. When moveCar is in State 3, it calls parkCar on each of its ticks. Therefore, parkCar is called very 100ms while the car is being parked.

Misalignment Detection

Our parking algorithm is equipped with a Misalignment Detector. Its role is to judge whether the car can park itself in the given space, and if it judges that parking is impossible, to correct the car’s position to make it possible.

Our algorithm has a provision to keep track of the values of distance from the side sensor (sDIstance) from the earlier clock (rDist) and earlier 2 clock ticks (rrDist) of the state machine. Having these 2 values is extremely important to the successful working of the misalignment detector.

The detector works by checking how much sDIstance has changed over the last 2 clock cycles. If the change in sDistance is large, it means the car is not ideally positioned and it will set the park car state machine to the forward state. It will also define how long the car should remain in this state. This can be seen in the figure below:



Figure 12: Example of Misalignment Detection

What is beautiful about this whole setup is that this exactly how a human would park the car! If the driver realizes that he is not aligned well enough, he will go forward and try again.

Putting it All Together

If you have taken a look at the high level design described earlier in the code, and read the description of the state machines in the earlier section, you have all the information you need to understand how the software of the car works.

Essentially, the AlgorithmModule state machines are what set the flags to control the movement of the car. These flags are interpreted by the ControlModule state machines, and translate it into actual motor control.

Results of Design

Speed of Execution
Accuracy
Safety and Interference
Usability

Speed of Execution

Speed wasn’t a big issue for us. All components of the software were done as state machines.

The Motor Control state machines update at ticks every 50ms. This was ample time for the state machines to compute the necessary controlBits and assert the required inputs to the H-bridge. As a result, we were able to obtain highly accurate and sensitive responses from the motors to the control code.

The Algorithm Control state machines update at ticks every 100ms. This was enough time for the state machines to compute the necessary parameters, and to assert the necessary flags for the Control Module to interpret them and translate it into motor motion.

The response of the car to its surroundings is also very fast. The sensors have a response time of 20ms, which is quick enough for them to be processed in real time.

Accuracy

Distance Sensors

The sensors were very accurate within their specified range. Even with integer calculations, we were able to calculate distances with a +/- 1cm accuracy. Because we could not control the movement of the car with this degree of accuracy, the accuracy of our distance sensors are sufficient.

Parking Space Detection

The sequence to detect a parking space works very accurately. In the many trials that we performed, it always detected the parking space and stopped on detection.

Parking Algorithm

The parking algorithm we have written works very well when the car is close to a set distance from the side of the parking lot. It, however, becomes less accurate when the car is placed at larger distances from the parking space.

The parking algorithm we have written works very well when the car is close to a set distance from the side of the parking lot. It, however, becomes less accurate when the car is placed at larger distances from the parking space.

Safety and Interference

There were not many safety concerns with our project. In order to minimize disturbance to other project groups, and avoid the car colliding into students, we made a separate test area in the hallway. We used this test area for all testing purposes.

Also, since the car is completely autonomous, there was no human contact required (except for turning on the car). Therefore, there wasn’t an issue of interference with the systems in the car.

Usability

In our opinion, this project has tremendous potential. With some more work on the parking algorithm, we feel that we can develop a system for the RC car to park irrespective of its orientation and distance from the parking lot. With enough research, this can be developed for real cars!

It can also be used as a learning tool for people who want to learn driving. By observing the motion of this car, students can learn how to parallel park better.

Lastly, this project could serve as a useful reference point for future projects dealing with R/C cars. The Control Module we have implemented to control the R/C car can be used universally for any 2-wheel drive R/C car.

Conclusion

Standards, IP, and Legal
Ethical Considerations

Overall, we feel the project met most of our expectations, as we were able to build an autonomous car which could detect a parking space, and park in it. When we started out, we intended the car to be able to locate a parking spot, and park irrespective of its distance from the parking space and its orientation. We were, however, unable to make it robust enough to accommodate parking from different orientations and distances. However, we feel the basic algorithm would remain the same, and this algorithm can be built upon to accommodate these features.

This was also a tremendous learning experience for us, especially with the hardware. We learn a tremendous amount about motor control systems, efficient circuit design, and hardware debugging. We also learned a lot about software. Through this project, we got valuable experience in developing efficient software using memory and run-time optimizations, something that cannot be gained through routine assignments.

If we had an opportunity to start this project over, there are a few things we would do differently.

1. Use a regulator to ensure a steady current is being supplied to the batteries despite the fluctuation in voltage across the batteries, particularly as they lose power

2. Consider implementing an optical sensor to track the velocity of the car

3. Build a feedback PWM loop to control the velocity of the car

4. Consider adding a fourth sensor on the side to calculate the orientation of the car

5. Consider building the car ourselves

Standards, Intellectual Property, and Legal Concerns

There were no standards or regulations that concerned our project because we decided not to control the car using radio signals. There are also no concerns with intellectual property because we purchased the RC car and are only using it for personal use. All the software and other hardware was designed by us.

Ethical Considerations

We adhered to the IEEE Code of Ethics throughout this project. We were very careful to consider the effects of our decisions on us, those around us, and the outcome of our project. We took significant time to plan our project before implementing it. We wanted to ensure our car was designed in the best way possible, in terms of performance, reliability, and safety. We worked cooperatively with other people, seeking and providing feedback and constructive criticism from the professor, TA's, and other groups to build the best possible design.

We also set up a safe testing environment. In an area with high traffic, people could have easily stepped on the car and been hurt. We tested our car in a highly controlled environment to ensure everyone’s safety. We did not make any decisions that would cause harm to others or the environment.

In no circumstances did we give or accept bribes. All of our parts were either bought or sampled in the appropriate manner. We have been honest regarding the results and limitations of our design. We have worked hard to create the best design possible in the given time frame, and it is safe to operate. All people involved with this project were treated fairly.

Appendix

Commented Code
High Level Schematic
Parts List and Cost
Tasks
References

Appendix A: Commented Code

This link contains the source code for our project: Source Code

This link contain supplementary functions we wrote during the development of our project: Supplementary Code

Appendix B: High Level Schematic



Appendix C: Parts List and Cost

Part Number Cost

RC Car 1 $20

10cm-80cm Sharp IR Sensor (GP2Y0A21YK) 1 Free (Sampled From Sharp)

4cm-30cm Sharp IR Sensor (GP2D120XJ00F) 2 Free (Sampled From Sharp)

ST Micro H-Bridge (L298HN) 1 Free (Sampled from ST Microelectronics)

ATMEGA 644 1 Free (Sampled from Empire Technologies)

Custom PC Board 1 $4

Small Solder Board 1 $2

9V Battery 1 $2

AA Battery 4 $2

Headers 65 $3.25

Regulator (LM340T5) 1 Free (In Lab)

Screws and Spacers Free (In Lab)



Total $33.25

Appendix D: Tasks

Both of us contributed to all parts of the project, however we spent more time working on certain things.

· Design of Hardware: Nagappan

· Design of Control Algorithm: Both

· Design of Parking Algorithm: Prakash

· Testing of Hardware: Both

· Testing of Software: Both

· Compiling Report and Web Site: Both

Appendix E: References

Data Sheets

· http://document.sharpsma.com/files/gp2y0a21yk_e.pdf

· http://document.sharpsma.com/files/GP2D120XJ00F_SS.pdf

· http://www.st.com/stonline/products/literature/ds/1773/l298.pdf

· http://courses.cit.cornell.edu/courses/ee476/AtmelStuff/mega644full.pdf

· http://www.digchip.com/datasheets/download_datasheet.php?id=513599&part-number=LM340T5

Vendor Sites

· www.sharpmsa.com

· www.atmel.com

· www.st.com

Background Sites and Papers

· http://electronics.howstuffworks.com/rc-toy.htm

We would also like to thank Professor Land, Matt, and all the other TA’s for the help they provided us during this project



©2005 Cornell University



stepper motor programming

Software flow chart of Stepper Motor controller






Source code file of Stepper Motor controller




001

002

003

004

005

006

007

008

009

010

011

012

013

014

015

016

017

018

019

020

021

022

023

024

025

026

027

028

029

030

031

032

033

034

035

036

037

038

039

040

041

042

043

044

045

046

047

048

049

050

051

052

053

054

055

056

057

058

059

060

061

062

063

064

065

066

067

068

069

070

071

072

073

074

075

076

077

078

079

080

081

082

083

084

085

086

087

088

089

090

091

092

093

094

095

096

097

098

099

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

;********************************************************

;

; Stepper Motor controller

;

; Author : Seiichi Inoue

;********************************************************



list p=pic16f84a

include p16f84a.inc

__config _hs_osc & _wdt_off & _pwrte_on & _cp_off



;**************** Label Definition ********************

cblock h'0c'

mode ;Operation mode

;0=stop 1=right 2=left

count1 ;Wait counter

count2 ;Wait counter(for 1msec)

endc



rb0 equ 0 ;RB0 of PORTB

rb1 equ 1 ;RB1 of PORTB

rb2 equ 2 ;RB2 of PORTB

rb5 equ 5 ;RB5 of PORTB

rb7 equ 7 ;RB7 of PORTB



;**************** Program Start ***********************

org 0 ;Reset Vector

goto init

org 4 ;Interrupt Vector

clrf intcon ;Clear Interruption reg



;**************** Initial Process *********************

init

bsf status,rp0 ;Change to Bank1

clrf trisa ;Set PORTA all OUT

movlw b'00100111' ;RB0,1,2.5=IN RB7=OUT

movwf trisb ;Set PORTB

movlw b'10000000' ;RBPU=1 Pull up not use

movwf option_reg ;Set OPTION_REG

bcf status,rp0 ;Change to Bank0

clrf mode ;Set mode = stop

clrf count1 ;Clear counter

clrf count2 ;Clear counter

movlw b'00000101' ;Set PORTA initial value

movwf porta ;Write PORTA

bsf portb,rb7 ;Set RB7 = 1

btfsc portb,rb5 ;RB5 = 0 ?

goto $-1 ;No. Wait



start

;************* Check switch condition *****************

btfsc portb,rb1 ;RB1(stop key) = ON ?

goto check1 ;No. Next

clrf mode ;Yes. Set stop mode

goto drive ;No. Jump to motor drive

check1

btfsc portb,rb2 ;RB2(right key) = ON ?

goto check2 ;No. Next

movlw d'1' ;Yes. Set right mode

movwf mode ;Save mode

goto drive ;No. Jump to motor drive

check2

btfsc portb,rb0 ;RB0(left key) = ON ?

goto drive ;No. Jump to motor drive

movlw d'2' ;Yes. Set left mode

movwf mode ;Save mode



;******************** Motor drive *********************

drive

movf mode,w ;Read mode

bz start ;mode = stop

bsf portb,rb7 ;Set RB7 = 1

btfsc portb,rb5 ;RB5 = 0 ?

goto $-1 ;No. Wait

movlw d'5' ;Set loop count(5msec)

movwf count1 ;Save loop count

loop call timer ;Wait 1msec

decfsz count1,f ;count - 1 = 0 ?

goto loop ;No. Continue

bcf portb,rb7 ;Set RB7 = 0

btfss portb,rb5 ;RB5 = 1 ?

goto $-1 ;No. Wait

movf porta,w ;Read PORTA

sublw b'000000101' ;Check motor position

bnz drive2 ;Unmatch

movf mode,w ;Read mode

sublw d'1' ;Right ?

bz drive1 ;Yes. Right

movlw b'00001001' ;No. Set Left data

goto drive_end ;Jump to PORTA write

drive1

movlw b'00000110' ;Set Right data

goto drive_end ;Jump to PORTA write

;-------

drive2

movf porta,w ;Read PORTA

sublw b'000000110' ;Check motor position

bnz drive4 ;Unmatch

movf mode,w ;Read mode

sublw d'1' ;Right ?

bz drive3 ;Yes. Right

movlw b'00000101' ;No. Set Left data

goto drive_end ;Jump to PORTA write

drive3

movlw b'00001010' ;Set Right data

goto drive_end ;Jump to PORTA write

;-------

drive4

movf porta,w ;Read PORTA

sublw b'000001010' ;Check motor position

bnz drive6 ;Unmatch

movf mode,w ;Read mode

sublw d'1' ;Right ?

bz drive5 ;Yes. Right

movlw b'00000110' ;No. Set Left data

goto drive_end ;Jump to PORTA write

drive5

movlw b'00001001' ;Set Right data

goto drive_end ;Jump to PORTA write

;-------

drive6

movf porta,w ;Read PORTA

sublw b'000001001' ;Check motor position

bnz drive8 ;Unmatch

movf mode,w ;Read mode

sublw d'1' ;Right ?

bz drive7 ;Yes. Right

movlw b'00001010' ;No. Set Left data

goto drive_end ;Jump to PORTA write

drive7

movlw b'00000101' ;Set Right data

goto drive_end ;Jump to PORTA write

;-------

drive8

movlw b'00000101' ;Compulsion setting



drive_end

movwf porta ;Write PORTA

goto start ;Jump to start



;************* 1msec Timer Subroutine *****************

timer

movlw d'200' ;Set loop count

movwf count2 ;Save loop count

tmlp nop ;Time adjust

nop ;Time adjust

decfsz count2,f ;count - 1 = 0 ?

goto tmlp ;No. Continue

return ;Yes. Count end



;********************************************************

; END of Stepper Motor controller

;********************************************************



end







--------------------------------------------------------------------------------



Listing file of Stepper Motor controller



MPASM 02.50.02 Intermediate STEP.ASM 3-9-2001 23:52:45 PAGE 1





LOC OBJECT CODE LINE SOURCE TEXT

VALUE



00001 ;********************************************************

00002 ;

00003 ; Stepper Motor controller

00004 ;

00005 ; Author : Seiichi Inoue

00006 ;********************************************************

00007

00008 LIST P=PIC16F84A

00009 INCLUDE P16F84A.INC

00001 LIST

00002 ; P16F84A.INC Standard Header File, Version 2.00'(modify)

00134 LIST

2007 3FF2 00010 __CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF

00011

00012 ;**************** Label Definition ********************

00013 CBLOCK H'0c'

0000000C 00014 MODE ;Operation mode

00015 ;0=stop 1=right 2=left

0000000D 00016 COUNT1 ;Wait counter

0000000E 00017 COUNT2 ;Wait counter(for 1msec)

00018 ENDC

00019

00000000 00020 RB0 EQU 0 ;RB0 of PORTB

00000001 00021 RB1 EQU 1 ;RB1 of PORTB

00000002 00022 RB2 EQU 2 ;RB2 of PORTB

00000005 00023 RB5 EQU 5 ;RB5 of PORTB

00000007 00024 RB7 EQU 7 ;RB7 of PORTB

00025

00026 ;**************** Program Start ***********************

0000 00027 ORG 0 ;Reset Vector

0000 2805 00028 GOTO INIT

0004 00029 ORG 4 ;Interrupt Vector

0004 018B 00030 CLRF INTCON ;Clear Interruption reg

00031

00032 ;**************** Initial Process *********************

0005 00033 INIT

0005 1683 00034 BSF STATUS,RP0 ;Change to Bank1

0006 0185 00035 CLRF TRISA ;Set PORTA all OUT

0007 3027 00036 MOVLW B'00100111' ;RB0,1,2.5=IN RB7=OUT

0008 0086 00037 MOVWF TRISB ;Set PORTB

0009 3080 00038 MOVLW B'10000000' ;RBPU=1 Pull up not use

000A 0081 00039 MOVWF OPTION_REG ;Set OPTION_REG

000B 1283 00040 BCF STATUS,RP0 ;Change to Bank0

000C 018C 00041 CLRF MODE ;Set mode = stop

000D 018D 00042 CLRF COUNT1 ;Clear counter

000E 018E 00043 CLRF COUNT2 ;Clear counter

000F 3005 00044 MOVLW B'00000101' ;Set PORTA initial value

0010 0085 00045 MOVWF PORTA ;Write PORTA

0011 1786 00046 BSF PORTB,RB7 ;Set RB7 = 1

0012 1A86 00047 BTFSC PORTB,RB5 ;RB5 = 0 ?

0013 2812 00048 GOTO $-1 ;No. Wait

00049

0014 00050 START

MPASM 02.50.02 Intermediate STEP.ASM 3-9-2001 23:52:45 PAGE 2





LOC OBJECT CODE LINE SOURCE TEXT

VALUE



00051 ;************* Check switch condition *****************

0014 1886 00052 BTFSC PORTB,RB1 ;RB1(stop key) = ON ?

0015 2818 00053 GOTO CHECK1 ;No. Next

0016 018C 00054 CLRF MODE ;Yes. Set stop mode

0017 2821 00055 GOTO DRIVE ;No. Jump to motor drive

0018 00056 CHECK1

0018 1906 00057 BTFSC PORTB,RB2 ;RB2(right key) = ON ?

0019 281D 00058 GOTO CHECK2 ;No. Next

001A 3001 00059 MOVLW D'1' ;Yes. Set right mode

001B 008C 00060 MOVWF MODE ;Save mode

001C 2821 00061 GOTO DRIVE ;No. Jump to motor drive

001D 00062 CHECK2

001D 1806 00063 BTFSC PORTB,RB0 ;RB0(left key) = ON ?

001E 2821 00064 GOTO DRIVE ;No. Jump to motor drive

001F 3002 00065 MOVLW D'2' ;Yes. Set left mode

0020 008C 00066 MOVWF MODE ;Save mode

00067

00068 ;******************** Motor drive *********************

0021 00069 DRIVE

0021 080C 00070 MOVF MODE,W ;Read mode

0022 1903 2814 00071 BZ START ;mode = stop

0024 1786 00072 BSF PORTB,RB7 ;Set RB7 = 1

0025 1A86 00073 BTFSC PORTB,RB5 ;RB5 = 0 ?

0026 2825 00074 GOTO $-1 ;No. Wait

0027 3005 00075 MOVLW D'5' ;Set loop count(5msec)

0028 008D 00076 MOVWF COUNT1 ;Save loop count

0029 2062 00077 LOOP CALL TIMER ;Wait 1msec

002A 0B8D 00078 DECFSZ COUNT1,F ;count - 1 = 0 ?

002B 2829 00079 GOTO LOOP ;No. Continue

002C 1386 00080 BCF PORTB,RB7 ;Set RB7 = 0

002D 1E86 00081 BTFSS PORTB,RB5 ;RB5 = 1 ?

002E 282D 00082 GOTO $-1 ;No. Wait

002F 0805 00083 MOVF PORTA,W ;Read PORTA

0030 3C05 00084 SUBLW B'000000101' ;Check motor position

0031 1D03 283B 00085 BNZ DRIVE2 ;Unmatch

0033 080C 00086 MOVF MODE,W ;Read mode

0034 3C01 00087 SUBLW D'1' ;Right ?

0035 1903 2839 00088 BZ DRIVE1 ;Yes. Right

0037 3009 00089 MOVLW B'00001001' ;No. Set Left data

0038 2860 00090 GOTO DRIVE_END ;Jump to PORTA write

0039 00091 DRIVE1

0039 3006 00092 MOVLW B'00000110' ;Set Right data

003A 2860 00093 GOTO DRIVE_END ;Jump to PORTA write

00094 ;-------

003B 00095 DRIVE2

003B 0805 00096 MOVF PORTA,W ;Read PORTA

003C 3C06 00097 SUBLW B'000000110' ;Check motor position

003D 1D03 2847 00098 BNZ DRIVE4 ;Unmatch

003F 080C 00099 MOVF MODE,W ;Read mode

0040 3C01 00100 SUBLW D'1' ;Right ?

0041 1903 2845 00101 BZ DRIVE3 ;Yes. Right

0043 3005 00102 MOVLW B'00000101' ;No. Set Left data

0044 2860 00103 GOTO DRIVE_END ;Jump to PORTA write

MPASM 02.50.02 Intermediate STEP.ASM 3-9-2001 23:52:45 PAGE 3





LOC OBJECT CODE LINE SOURCE TEXT

VALUE



0045 00104 DRIVE3

0045 300A 00105 MOVLW B'00001010' ;Set Right data

0046 2860 00106 GOTO DRIVE_END ;Jump to PORTA write

00107 ;-------

0047 00108 DRIVE4

0047 0805 00109 MOVF PORTA,W ;Read PORTA

0048 3C0A 00110 SUBLW B'000001010' ;Check motor position

0049 1D03 2853 00111 BNZ DRIVE6 ;Unmatch

004B 080C 00112 MOVF MODE,W ;Read mode

004C 3C01 00113 SUBLW D'1' ;Right ?

004D 1903 2851 00114 BZ DRIVE5 ;Yes. Right

004F 3006 00115 MOVLW B'00000110' ;No. Set Left data

0050 2860 00116 GOTO DRIVE_END ;Jump to PORTA write

0051 00117 DRIVE5

0051 3009 00118 MOVLW B'00001001' ;Set Right data

0052 2860 00119 GOTO DRIVE_END ;Jump to PORTA write

00120 ;-------

0053 00121 DRIVE6

0053 0805 00122 MOVF PORTA,W ;Read PORTA

0054 3C09 00123 SUBLW B'000001001' ;Check motor position

0055 1D03 285F 00124 BNZ DRIVE8 ;Unmatch

0057 080C 00125 MOVF MODE,W ;Read mode

0058 3C01 00126 SUBLW D'1' ;Right ?

0059 1903 285D 00127 BZ DRIVE7 ;Yes. Right

005B 300A 00128 MOVLW B'00001010' ;No. Set Left data

005C 2860 00129 GOTO DRIVE_END ;Jump to PORTA write

005D 00130 DRIVE7

005D 3005 00131 MOVLW B'00000101' ;Set Right data

005E 2860 00132 GOTO DRIVE_END ;Jump to PORTA write

00133 ;-------

005F 00134 DRIVE8

005F 3005 00135 MOVLW B'00000101' ;Compulsion setting

00136

0060 00137 DRIVE_END

0060 0085 00138 MOVWF PORTA ;Write PORTA

0061 2814 00139 GOTO START ;Jump to start

00140

00141 ;************* 1msec Timer Subroutine *****************

0062 00142 TIMER

0062 30C8 00143 MOVLW D'200' ;Set loop count

0063 008E 00144 MOVWF COUNT2 ;Save loop count

0064 0000 00145 TMLP NOP ;Time adjust

0065 0000 00146 NOP ;Time adjust

0066 0B8E 00147 DECFSZ COUNT2,F ;count - 1 = 0 ?

0067 2864 00148 GOTO TMLP ;No. Continue

0068 0008 00149 RETURN ;Yes. Count end

00150

00151 ;********************************************************

00152 ; END of Stepper Motor controller

00153 ;********************************************************

00154

00155 END

MPASM 02.50.02 Intermediate STEP.ASM 3-9-2001 23:52:45 PAGE 4



Label list has been deleted.

Processing explanation of Stepper Motor controller






Label definition





;**************** Label Definition ********************

cblock h'0c'

The data area is automatically assigned from 0ch by CBLOCK directive. ENDC is used for the ending of assignment.

The purpose of each data area is shown below.



Label

Purpose

mode : This is the area which manages the condition of the motor control.

0=Stop, 1=Clockwise, 2=Counterclockwise

count1 : This is the count area to make control waiting time.

It counts 1 millisecond five times and 5 milliseconds are made.

count2 : This is the counter to make 1 millisecond.







--------------------------------------------------------------------------------







Program start





;**************** Program Start ***********************



Instruction is executed from Zero addresses of the program memory when making the power ON of the PIC. When there is interruption processing, processing is begun from the addresse 4. Because it isn't using interruption this time, there is not program execution from the addresse 4. It makes the interruption prohibition condition if the interruption occurs. It isn't necessary to do this processing.







--------------------------------------------------------------------------------







Initialization process





;**************** Initial Process *********************

The following processing is done as the processing of being initialized after the turning on.

The initialization of the mode of port A

All ports are set to output mode.



The initialization of the mode of port B



RB0,1,2 and 5 are set to input mode. And RB7 is set to output mode.



Port B pull-ups are disabled (RPBU=1)



Because RB5 is used as the high impedance input at the circuit this time, the RB pull up feature should not be used.



Setting of a stop mode



Immediately after turned on, it sets a motor to the stop mode. When there is not this step, the original value of mode becomes 0. It is put for the safety.



Counters for the control waiting time are initialized



There is not a problem even if there is not these processing. They are put for the safety.



Port A initialization



It sets 0101 as the initial state of port A. Because it drives with the transistor, the logic reverses. It is in the condition, =H =L =H =L, from the bit on the left.



Discharging of the capacitor for the speed control



It makes RB7 H level and it makes TR1 ON and discharging in the electric charge of the capacitor for the speed control. The end of the discharge is confirmed by RB5.









--------------------------------------------------------------------------------





Switch condition confirmation process





;************* Check switch condition *****************

It detects the ON condition of the stop switch, the RRC switch, the RLC switch. A condition is set to mode according to the kind of the switch which was made ON. The order of the detection is a stop, a RRC, a RLC. When more than one switch is pushed at the same time, the switch which detected ON earlier is effective.

This processing is done every time it controls 1 step of motor.





--------------------------------------------------------------------------------



Motor drive process



;******************** Motor drive *********************

A stop mode is checked first. In case of the stop mode, it doesn't drive the motor and it jumps to the switch condition confirmation process.



In case of not being a stop mode, the following process is done.

Discharging of the capacitor for the speed control

Discharging the capacitor as the preparation to make the timing of the speed control.



The wait processing of 5 milliseconds



In the high-speed control, the rotor doesn't follow the change of the magnetic pole and the step motor doesn't rotate normally. It sets a timer value to turn a full speed normally.

In case of the motor which was used this time, it doesn't rotate normally when making less than 5 milliseconds.



The charging of a capacitor for the speed control and the confirmation process



It makes RB7 an L level and it begins charging the capacitor. It confirms that the charging completes by RB5. It is completion if RB5 becomes H level. Correctly, it is not charging completion and it is the fact that the voltage of the capacitor became above the threshold voltage of RB5.



The motor drive process



After the speed control timing, a motor is driven. The control state of the motor is confirmed first. This is done by reading the condition of port A. Next, whether it is a clockwise mode or a counterclockwise mode is judged. The following control state which should drive a motor by the result is set to port A. Because there are four conditions, processing is done in each condition.

After the motor drive process, it jumps again to the switch condition confirmation process.








MEMORY USAGE MAP ('X' = Used, '-' = Unused)



0000 : X---XXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX

0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXX------- ----------------

2000 : -------X-------- ---------------- ---------------- ----------------



All other memory blocks unused.



Program Memory Words Used: 102

Program Memory Words Free: 922





Errors : 0

Warnings : 0 reported, 0 suppressed

Messages : 0 reported, 0 suppressed









step_source.zip

step_hex.zip