Friday, February 24, 2012

Robot Dynamics - Getting the Specs Right

Well this article covers the dynamics involved in making a good robot! So let’s see what are the dynamics involved in making a perfect Robot there are many factors that can affect like RPM torque of the motor, diameter of the wheel friction between the tyres and the floor etc. We shall discuss how to calculate your requirement and then proceed into its application. For that you’ll need to brush up your knowledge of kinematics and dynamics the first few pages explain the concept’s involved if you feel you know all the concepts right just go directly to the implementation of the concepts.

Rotations per Minute (RPM):

It’s the number of times the axle of the motor spins in a minute. I.e. the number of rotations the wheel makes in a minute. We get motors having different rpm’s the common ones being 45, 60,100,150,200,250,300 in normal gear motors and higher rpm’s for brushless motors. 

Velocity:

Velocity is the distance travelled in unit time (unit time can be anything like second’s minutes or hours) so the units are meters per second or kilometres per hour etc. So how do we apply this to our robot and calculate the velocity of our robot. First of all we need to know the RPM of the motor used and the diameter of the wheel. Now we come to the fundamental concepts of circles. Consider a point on a circle let’s assume this point is touching the ground when rotating the circle without slippage the point again touches the ground when the circle finishes one rotation .the distance travelled during this time period is the distance travelled for one rotation 



And that distance is the product of the diameter and π (π=3.14). The total distance travelled per minute. 


Speed of Bot = RPM x Distance per rotation


I have used diameter in calculating if you consider the radius it will be 2πR.

Example:-

Let’s consider an example 

RPM = 150;

Diameter = 7 cm (0.07 m)

Distance per rotation = 3.14 x 0.07 = 0.2198

Speed = 0.2198 x 150 = 32.98 m/min or 0.5496 m/s

Torque:- 

It is the weight carrying capacity of the motor. The general units of torque are Kg/cm. I.e. the weight it can lift when attached at a distance of 1cm. Torque is also known as moment of force it is the force multiplied with the perpendicular distance from the point where the force is acting so the higher the torque the greater the force the robot can produce 



Here you should notice the greater the radius the lesser will be the force at the end point you’ll need to consider this when choosing the radius of the wheel. 


Stall Torque: - 

This is the force that can stop the motors from rotating i.e. this force is equal to the maximum torque that is produced by the motors so the forces act against each other and nullify .This is also the condition when the motor pulls the maximum current and can damage itself. Care has to be taken so that the motor doesn’t stall. A motor shouldn’t be left in stalled condition for a long time you will end up losing the motor. In India we don’t find any local shop mentioning the torque of the motors (some online shops do list) and those things are the ones sold at the shop just look for similar models and take in those values for calculations. It is equally important to know the stall current of the motor so as to decide upon your power supply the stall torque is the highest current that a motor takes up when in stalled condition.




Acceleration:-

This is a measure as to how fast will your bot get to its top speed. This is very tricky when correlating it to electronic motors so ill just explain you one thing straight if you feel your robot is going slower than it should and getting faster after a few seconds it’s because you are sacrificing acceleration for more weight (your bot is over loaded) you need to get higher torque motors with the same RPM ratings to get your bot to its top speed right from the beginning even here there will be a small time delay but it will be better than running a motor with less torque it will never reach the desired speed.

Traction:-

Traction is the maximum frictional force that can be produced between two surfaces without slipping. In general many people call this as grip on the floor. I.e. The force that prevents your robot from sliding off. you might be in a dilemma as to if high traction is good or not many believe that traction is only necessary for Sumo bot’s or battle bots but that isn’t true traction is required for all your bots if you have a good traction the turning and the control of the bot will be easy and precise. So, how can you have a good traction? The first thing I’d recommend is get your bot better wheels. If your robots motor has a higher torque which you think it won’t be using (like when you end up using overkill motors just because you can afford them or you have them lying around) then increase the weight of your bot as traction increases with the weight of the body. But we wise when involving concepts like this as you’ll need to be clear with the game plan to take these decisions as a wrong choice will make the bot vulnerable in some aspect or the other. Ok to make things simple ill give a few examples where you can put this into action but remember you are sacrificing some torque for this so you’ll need higher torque motors. In Battle robotics or if your robot should move on any other moving object or climbing steep inclines your bot SHOULD have a good traction in the other cases is might not be that needed but it’s always better to have some. 

How to calculate forces?

F = m.a (mass x acceleration)

