Upload
khangminh22
View
0
Download
0
Embed Size (px)
Citation preview
SY9316 EMBEDDED SYSTEMS I
LAB MANUAL
PREPARED BY APPROVED BY
V.KARTHICK RAJA Prof.S.GOBIMOHAN AP/EEE Prof & HEAD/EEE
DEPARTMENT OF EEE
DHANALAKSHMI SRINIVASAN ENGINEERING COLLEGE
PERAMBALUR – 621212.
DHANALAKSHMI SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR – 621212
Department of Electrical and Electronics Engineering
Sub. Code / Name : SY9316 / Embedded system lab I
Sem / Year : 1 / I
Staff Name : Mr.V.Karthick Raja / Asst.Prof
FIRST CYCLE EXPERIMNETS
1. LCD interfacing using 8051 microcontroller.
2. Keypad interfacing using 8051 microcontroller.
3. LCD interfacing using 8086 microcontroller.
4. Rolling display programming using 8086 processor.
5. Timer programming using 8086 processor.
SECOND CYCLE EXPERIMENTS
1. Round robin task scheduling.
2. Pre-emptive based task scheduling.
3. PID controller.
4. Modeling of combinational digital system
Staff I/C HOD / EEE
DHANALAKSHMI SRINIVASAN ENGINEERING COLLEGE, PERAMBALUR – 621212
Department of Electrical and Electronics Engineering
Sub. Code / Name: SY9316 / Embedded systems lab I
Sem / Year : 1 / I
Staff Name : Mr.V.Karthick Raja / Asst.Prof
LIST OF EXPERIMENTS
1. LCD interfacing using 8051 microcontroller.
2. Keypad interfacing using 8051 microcontroller.
3. LCD interfacing using 8086 microcontroller.
4. Rolling display programming using 8086 processor.
5. Timer programming using 8086 processor.
6. Round robin task scheduling.
7. Pre-emptive based task scheduling.
8. PID controller.
9. Modeling of combinational digital system
Staff I/C HOD / EEE
LCD INTERFACING USING 8051 MICROCONTROLLER
AIM:
To write an assembly language program to interface 8051 microcontroller with 8279 as LCD module.
APPARATUS REQUIIRED
1. 8051 microcontroller kit.
2. 8279 LCD interface
3. 50 pin cable
ALGORITHM:
1. Start the program.2. Initialize the mode and display with 8279 keyboard/display controller.3. Clear the display.4. Write the display.5. Get the character to be displayed.6. Outputs the value in maintain to address.7. Return the program
PROGRAM:
ADDRESS HEX CODE LABEL MNEMONICS
4100
4103
4105
4106
4108
90 FF C2
74 00
F0
74 CC
F0 \
MOV DPTR,#FFC2
MOV A,#00
MOVX @DPTR,A
MOV A,#CC
MOVX @DPTR,A
4109
410B
410C
410F
4111
4112
4114
4116
4117
4119
74 90
F0
90 FF C0
74 88
F0
78 05
74 FF
F0
D8 FD
80 FE
LOOP
HERE
MOV A,#90
MOVX @DPTR,A
MOV DPTR,#FFC0
MOV A,#88
MOVX @DPTR,A
MOV R0,#05
MOV A,#FF
MOVX @DPTR,A
DJNZ R0,LOOP
SJMP HERE
RESULT:
Thus the interfacing of 8051 microcontroller LCD module is done using 8279 controller.
KEYPAD INTERFACING WITH 8051 MICROCONTROLLER
AIM:
To write an assembly language program to interface 8051 microcontroller with keypad interface
APPARATUS REQUIIRED
1. 8051 microcontroller kit.
2. 8279 LCD interface
3. 50 pin cable
ALGORITHM:
1. Start the program.2. Initialize the mode and keypad with 8279 keyboard/display controller.3. Clear the display.4. Write the character.5. Get the character to be displayed.6. Outputs the value in maintain to address.7. Return the program
PROGRAM:
ADDRESS HEX CODE LABEL MNEMONICS
4100
4102
4104
4107
4109
410A
410C
410D
410F
4110
4112
4115
79 82
78 08
90 FF C2
74 02
F0
74 CC
F0
74 90
F0
74 FF
90 FF C0
F0 LOOP
MOV R1,#42
MOV R0,#08
MOV DPTR,#FFC2
MOV A,#02
MOVX @DPTR,A
MOV A,#CC
MOVX @DPTR,A
MOV A,#90
MOVX @DPTR,A
MOV A,#FF
MOV DPTR,#FFC0
MOVX @DPTR,A
4116
4118
411B
411C
411E
4120
4122
4123
4126
4127
4129
412B
412D
412E
4131
4132
D8 FD
90 FF C2
E0
54 07
60 FB
74 40
F0
90 FF C0
E0
54 0F
F5 82
89 83
E0
90 FF C0
F0
80 E4
AGAIN
WAIT
DJNZ R0,LOOP
MOV DPTR,#FFC2
MOVX A,@DPTR
ANL A,#07
JZ WAIT
MOV A,#40
MOVX @DPTR,A
MOV DPTR,#FFC0
MOVX A,@DPTR
ANL A,#0F
MOV DPL,A
MOV DPH,R1
MOVX A,@DPTR
MOV DPTR,#FFC0
MOVX @DPTR,A
SJMP AGAIN
LOOK –UP TABLE
4200
4204
4208
420C
0C 9F 4A 0B
99 29 28 8F
08 09 88 38
6C 1A 68 E8
LCD INTERFACING USING 8086 MICROCONTROLLER
AIM:
To write assembly language program to interface 8086 microprocessor with 8279 display/keyboard controller.
APPARATUS REQUIRED:
1. 8086 processor kit.
2. 8279 display/keyboard controller.
3. 50 pin cable
ALGORITHM:
1. Start the program.2. Initialize the mode and keypad with 8279 keyboard/display controller.3. Clear the display.4. Write the character.5. Get the character to be displayed.6. Outputs the value in maintain to address.7. Return the program.
PROGRAM:
ADDRESS HEX CODE LABEL MNEMONICS
1000
1002
1004
1006
1008
100A
100C
100E
B0 00
E6 C2
B0 CC
E6 C2
B0 90
E6 C2
B0 88
E6 C0
MOV AL,00
OUT C2,AL
MOV AL,CC
OUT C2,AL
MOV AL,90
OUT C2,AL
MOV AL,88
OUT C0,AL
1010
1012
1015
1017
1019
B0 FF
B9 05 00
E6 C0
E2 FC
F4
NEXT
MOV AL,FF
MOV CX,0005
OUT C0,AL
LOOP NEXT
HLT
RESULT:
Thus the LCD interfacing with 8086 microprocessor is done.
ROLLING DISPLAY PROGRAMMING USING 8086 PROCESSOR
AIM:
To write assembly language program to display rolling letters using 8086 microprocessor.
APPARATUS REQUIRED:
1. 8086 processor
2. 8279 keyboard/display control
3. 50 pin cable
\
ALGORITHM:
1. Start the program.2. Initialize the mode and keypad with 8279 keyboard/display controller.3. Clear the display.4. Write the character.5. Get the character to be displayed.6. Outputs the value in maintain to address.7. Return the program
PROGRAM:
ADDRESS HEX CODE LABEL MNEMONICS
1000
1003
1006
1008
100A
100C
100E
1010
1012
1014
BE 00 12
B9 0F 00
B0 10
E6 C2
B0 CC
E6 C2
B0 90
E6 C2
8A 04
E6 C0
START
NEXT
MOV SI,1200
MOV CX,000F
MOV AL,10
OUT C2,AL
MOV AL,CC
OUT C2,AL
MOV AL,90
OUT C2,AL
MOV AL,[SI]
OUT C0,AL
1016
1019
101A
101C
E8 E7 04
46
E2 F6
EB E2
CALL DELAY
INC SI
LOOP NEXT
JMP START
SUB PROGRAM
1500
1503
1504
1506
BA FF A0
4A
74 FD
C3
DELAY
LOOP1
MOV DX,AOFF
DEC DX
JNZ LOOP1
RET
LOOK-UP TABLE
1200
1204
1208
120C
FF FF FF FF
FF FF FF FF
98 68 7C C8
FF 1C 29 FF
RESULT:
Thus the rolling display program has been done using 8086 microprocessor.
TIMER PROGRAMMING USING 8086 PROCESSOR
AIM:
To write assembly language program to interface 8086 microprocessor with 8253 peripherals interval.
APPARATUS REQUIRED:
1. 8086 processor kit.
2. 8279 display/keyboard controller.
3. 50 pin cable
4. 8253 programmable timer.
5. CRO with probe.
ALGORITHM:
INTERUPT A TERMINL COUNT MODE 0
1. Initilize 8253 programmes interrupt times interface.
2. Set the channel and mode of operation of 8253.
3. Get the port address in accumulator.
4. Outout the LSB and MSB of count in port address control.
5. An interrupt will be created.
6. Stop the program
SQUARE WAVE GENERATION:
1. Start the program.
2. Initilize the 8253 programmable internal time interface.
3. Set the channel and mode of operation.
4. Outout the LSB and MSB of count in port address CHO.
5. A square wave will be generated.
6. Stop the program.
INTERFACING OF 8086 WITH 8253:
ADDRESS
HEXCODE MNENONICS COMMENTS
1000
1002
1004
1006
1008
100A
100C
BO,30
E6,CE
B0,05
E6,C8
B0,00
E6 C8
F4
MOV AL,30
OUT CE,AL
MOV AL,05
OUT C8,AL
MOV AL,OO
OUT C8,AL
HLT
CHANNEL 0 IN MODES
LSB OF COUNT
MSBOFCOUNT
HALT THE PROGRAM
SUB PROGRAM:ADDRESS HEXCODE MNEMONICS COMMENTS1000
1002
1004
1006
1008
100A
100C
B0,3B
E6,CE
B0,10
E6,C8
B0,00
E6,C8
F4
MOV AL,36
OUT CE,AL
MOV AL,10
OUT C8,AL
MOV AL,00
OUT C8,AL
HLT
CHANNEL 0,IN MODE 0
LSB OF COUNT
MSB OF COUNT
HALT THE PROGRAM
RESULT:
Thus the desired delay is produced to generate square wave using 8253 interfacing kit.
ROUND-ROBIN TASK SCHEDULING
AIM:
To demonstrate the use of VxWorks round-robin task scheduling facilities.
DESCRIPTION:
ROUND-ROBIN SCHEDULING
A round-robin scheduling algorithm attempts to share the CPU fairly among all ready tasks of the same priority. Without round-robin scheduling, when multiple tasks of equal priority must share the processor, a single task can usurp the processor by never blocking, thus never giving other equal priority tasks a chance to run.Round-robin scheduling achieves fair allocation of the CPU to tasks of the samePriority by an approach known as time slicing. Each task executes for a definedinterval or time slice; Round-robin scheduling can be enabled with routine kernelTimeSlice(), which takes a parameter for a time slice, or interval. The interval is the amount of time each task is allowed to run before relinquishing theprocessor to another equal priority task.The following routine controls round-robin task scheduling:
kernelTimeSlice(int ticks): Control round-robin scheduling. The number of ticks(60 ticks equate to one second) determine the duration of the time slice.
PROCEDURE:
• Initialize function to create three tasks.• Create tasks by using spawn• Turn on round robin using TIMESLICE• Run the examples by executing the main routine("sched") of the example on the WindShterminal.
PROGRAM:
#include "vxWorks.h"#include "taskLib.h"#include "kernelLib.h"#include "sysLib.h"#include "logLib.h"void taskOne(void);void taskTwo(void);void taskThree(void);#define ITER1 100#define ITER2 10#define PRIORITY 101#define TIMESLICE sysClkRateGet()#define LONG_TIME 1000000
void sched(void) {
int taskIdOne, taskIdTwo, taskIdThree;
if(kernelTimeSlice(TIMESLICE) == OK) printf("\n\n\n\n\t\t\tTIMESLICE = %d seconds\n\n\n", TIMESLICE/60);
if((taskIdOne =taskSpawn("task1",PRIORITY,0x100,20000,(FUNCPTR)taskOne,0,0,0,0,0,0,0,0,0,0)) == ERROR)
printf("taskSpawn taskOne failed\n");
if((taskIdTwo =taskSpawn("task2",PRIORITY,0x100,20000,(FUNCPTR)taskTwo,0,0 ,0,0,0,0,0,0,0,0)) == ERROR)
printf("taskSpawn taskTwo failed\n");
if((taskIdThree = taskSpawn("task3",PRIORITY,0x100,20000,(FUNCPTR)taskThree,0 ,0,0,0,0,0,0,0,0,0)) == ERROR) printf("taskSpawn taskThree failed\n");
}
void taskOne(void){
int i,j;for (i=0; i < ITER1; i++){ for (j=0; j < ITER2; j++) logMsg("\n",0,0,0,0,0,0); for (j=0; j < LONG_TIME; j++); }
}
void taskTwo(void){
int i,j;for (i=0; i < ITER1; i++){ for (j=0; j < ITER2; j++) logMsg("\n",0,0,0,0,0,0); for (j=0; j < LONG_TIME; j++); }
}
void taskThree(void){
int i,j;for (i=0; i < ITER1; i++){ for (j=0; j < ITER2; j++) logMsg("\n",0,0,0,0,0,0); for (j=0; j < LONG_TIME; j++); }
}
RESULT:
Thus Round Robin Scheduling is executed using vxWorks.
PREEMPTIVE PRIORITY BASEDTASK SCHEDULING
AIM:
To demonstrate the use of VxWorks preemptive priority based task scheduling facilities.
Description:
PREEMPTIVE PRIORITY BASED SCHEDULING
With a preemptive priority based scheduler, each task has a priority and the kernel insures that the CPU is allocated to the highest priority task that is ready to run.This scheduling method is preemptive in that if a task that has a higher prioritythan the current task becomes ready to run, the kernel immediately saves the current tasks's context and switches to the context of the higher priority task.The Wind kernel has 256 priority levels(0-255). Priority 0 is the highest andpriority 255 is the lowest. Tasks are assigned a priority when created; however,while executing, a task can change its priority using taskPrioritySet().
1. EXAMPLE: PREEMPTIVE PRIORITY BASED SCHEDULINGOne of the arguments to taskSpawn() is the priority at which the task is to execute:
id = taskSpawn(name, priority, options, stacksize, function, arg1,.. , arg10);
By varying the priority(0-255) of the task spawned, you can affect the priority of the task.Priority 0 is the highest and priority 255 is the lowest. In addition a task's priority can be changed after its spawned using the following routine:
taskPrioritySet(int tid, int newPriority): Change the priority of a task.
Three tasks with different priorities(HIGH,MID,LOW) are given. The result of running the program is that the task with the highest priority, "taskThree" will run to completion first, followed by the next highest priority task, "taskTwo", and the finally the task with the lowest priority which is "taskOne
PROCEDURE:
• Initialize functions to create two tasks.• Create tasks using spawn• Initialize priority to tasks.• Run the examples by executing the main routine("sched") of the example on WindShterminal.
PROGRAM:
#include "vxWorks.h"#include "taskLib.h"#include "logLib.h"void taskOne(void);void taskTwo(void);void taskThree(void);#define ITER1 100#define ITER2 1#define LONG_TIME 1000000#define HIGH 100 #define MID 101 #define LOW 102
void sched(void) {
int taskIdOne, taskIdTwo, taskIdThree;
printf("\n\n\n\n\n");if((taskIdOne = taskSpawn("task2",LOW,0x100,20000,(FUNCPTR)taskOne,0,0,0,0,
0,0,0,0,0,0)) == ERROR) printf("taskSpawn taskOne failed\n");if((taskIdTwo = taskSpawn("task2",MID,0x100,20000,(FUNCPTR)taskTwo,0,0,0,0,
0,0,0,0,0,0)) == ERROR) printf("taskSpawn taskTwo failed\n");if((taskIdThree = taskSpawn("task3",HIGH,0x100,20000,(FUNCPTR)taskThree,0,0,0 ,0,0,0,0,0,0,0)) == ERROR) printf("taskSpawn taskThree failed\n");
}
void taskOne(void){
int i,j;
for (i=0; i < ITER1; i++){ for (j=0; j < ITER2; j++) logMsg("\n",0,0,0,0,0,0); for (j=0; j < LONG_TIME; j++);}
}
void taskTwo(void){
int i,j;for (i=0; i < ITER1; i++){ for (j=0; j < ITER2; j++) logMsg("\n",0,0,0,0,0,0); for (j=0; j < LONG_TIME; j++);}
}
void taskThree(void){
int i,j;
for (i=0; i < ITER1; i++){ for (j=0; j < ITER2; j++) logMsg("\n",0,0,0,0,0,0); for (j=0; j < LONG_TIME; j++);}
}
RESULT:
Thus Preemptive Priority Scheduling is executed using vxWorks.
PID CONTROLLER
AIM:
To demonstrate the working of transfer function, P controller, PD controller, PI controller and PID controller using MATLAB.
DESCRIPTION:
Transfer Functions: - For Matlab modelling we need Transfer Functions - To find the Transfer Function of a given system we need to take the Laplace transform of the system modelling equations (2) & (3)
System modelling equations:F = mv˙ + bv (2)y = v (3)
Laplace Transform:F(s) = msV (s) + bV (s)Y (s) = V(s)
Characteristics of PID Controllers
• Proportional Controller Kp-reduces the rise time-reduces but never eliminates steady-state error
• Integral Controller Ki-eliminates steady-state error-worsens transient response
• Derivative Controller Kd-increases the stability of the system-reduces overshoot-improves transient response
Functions used:
h = t f (num, den )
s y s = feedback ( forward , backward ) ;
Transfer function:
P Transfer Function:
PD Transfer Function:
PI Transfer Function:
PID Transfer Function:
PROCEDURE:
• Find out the transfer function for given values (m, b, k)
• Find out Proportional(P), Proportional Derivative(PD), Proportional Integral(PI), Proportional Integral Derivative(PID) for given transform
• Plot the results.
CODING:
TRANSFER FUNCTION:
%{ Set up v a r i a b l e s%} m=1; b=10; k=20;%{ C a l c u l a t e response%} num=1; den=[m, b , k ] ; p l a n t=t f (num, den ) ; step ( plant )
P CONTROLLER:
%{ Set up v a r i a b l e s%} m=1; b=10; k=20;%{ C a l c u l a t e response%} num=1; den=[m, b , k ] ; p l a n t=t f (num, den ) ; step ( plant )
%{Set up p r o p o r t i o n a l gain%}
Kp=300;
%{ C a l c u l a t e c o n t r o l l e r%} s y s c t l=feedback (Kp ∗ plant , 1 ) ; %{ Plot r e s u l t s%} t =0 : 0 . 0 1 : 2 ; step ( sys c t l , t )
PD CONTROLLER:
%{ Set up v a r i a b l e s%} m=1; b=10; k=20;%{ C a l c u l a t e response%} num=1; den=[m, b , k ] ; p l a n t=t f (num, den ) ; step ( plant )
%{Set up p r o p o r t i o n a l and d e r i v a t i v e gain%} Kp=300; Kd=10; %{ C a l c u l a t e c o n t r o l l e r%} contr=t f ( [ Kd, Kp ] , 1 ) ; s y s c t l=feedback ( contr ∗ plant , 1 ) ; %{ Plot r e s u l t s%} t =0 : 0 . 0 1 : 2 ; step ( sys c t l , t )
PI CONTROLLER:
%{ Set up v a r i a b l e s%} m=1; b=10; k=20;%{ C a l c u l a t e response%} num=1; den=[m, b , k ] ; p l a n t=t f (num, den ) ; step ( plant )
%{Set up p r o p o r t i o n a l and i n t e g r a l gain%} Kp=30; Ki =70; %{ C a l c u l a t e c o n t r o l l e r%} contr=t f ( [ Kp, Ki ] , [ 1 , 0 ] ) ; s y s c t l=feedback ( contr ∗ plant , 1 ) ; %{ Plot r e s u l t s%} t =0 : 0 . 0 1 : 2 ; step ( sys c t l , t )
PID CONTROLLER:
%{ Set up v a r i a b l e s%} m=1; b=10; k=20;%{ C a l c u l a t e response%} num=1; den=[m, b , k ] ; p l a n t=t f (num, den ) ; step ( plant )
%{Set up p r o p o r t i o n a l and i n t e g r a l gain%} Kp=350; Ki =300; Kd=50; %{ C a l c u l a t e c o n t r o l l e r%} contr=t f ( [Kd, Kp, Ki ] , [1 , 0 ] ) ; s y s c t l=feedback ( contr ∗ plant , 1 ) ; %{ Plot r e s u l t s%} t =0 : 0 . 0 1 : 2 ; step ( sys c t l , t )
PID Controller:
RESULT:
Thus the program for P,PI,PD and PID controller was executed using MATLAB successfully and verified.
MODELLING OF COMBINATIONAL DIGITAL SYSTEM
AIM:
To write the verilog code for simulation of following combinational circuits using Xilinx IDE.
i. Multiplexer
ii. Comparator
iii. Arithmetic Logic Unit
iv. Carry Look-ahead Adder
v. Ripple Carry Adder
DESCRIPTION:
Verilog HDL is a Hardware Description Language that can be used to model a digital system at many levels of abstraction ranging from the algorithmic level to the gate-level to switch level. Verilog has a variety of constructs as part of it. All are aimed at providing a functionally tested and a verified design description for the target FPGA or ASIC. The language has a dual function: one fulfilling the need for a design description and the other is fulfilling the need for verifying the design for functionality and timing constraints like propagation delay, critical path delay, setup and hold times. In addition, the language provides a programming language interface through which the internals of a design can be accessed during simulation including the control of a simulation run.
The digital circuit can be modeled in three different styles. Those are gate level, data flow and behavioral. In addition with switch level modeling is also used.
The design that is specified and entered is simulated for functionality and fully debugged. Test inputs can be purely combinational, periodic, numeric sequences, random inputs, conditional inputs, or combination of those.Translation of the debugged design into the corresponding hardware circuit is called synthesis. Test bench is also provided in verilog to generate stimulus for simulation.
PROCEDURE:
• Create new project in Xilinx IDE.
• Enter the verilog code.
• Debug the code using synthesis XST.
• Create test bench waveform.
• Simulate the stimulus to get results.
CODING:
MULTIPLEXER:
module mux(i0, i1, i2, i3,select, y);
input i0;
input i1;
input i2;
input i3;
input[1:0]select;
output y;
reg y;
always@(i0 or i1 or i2 or i3 or select)
case(select)
2'b00:y=i0;
2'b01:y=i1;
2'b10:y=i2;
2'b11:y=i3;
endcase
endmodule
ARITHMETIC LOGIC UNIT:
module al4(out,a,b,s);
output [3:0]out;
input [3:0]a,b;
input [3:0]s;
assign out=(s==1) ? a+b:(s==2) ? a-b:(s==3) ? a|b:(s==4) ? a&b:(s==5) ? ~(a&b):(s==6) ? ~(a|b):(s==7) ? a^b:(s==8) ? (a~^b):~a;
end module
CARRY LOOK-AHEAD ADDER:
module gem(sum,c_out,a,b,c_in);
output[3:0]sum;
output c_out;
input[3:0]a,b;
input c_in;
wire p0,g0,p1,g1,p2,g2,p3,g3;
wire c4,c3,c2,c1;
assign p0=a[0]^b[0],
p1=a[1]^b[1],
p2=a[2]^b[2],
p3=a[3]^b[3];
assign g0=a[0]&b[0],
g1=a[1]&b[1],
g2=a[2]&b[2],
g3=a[3]&b[3];
assign c1=g0|(p0&c_in),
c2=g1|(p1&g0)|(p1&p0&c_in), c3=g2|(p2&g1)|(p2&p1&p0)|(p2&p1&p0&c_in),
c4=g3|(p3&g2)|(p3&p2&g1)|(p3&p2&p1&g0)|(p3&p2&p1&p0&c_in);
assign sum[0]=p0^c_in,
sum[1]=p1^c1,
sum[2]=p2^c2,
sum[3]=p3^c3;
assign c_out=c4;
endmodule
RIPPLE CARRY ADDER:
module rip(sum,cout,a,b,cin);
output cout;
output [3:0] sum;
input [3:0] a,b;
input cin;
wire c1,c2,c3;
assign sum[0]=(a[0]^b[0]^cin);
assign c1=(a[0]&b[0])|(cin&(a[0]^b[0]));
assign sum[1]=(a[1]^b[1]^c1);
assign c2=(a[1]&b[1])|(c1&(a[1]^b[1]));
assign sum[2]=(a[2]^b[2]^c2);
assign c3=(a[2]&b[2])|(c2&(a[2]^b[2]));
assign sum[3]=(a[3]^b[3]^c3);
assign cout=(a[3]&b[3])|(c3&(a[3]^b[3]));
endmodule