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