Calculating forces is a must when you build your Robot! Let’s get through the basics once. Every time we consider a set of forces we need to get the resultant force and its value to know how the body experiencing the force will behave. The resultant force as the name suggests is the net force acting i.e. the actual force the body is experiencing though there a number of forces the body experiences only the resultant of the forces acting on it. Look at the diagram below to understand.



In the above figure we are considering all the forces to be acting from centre but in reality there would be a rotational force due to the forces 10F, 5F and 10F there would be rotational torque produced. Like in the figure below. 



Component of Force

You might consider some cases where force is acting at an angle then what will be the resultant force in the direction of movement of the body. Look at the diagram below and you’ll get it!



So in general when the force is acting at an angle as shown in the figure the force along the direction of movement can be found out by resolving it into its components like shown in the above diagram.
Some general Force you can encounter:-

Force of Gravitation:-

This is the force that is applied on the body directed towards the centre of the earth. This force is equal to the weight of the body (f=m.a; a=9.8 m/s^2; f=m.g)



Normal Reaction

Normal reaction is the force exerted opposite to the direction of the applied force this supports the Newton’s Third law. I.e. it gets things going for example it’s responsible for us standing on the ground.



CALCULATING FORCES ON INCLINES


UP the INCLINE:-

When climbing up the incline a component of the gravitational force acts against us so the force we have on the robot is reduced by this component as it acts in the opposite direction of the force we are applying to get our bot to the top the diagram below ill make it clear.



Down the Incline

When coming down the incline the component acts along with you so the force increases. Look at the figure below so get a clear picture



Friction on inclines:

Some times your bot might start slipping on inclines this is because the magnitude of the component of weight is greater than the force of friction in between the tyres and the surface of the inclines. When applying this concept we don’t have much to do other than to get a good set of tyres for your bot. 

How things are related!

Now I’ll tell you how all the concepts are related with each other. 

Distance from shaft v/s the effective force at the end point though the torque will remain constant for any value of the distance from shaft of the motor we should notice that as the distance from centre increases the force acting on the tip is decreasing. Because T=rxf and the total torque remains constant for a particular motor and you are increasing the radius so the effective force at the tip is reduced in turn. Have a look at the two examples below to get a clear picture



In this example the effective force at the end is torque/radius = 1 Kg



The same motor now has an effective force of 2Kg (Torque/radius = 2Kg) when the radius is reduced to 5 cm so it has to be noted that we shouldn’t go for huge radii unless inevitable. In the two pictures I used rod’s the same concept can be applied to wheels also

* When calculating force requirement for lifting objects you’ll need to consider the distance up to its centre of gravity!

Velocity V/s Rpm and Wheel Diameter

The velocity is also another thing which will give the winning edge to your robot so it is also a thing you need to think about! There are two ways in which you can increase your velocity either increase the Rpm or the Wheel diameter. You can do either of them but in general it is advised to go for higher rpm motor they somehow seem to have an edge over increasing wheel diameter but whatever you are doing you need to keep the requirement of torque in mind otherwise the winning edge if not understood or applied properly will make you lose.

Rpm V/S Torque:-

We could be confused in choosing the correct combinations of Rpm and torque. In general they are inversely proportional i.e. for a particular base motor as the rpm increases the torque decreases the maximum torque for a motor occurs at 0 RPM and the Minimum torque occurs when the motor is running at its highest possible RPM if you’re not utilizing that much torque Where does that extra torque go? The extra torque is used in accelerating your Bot though not to 100% most of it goes that way.

Let’s go a bit electrical!

You might have mastered these concepts and made a bot involving good mechanics but you’ll be powering up the entire thing using electrical energy. Many people design bot’s excellent mechanical concepts but fail when choosing the power supply. I have myself had the leading edge of a good enough power supply many times as the opponents though had good mechanism etc they didn’t have enough juice to pump through their bot. Whenever choosing a power supply you should keep in mind the power requirement of each and every part of your bot and get appropriate batteries and also never ignore the voltage recommendations of the components you are using. For example you have four motors on your bot which consume 3amps current at stall (yes! You’ll need to consider the stall current when calculating) then the battery should have a current capacity at minimum 13amps (one amp extra just to be sure) alongside you should also know the voltage requirements if the rating of the motors is 12 volts the battery should be rates 12V 13 A (considering motors are wired parallel) 

Example:-

Challenge: - SUMO ROBOT

Now it’s time we apply all the things we learnt to building an example Bot! Let’s take up a challenge we have to build a Sumo bot and the general restriction a sumo bot goes like 

Specifications:-

Max Weight 5Kg

Dimensions 30x30x30

Max voltage 12V

Now our task is to build a bot that will emerge as a winner in the competition .So let’s start out calculating our requirements of force the first main task will be to push the other bot outside the arena also there will be other tasks like pushing bricks against inclines etc in qualification rounds now let’s get to business so what would be our force requirements? First and foremost we will have to push the other bots outside the arena and they will weight around 5 Kg most people will go wrong here only they will consider this force only but there are other factors you will also need to consider the weight of your bot and some other force dampening factors like rough terrain etc. So the force will need to be around 11kg (5Kg to push + 5Kg to carry our bot + 1Kg for possible situations) now comes the incline part we need to know the angle of inclination beforehand generally around 25 degrees . Then comes in the speed of the bot this is dependent on you how much do you want? Well something around 0.50 m/s is good for sumo bots. Now let’s list out all the 

Requirements:-

Force: - 11 Kg

Velocity: - 0.50 m/s

So now we have the force required that is the effective force at the tip of the wheels what we have left to calculate is the diameter of the wheel the RPM and the torque of the motors required. Lets first get through the velocity first we have seen that

Speed of Bot = RPM x Distance per rotation


Now, 0.50 m/s = Rps distance per rotation 
(Rps = rotations per second *conversion taken as speed in m/s)
And Distance per rotation = 3.14 x 2 x radius 
Keeping it aside,
Torque = Radius x Force
And Rps = Speed of the Bot / Distance per rotation
= 0.50/2x3.14xRadius
As we can see there are a number of possible combinations you’ll need to chose based on the material available in general the diameter of the wheels available is 7cm (radius = 3.5cm) or (0.035 m) now let’s calculate the rpm needed
RPM = RPS x 60
Rps = 0.50/2x3.14x0.035
= 2.2747
RPM = Rps x 60
= 2.2747 x 60 = 136.482
So now we got the Rpm to be 136.482 and the nearest readymade values is 150 RPM 
Torque = Radius x Force
= 3.5 x 11
= 38.5 Kg/cm

Again this load is shared by the number of motors on your bot! So if it is 2 the rating would be 150RPM and 19.25 Kg/cm torque.


NOTE:-
The calculations above are considering a 100% efficient functioning of everything but that just never happens and will never happen so you’ll need to keep all efficiency reducing factors in mind I will just list a few examples undercharges batteries, things which reduce the traction of your bot like oil, water plastic sheets etc. Also things which can increase traction like adhesives etc other factors like, slopes, errors in motors can also affect your calculations by a good margin so consider all these and then decide what will be your winning configuration.

Wednesday, February 22, 2012

PID : Proportional–Integral–Derivative


What is PID?
Ok so what is this PID and why is it much talked? Well, PID means proportional–integral–derivative and it is a control feedback method applied in different control systems, its main task is to minimize the error of whatever you are about to control. It is superior quality error control feedback mechanism and the general industry standard. Speaking simple it takes in the inputs calculates the deviation from the intended behaviour and accordingly adjusts the outputs so that the deviation from the desired behaviour is minimized thus getting the highest possible accuracy.

What does this PID have to do with me?
Well, there are many applications in the field of robotics like correcting sensor readings, manipulating pwm speed which is the chief objective called motion control. Before using PID control you were simply telling the robots wheels to drive at a certain speed, set by a PWM output hence assuming that the robot wheels would turn at the same speed and the robot would travel in a straight line. This is known as open loop control. This means that you send an output to the motors with no feedback and assume they travel at the speed you set. It is very unlikely that two motors, even two identical motors will turn at the same speed. So some sort of feedback is required to control the speed. This is normally achieved using an encoder. When the speed of the motor is controlled using feedback it is known as closed loop control. Here PID control comes into action! after taking the readings from the encoders it sets the speed such that the bot travels accurately you would have already noticed that the normal geared motors we get (especially in India) don’t have precision they have an error ranging from 3 to 8 percent which can mean a lot when turning especially in line followers even a small error can make a line follower miss the line completely or just confuse the bot!

The ‘P’ part:-
The proportional part, for example let us consider that we are making a bot to follow another on a straight line then our interest will be to check continually at what distance we are from the other bot and accordingly set the current speed of the bot .We could do it in two ways just be dumb and say if the distance is greater than the set-point and speed up, then we end up either crashing into the bot of fall behind it based on the value we set to speed up or we can also check the proportional error i.e. the set distance – current distance and then speedup the bot by setting a value to be multiplied by the difference in the distance.

Example for proportional control-

Bot is running at a pwm speed of 180
Set distance = 2 cm
Current distance = x
Deviation = x-2
Gain = 20 (this is decided by trial and error method)
If distance < 2
Pwm speed = pwm speed + (gain x deviation)
in the above example if the deviation is low the increase in speed will be less and if the deviation is more the speed will be increased significantly so the bot will behave better and avoid thing like ramming into other bots or falling behind . The proportional method works pretty well with a high sampling rate and a low settling time which is good thing.
P=E*Gp
P is proportional calculated error
E is the original error
Gd is the proportional gain constant

The 'I’ Part:-
The integral part is the accumulative error made over a set period of time (t); you might think why do we need the accumulative error over time? Let’s take an example, suppose we are driving a car and want to keep it at the centre of the road. At a particular time we go a little to the right then we make the car straight by moving it a little to the left then we get the car to be straight but it might not be at the centre accumulating a minute constant error which after some time when added to the code will get the car to the centre as it grows in number. This could be quite tricky to implement and has a higher settling time also will need a slower sampling rate so as to make it have only small changes and doesn’t accumulate to a fairly large quantity. The integral control improves steady state performance that is when the value is fairly consistent but doesn’t suit ever changing values.

I=Ei*Gi
Ei Sum of all previous error.
Gi is the integral gain constant

The 'D’ Part:-
The derivative part is the rate of change of error i.e. the difference in the errors as time proceeds For example, the error was C before and now it’s D, and t time has passed, then the derivative term is (C-D)/t. The advantage of the derivative part is that it prevents sudden changes from happening but could also slow down the entire process if not used wisely but along with the integral part it will work wonderfully if tuned correctly. You can use the timer on the microcontroller to measure the time .There exist no D-only controller.
D=E*Gd
E= (Et1-Et2)/t2-t1 i.e. the difference in value by time difference
Gd is the derivative gain constant
The whole thing put together should be
Error = P+I+D
This error should be added to the value you are controlling

Sample rate: -
This is the rate at which the readings are noted i.e. How many times a second are you scanning the sensors per second. A good sample rate will be around 10 to 50 times a second. Strictly speaking it once it’s above 10 it really doesn’t matter much for general robotics but the higher the better and keep in mind that sampling rate matters much when dealing with PID

Tips:-
•PID doesn’t guarantee off the box results the code requires constant tweaking based on circumstances once tweaked correctly will run exceptionally
•PID algorithm has some settling time so it will take a few seconds before the bot starts to perform well.
•Some applications may require using only one or two actions to provide the appropriate system control. This is achieved by setting the other parameters to zero. A PID controller will be called a PI, PD, P or I controller in the absence of the respective control actions.
•Once you have equations for the PID component functions, the next step is to obtain parameters for the PID equation. Because the selection of parameters depends on the physical characteristics of the system, there is no stock set of values that can be applied to every implementation. Instead, the parameters for the equations must be tuned to the particular platform they are intended to control.
•             The following procedures can be applied when tuning PID values
i)             Analytical:-we can set the values based on theory and circumstantial calculations
ii)            Trial and error :- set random values and keep tweaking the values until desired behaviour is achieved
•When tuning PID first set the speed to a low value and continue increasing along with retuning the values.
•When using a PID algorithm a sample rate can be a issue which causes inconsistency just keep playing with the values and try to get the highest sample rate possible keeping the bot follow ideal behaviour
•When going for competition robotics keep in mind the settling time of the PID algorithm the less    the better
•Though PID works well in controlling errors don’t try to make a 100 rpm and a 300 rpm motor move in a straight line it just won’t happen.
•If the error can be reduced physically then don’t be lazy DO it!

PID for line followers:

So, in which aspects of a microcontroller can we use the PID algorithm? Every aspect of it! Form the sensor readings to motor control having PID on everything would be a tough thing indeed but once you get the hang of it your line follower will the best and when having PID running on your bot the more number of sensor you have on your bot the better so that by the time the bot responds at least one of the sensor detects the line

Sensors interfacing:-
We should assign an error value for each of the sensor for the PID to be effective
EX:-
Consider we have 5 sensors
The sensors
00100 – Error value = 0
01000 – Error value = 2
10000 – Error value = 5
00010 – Error value = -2
00001 – Error value = -5
When setting the error value we notice that by setting the error value to the farthest sensor high we will get aggressive response when that error goes up into the PID control code the value goes too high we should take it into consideration and adjust the value

Encoders:-
Before going to motion control we’ll need to know a bit about encoders. Wheel encoders are devices that allow one to measure the precise speed or distance a wheel travels. Depending on the type of encoder used, it may be possible to determine the direction of movement. These are helpful for precise movement, allowing a robot to turn exact angles or move exact distances. Wheel encoders can provide information for odometry and be utilized in localization problems. There are many types of encoders but the main one going with robotics are optical encoders. Encoders can be used to detect things like direction, angle, distance travelled etc for more information refer http://en.wikipedia.org/wiki/Rotary_encoder


Motion control:-

It is better to have encoders on fast line followers to know the actual speed that the motor is running at so as to minimize the possible error which can make the bot totally miss the line. A common control mechanism, for small robots, is to control the velocity of a motor. On a typical robot, differential drive is used for steering. In order to go straight both motor shafts have to be turning at precisely the same rate (and the wheels have to be the same diameter as well). With an encoder one can count how many clicks have gone by in a period and uses that as an indication of velocity. The error between the velocity set point and the actual velocity is used to control the power levels to the motors. Using the PID controller this can be done highly efficiently and accurately.

Putting Everything Together
Ok, so now let’s put everything together. Let’s assume we built a line follower robot and are implementing PID for it.
Specifications (taken in general point of view)
6 Sensors
10 Bit ADC
8 Bit PWM
Gear motors
Incremental optical encoders

We are applying PID for the sensors and wheel encoders. Lets first consider the sensors generally we use analogue sensors for the line followers here we need to consider the readings of the sensors it is quite common that all the sensors don’t give us a single values to proceed with hence we come in a different approach let us a separate function to read all the sensors and give us a single value so that we can implement the PID algorithm easily let us take the values from all the six sensors and set them to a range of -25 to 25 Then we can set everything correctly the set point should be zero that is when the line lies in the centre then 10 when under an extra sensor right and 25 when to the rightmost sensor similarly -10 when under an extra sensor left and -25 when to the leftmost sensor . Hence the set point should be ‘ZERO’. Now coming to the P, I, D for P and D the E will be same (you can refer to the formula once again) where as for the I term the E is the integral for all the previous errors. all you have to set is the Gain constants for the P,I and D while calculating the gain constants the resolution of PWM on your microcontroller should be taken into consideration in this example I took it to be 8 Bit so the value would range from 0 – 255. Now we should decide the set speed this is also tricky you should get a good response from your bot therefore you should get motors of higher RPM than you require and set the PWM speed to 150 so we can get a change of 100 to nullify the error .After deciding these values now you should go for the gain constants the highest should always be for the Proportional constant then the derivative constant and last the integral constant. The maximum change we can make is 100 so even the error should not exceed 100 and without the error going into the PID loop itself the error is 25 so the maximum gain constant used is 4 (25 x 4 = 100) but we again want to further divide the maximum gain constant among Gd Gp Gi so as I previously told we would want the gain constant for proportional value to be high so we set it to 2.5 then derivative to 1 and integral to 0.5 now we need to keep tuning these values until we get the best behaviour from our line follower it is advised to have these values read in the start so that we don’t need to connect it to a computer every time we need to change the values.

General Tip: - set the proportional value to around 60% to 70% of the change we can make

Saturday, February 4, 2012

MOBILE OPERATED ROBOT

                                               MOBILE PHONE OPERATED BOT



OVERVIEW:
Today as the mobile phones are become very essential for everyone and has a vital use so to think about a mobile phone operated robot is an innovative idea. We can operate our robot from any distant or remote area. It is a wireless robot but instead of using a separate wireless module (transmitter and receiver) we are using the cell phones for this purpose. This robot has advantages over simple wireless bot as it overcomes the limitations of wireless like limited range, frequency interference etc. Mobile operated bot is having a wide range (service provider range), less fear of interference as every call is having a unique frequency and moreover it has more control keys (12 keys).The principle used for mobile controlled robot is the decoding of the DTMF tone. DTMF tone stands for dual-tone multi-frequency tone. During any call if a button is pressed, a tone corresponding to that button is generated and heard at the other end of the call. This tone is basically known as DTMF tone and these tones are standard one, fixed by IEEE, ISO, EIA, ITU etc.

CIRCUIT DESCRIPTION:





WORKING:

The mobile operated robot is having basically five main phases:

1. Make a call to mobile on robot.
2. Sending the signal generated by DTMF encoder in transmitter.
3. Receiving the signal by receiver.
4. Decode the signal with HT9170 decoder IC.
5. Process the decoded signal with on board processor ATmega16.


Firstly make a call from the remote phone to the phone attached to the robot and connect the receiving mobile phone with headset in auto answer mode. As the call is received, the connection is established between two. Now if you press a button then the DTMF tone generates a signal by adding the frequency corresponding to that button and sends to the receiver. Receiver detects it and sends it to HT9170 decoder IC which decodes the DTMF tone and fed the decoded signal to the microcontroller ATmega16 i.e. on board processor. According to the program in the microcontroller the robot starts moving.

In DTMF the tones and assignments are as follows:


The keys A,B,C,D are not available in the mobile phones as these keys are used to transmit some secret or confidential data. These keys are basically used in govt. and defense sector.
All type of HT9170 series use digital counting techniques to detect and decode all the 16 DTMF tone pair into 4-bit code output.



VP and VN are the dual i/p of the op-amp, GS is the output of op-amp. When input signals given at pin1 and pin2 found to be effective then DV(pin15) becomes high, the correct 4- bit code of tone is transferred to the output pins D0-D3. The decoded digital data is then negated using 4 NOR gates of 7404 HEX INVERTER. This inverted input will be given to Port A of microcontroller. The microcontroller is programmed to give output at Port D,to control the motor driver. As the microcontroller is not able to drive the motor so a motor driver IC L293D is used for this purpose.















Saturday, January 21, 2012

ASSEMBLER DIRECTIVES


An assembler directive is a message to the assembler that tells the assembler something it needs to know in order to carry out the assembly process; for example, an assemble directive tess the assembler where a program is to be located in memory. We are going to use the following directives in this course:
<label>EQU<value>Equate
ORG<value>Origin
<label>DC<value>Define constant
<label>DS<value>Define storage
END<value>End of assembly language program and "starting address" for execution
In each case, the term <label> indicates a user-defined label (i.e., symbolic name) that must start in column 1 of the program, and <value> indicates a value that must be supplied by the programmer (this may be a number, or a symbolic name that has a value).
Equate
The EQU assembler directive simply equates a symbolic name to a numeric value. Consider:
SundayEQU1
MondayEQU2
The assembler substitutes the equated value for the symbolic name; for example, if you write the instruction ADD.B #Sunday,D2, the assembler treats it as if it wereADD.B #1,D2.
You could also write
SundayEQU1
MondayEQUSunday + 1
In this case, the assembler evaluates "Sunday + 1" as 1 + 1 and assigns the value 2 to the symbolic name "Monday".
Do not think that the EQU directive creates variables or constant. It doesn't and it has no effect on the code generated by the program. This directive simply allows you to make a name equivalent to its value (i.e., it's a form of short hand).
Origin
The origin directive tells the assembler where to load instructions and data into memory. The 68000 reserves the first 1024 bytes of memory for exception vectors. Your programs will start at location 1024; that is, you should begin your program with ORG 1024 or ORG $400 (remember that 1024 = 40016).
Define Constrant
The define constant assembler directive allows you to put a data value in memory at the time that the program is first loaded. The DC directive takes the suffix .B.W, or.L. You can put several values on one line (each value is separated by a comma). The optional label field is given the address of the first location in memory allocated to the DC function. Consider the example:
ORG$2000Locate data here
Val1DC.B20,34Store 20 and 34 in consecutive bytes
Val2DC.L20
MeDC.B’Alan Clements’
The effect of this code is to store the value $14 in location $2000, $22 in location $2001, $00000014 in locations $2002, $2003, $2004, $2005. Remember that a 32-bit longword takes four bytes of memory. The ASCII string ‘Alan Clements’ is stored in bytes $2006 to $2012.
If you write MOVE.B Val2,D2, the assembler translates it as MOVE.B $2002,D2. When this instruction is executed, data register D2 is loaded with the contents of memory location $2002. The value loaded into D2 might be 20. Might be?? Yes, might be, because another instruction might modify the contents of Val2. By the way, if you execute MOVE.B Me,D0, data register D0 would be loaded with $41 (the ASCII code for ‘A’). However, if you execute MOVE.W Me,D0, data register D0 would be loaded with $416C (the ASCII code for ‘Al’).
Define Storage
The define storage directive is used to reserve one or more memory locations. This directive is similar to the Pascal type declaration. Consider:
ResultDS.B 1Save a byte for Result
TableDS.W 10Save 10 words (20 bytes) for Table
PointDS.L 1Save 1 longword (4 bytes) for Point
We will put these two fragments of assembly language together and assemble them using the X68K command (X68K is the Teesside 68K cross-assembler that runs under DOS on a PC). The following is part of the listing file produced by the assembler. The second column contains memory addresses and the third column contains the data loaded into these addresses.
2 00002000ORG$2000;Locate data here
3 000020001422VAL1:DC.B20,34
4 0000200200000014VAL2:DC.L20
5 00002006416C616E2043ME:DC.B’Alan Clements’
6C656D656E74
73
6 0000201300000001RESULT:DS.B1;Save a byte for Result
7 0000201400000014TABLE:DS.W10;Save 10 words (20 bytes) for Table
8 0000202800000004POINT:DS.L1;Save 1 longword (4 bytes) for Point

Monday, January 16, 2012

Extension For Admission

Students interested in joining The Engineers' Choice coaching institute for the trial classes should do it by 25th january.
The institute is for CSE and ECE branches and for 1st year of all branches.
Its located in Haldwani,Nainital,Uttarakhand.

Sunday, January 8, 2012

MICROCONTROLLER-BASED HEART-RATE METER





MICROCONTROLLER-BASED HEART-RATE METER



Heart rate can be measured either by the ECG waveform or by the blood flow into the finger (pulse method). The pulse method is simple and convenient. When blood flows during  the systolic stroke of the heart into the body parts, the finger gets its blood via the radia1afteryt on the the arm. The blood flow into the finger can be sensed photoelectrically.

To count the heart beats, here we use a small light source on one side of the finger (thumb) and observe the p change in light intensity on the other side. The blood flow causes variation in light intensity reaching the light- dependent resistor (LDR), which result in change in signal strength ‘due tb ‘change in the resistance of the LDR.

Circuit description

Fig. 1 shows the circuit of microcontroller-based heart-rate meter. The setup uses a 6V electric bulb for light illumination of flesh on the thumb behind the nail and the LDR as detector of change in the light intensity due to the flow of blood, The photo-current is converted into voltage and amplified by operational amplifier IC LM358 (Id). The detected signal is given to the non-inverting input (pin 3) and its output is fed to another non-inverting input (pin 5) for squaring and amplification. Output pin 7 provides detected heartbeats to pin 12 of the microcuntroller. Preset VRI is used for sensitivity and preset VR2 for trigger- level settings.


Microcontroller IC AT89C2051 (1C2) is at the heart of the circuit. It is a 20-pin, 8-bit microcontroller with 2 kB of Flash programmable and erasable read-only memory (PEROM), 128 bytes of RAM, 15 input /output (I/O) lines, two 16-bit timer/counters, a five-vector two-level interrupt architecture, a full-duplex serial port, a precision analogure comparator, on-chip oscillator and clock circuitry.

          Port-1 pins P1.7 through P1.2, and  port-3 pin P3.7 are connected to input pins 1 through 7 of IC ULN2003 (IC3), respectively.These pins are pulled-up with 10-kilo-ohm resistor network RNW1. They drive all the segments of the 7-segment display with the help of inverting buffer IC3.

          The display are selected through port pins P3.0, P3.1 and P3.2 of the
Microcontroller (IC2). Port pins P3.0 down through P3.2 are connected to
The base of transistors T3 through T1, respectively. Pin 6 of IC goes low to drive transistor T1 into saturation and provide supply to the common-anode  pin (either pin 3 or pin  8) of DIS1.Similarly, transistors T2 and T3 drive  common-anode pin 3 or 8 of7-segment  displays DIS2 and DIS3, respectively. Only three 7-segment display are  used.

1C2 provides segment-data and display-enable signals simultaneously in time-division-multiplexed mode for displaying a particular number on tie 7-segment display unit. Segment-data and display-enable pulses for the display are refreshed every 5’ ms. Thus the display appears to the continuous, even though it one by one.

Switch S2 is used to manually reset  the microcontroller, while the power on reset signal for the microcontroller is derived from the combination of capacitor C4 and resistor R8. An 11.0592MHz crystal is used to generate the basic clock frequency for the microcontroller. The circuit is powered  by a 6V battery.

Port pin P3.6 of the microcontroller is internally for software checking. This pin is actually the output of the internal analogue comparator, which is available internally for comparing the two analogue  levels at pins i2 and 13. As pins 12 and, 13 of IC2 can work as an analogue Comparator, these are used for sensing the rise and fall of the pulse waveform and  there by evaluate the time between two peaks and hence the beat rate.



The output of the pulse pi preamplifier is fed to pin 12 microcontroller. Pin 13 of the microcontroller is connected to the preset for reference-level setting of the comparator. Thus voltages at pins 12 and  13 are always compared. The rise and the fall at pin 12 are Sensed by the program.

          The internal timer of the microcontroller is used to find the time
taken for one wavelength. This time is converted into the heart beat rate in beats per minute by a pre-calculated look-up table. The program notes the time between the high-to- low nd low-to-high transitions of the wave. This time in microseconds is converted in steps of 4 ms for comparison with the values already stored in the look-up table. This number is used to find (from the look-up table) the heart rate in bçats per minute. The number so obtained is converted into a 3-digit humber in binary-coded decimal (BCD) form. The same is output to the 7-segment LED displays in a multiplexed manner. The display shows the rate for a while and proceeds  to another measurement. Thus beat rates obtained from time to time are visible on the display.

Construction and testing

The arrangement for heart beat rate detection is shown in Fig. 2. Purchase a plastic ‘T’ tube from an electrical parts shop. The tube should be about 5cm long and have a diameter of 1.5 cm. House the electrk bulb into the left tube and the LDR (soldered on a small PCB) into the right tube. Fihilds on both sides of the tube to maintain darkness for better performance Connect .the 6V battery supply to the bulb and the LDR to the circuit board via a shielded cable.

For heart beat detection, which can be seen on a cathode ray oscilloscope (CR0), insert your thumb with the nail facing the LDR inside the Ttube. Shaking the thumb will change the level of signal from the previous value, and it will keep oscillating. Therefore you have to hold the thumb firmly between the light bulb and the LCR while the measurement is being made. Place the circuit components and IC bases on the PCB board. Check the pulse pick-up through the CRO at output pin 7 of IC1 (refer Fig.3). In sert the programmed microcontroller and other ICs into the IC bases. Set the  levels of sensitivity, trigger and voltage reference for the comparator by using presets VR1, VR2 and VR3, respectively.

          Hold the thumb steady and observe the heart beat rate on the display. The rate may vary and may not be exactly steady. For instance, normally, the rate can vary between 60 and 100.

          Since this is a beat-to-beat measurement and not ab average over a time period of one minute, variation is expected. However, when the reading  shows high value at times, say 140 it may be due to unusual mains hum picked up by transducer. To suppress it, place a separate capacitor of 100 µF across the 5V supply.

          An actual-size, single-side PCB for the microcontroller-based heart-rate meter is shown in Fig. 4 and its component layout in Fig.5.
Software
The software is written in Assembly lauguage and assembled using ASM51 cross-assembler.The Intel hex code is generated and burnt  into the microcontroller chip by using a suitable programmer. The software is well commented and easy to understand.

The timer does the job of find-ing the time between two successive pulse waveform points. Since the comparator within the microcontroller IC knows the point of crossings of the wave with the DC line determined by preset VR3, the three crossings follow one after another and at the end of the third crossing the time is read from the time-count register. This time is then converted in terms of the number of 4 ms intervals. From the number of such 4ms units, the number of beats per minute is determined from the look-up table already stored in the same memory starting from the label ‘table’ in the
Program listing.


 

PARTS LIST

[Cl                                           LM358’ operational amplifier

1C2                                          AR 89C2P51 microcontroller

IC3                                          ULN 2003 current buffer.

T1-T3                                      -BC557 pnp transistor

D1                                           - 1N4007 rectifier diode.

DIS-DIS3                               - LTS542 common-anode,
                                                   7-segment display

LED1 LED2                           - 5mm LED

Resistors (all ¼-watt, ±5%carbon)

R1,R8                                      - 10kilo-ohm

R2                                           - 47-kilo-ohm

R3                                           - 100-kilo-ohm

R4,R5                                      - 1-kilo-ohm

R6,R7                                      - 330- ohm

R9-R11                                   - 1.2 kilo-ohm

RNW1                                     - 10 kilo-ohm resistor network








Capacitors:

C1                               -470nF ceramic disk

C2,C5,C8                    - 0.1µF ceramic disk

C3,C9                          - 470µF, 16V electrolytic

C4                               - 10µF, 16V electrolytic

C6,C7                          - 22pF ceramic disk

Miscellaneous :

S1, S3                  - On/Off switch
S2                          - Tactile switch
X                          - 11.0592MHz crystal
BATT1, BATT2-6V- 6V battery




Figure 1     Waveform of heartbeat detection







Figure 2                A single-side, actual-size PCB layout for microcontroller-based heart-rate meter




THE ABOVE CIRCUIT IS A MODIFIED VERSION OF IR SENSOR BASED FINGER BASED PULSE SENSOR. IT CAN BE INTERFACED WITH MICRCONTROLLER IN PLACE OF LDR CIRCUIT. REST IS SAME.

                      
Figure 3          Circuit diagram of microcontroller-based heart rate meter
`







Figure 4        Component layout for the PCb