embedded systems lab manual

80
SEC - ECE EMBEDDED SYSTEMS LAB RECORD SWITCH INTERFACING #include<LPC21xx.H> int main() { IODIR1=0X00FF0000; while(1) { IOCLR1=0x00FF0000; IOSET1= ((IOPIN0&0X0000FF00)<<0X08); } } STEPPER MOTOR INTERFACING: #include<LPC21xx.H> void delay() { unsigned int i; for(i=0;i<=10000;i++); } int main() { IODIR0=0X000000FF; for(;;) { IOSET0=0X00000051; delay(); IOCLR0=0x00000051; IOSET0= 0x00000062; delay(); IOCLR0=0x00000062; IOSET0= 0x00000094; delay(); IOCLR0=0x00000094; IOSET0= 0x000000A8; delay(); IOCLR0=0x000000A8; } } LED DISPLAY #include<LPC21xx.H> void delay() { unsigned int i; for(i=0;i<=10000;i++); } int main() { IODIR0=0X000000FF; for(;;) { IOSET0=0X000000FF; delay(); IOCLR0=0x000000FF; } } SWITCH SAMPLE OUTPUT 1

Upload: tmuthu123

Post on 29-Oct-2014

497 views

Category:

Documents


9 download

DESCRIPTION

EC 1404 Trichy Anna University Syllabus

TRANSCRIPT

Page 1: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

SWITCH INTERFACING #include<LPC21xx.H>int main(){IODIR1=0X00FF0000;while(1){IOCLR1=0x00FF0000;IOSET1= ((IOPIN0&0X0000FF00)<<0X08);} }STEPPER MOTOR INTERFACING: #include<LPC21xx.H>void delay(){unsigned int i;for(i=0;i<=10000;i++);}int main(){IODIR0=0X000000FF;for(;;){IOSET0=0X00000051; delay(); IOCLR0=0x00000051;IOSET0= 0x00000062; delay(); IOCLR0=0x00000062;IOSET0= 0x00000094; delay(); IOCLR0=0x00000094;IOSET0= 0x000000A8; delay(); IOCLR0=0x000000A8;} }LED DISPLAY#include<LPC21xx.H>void delay(){unsigned int i;for(i=0;i<=10000;i++);}int main(){IODIR0=0X000000FF;for(;;){IOSET0=0X000000FF; delay(); IOCLR0=0x000000FF;} } SWITCH SAMPLE OUTPUT

1

Page 2: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

EX NO: DATE:

VERIFICATION AND VALIDATION USING Keil IDE

AIM

To verify and validate the given applications using industry standard Integrated Development Environment Keil µ vision ARM-MDK.

LED Display, Stepper motor, Switch interfacing.

TOOLS REQUIRED:

S.NO Name Type1 Keil µvision4 IDE2 ARM 7-LPC 2148 Microcontroller

ALGORITHM:

STEPPER MOTOR INTERFACING: Include the < LPC214x.H> header file Configure the Port0 pins (P0.0to P0.7) as GPI0 using Pin Selection Zero Register

(PINSEL0). Configure the Input Output Direction zero register (IODIR 0), to make the Input mode of

Port zero pins (P0.0 to P0.3) Configure the Input Output Direction zero register (IODIR 0), to make the Output mode of

Port zero pins (P0.4 to P0.7) Based on the stepper motor winding sequence, make the corresponding port pins to active

high through Input Output Pin zero Register (IOPIN 0) Call the delay program

SWITCH INTERFACING Include the < LPC214X.H> header file Configure the Port 0 pins (P0.16 to P0.23) as GPI0 using Pin Selection one Register

(PINSEL1). Configure the Input Output Direction zero register (IODIR 0) for selecting input and

output operation of Port0 pins (P0.16 to P0.23) as per hardware pins schematic. Based on the IO interfacing, make the corresponding port pins to active high through Input

Output Set zero Register (IOSET0) register. Call the delay program To reset the output port pin, make corresponding port pin to active high through Input

Output Clear Zero Register ( IOCLR0) PROCEDURE:

Click on the D (debug icon) to start the debugger simulator program. Based on the application, place the necessary peripheral on the simulator window. To verify the execution, apply the appropriate inputs through port pins and then validate

the results.RESULT:

Thus the switch, stepper motor interfacing programs were verified and validated successfully.

MULTITASKING PROGRAM

2

Page 3: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

#include <LPC21xx.H> /* LPC21xx definitions */#include <ucos.h>#include <board.h>#define TASK_STK_SIZE 100 /* Size of each task's stacks (# of WORDs) */#define NO_TASKS 3 /* Number of identical tasks */char TaskData[NO_TASKS]; OS_STK TaskStk[NO_TASKS][TASK_STK_SIZE]; /* Tasks stacks */OS_STK TaskStartStk[TASK_STK_SIZE];extern void init_timer (void); void Task2 (void *data){int n, i;

data = data; // avoid compiler warningwhile(1)

{for (n = 0x00080000; n <= 0x04000000; n <<= 1) {

*IOSET0 = n; /* Blink LED 5, 6 ,7 ,8*/ /* Turn on LED */ OSTimeDly(10); /* Wait one second */

*IOCLR0 = n; /* Turn off LEDs */ OSTimeDly(10); /* Wait one second */

i++;q_printf("LoPrio "); } } }

void Task1 (void *data){ int n, i;

data = data; // avoid compiler warningwhile(1)

{for (n = 0x00008000; n <= 0x00040000; n <<= 1)

{*IOSET0 = n; /* Blink LED 1,2, 3, 4 */q_printf("Task1 LEDON ");

OSTimeDly(10); /* Wait one second */q_printf("Task1 LEDOFF ");*IOCLR0 = n; /* Turn off LEDs */

OSTimeDly(10); /* Wait one second */q_printf("%s", "HiPrioTsk ");i++;

} } }void startTask(void *data){init_timer();TaskCreate(Task1, (void *)&TaskData[0], "HiPrioTsk", 1); TaskCreate(Task2, (void *)&TaskData[1], "LoPrioTsk", 2);while (1)

{ OSTimeDly(1000); }}int main (void) {

*IODIR0 = 0x007F8000; OSInit(); /* Initialize uC/OS-II */

init_timer(); TaskCreate(startTask, (void *)0, "VHiPrioTsk", 0);

OSStart(); /* Start multitasking */return 0; // Actually we should never come here

}EX NO: DATE:

3

Page 4: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

VERIFICATION AND VALIDATION USING RTOS

AIM

To verify and validate the multitasking applications using industry standard open source RTOS.

TOOLS REQUIRED:

S.NO Name Type

1 Triton IDE

2 Flash Fusion Fusing software

3 µC-OS-II RTOS

HARDWARE REQUIRED:

S.NO Name Type Quantity

1 ARM 7 - LPC 2148 Microcontroller kit 1

2 DC source (0-12)V 1

ALGORITHM

MULTITASKING Include the header file LPC21xx.h , Board.h and ucos.h Define the Stack size and number of tasks Initialize the Task Stack size and number of task Call the Timer function initialization With in the main function, initialize the µC-OS-II kernel Call the Timer function initialization Crate the Start Up Task To start the multitasking call the function OSStart. Terminate the main program With in the startup creation, initialize the timer function call and create the remaining tasks

named as task1 and task1 Give the time delay for the task With in the task 1 and task 2 write the LED control operation code with time delay

RESULT:

Thus the multitasking and message queue programs were verified and validated successfully.

PROGRAM - LED blinking

4

Page 5: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

#include "inc/hw_memmap.h"#include "inc/hw_types.h"#include "driverlib/gpio.h"#include "driverlib/sysctl.h"int main(void){SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);unsigned long count;while(1) { GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0); for(count=0;count<200000;count++){}GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_PIN_5); for(count=0;count<200000;count++){ }}}PROGRAM – RGB Pattern#include "inc/hw_memmap.h"#include "inc/hw_types.h"#include "driverlib/gpio.h"#include "driverlib/sysctl.h"int main(void){SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7, 0);unsigned long count;while(1) {GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0);for(count=0;count<200000;count++){}GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_PIN_5); for(count=0;count<200000;count++){}}}

EX NO: DATE:

5

Page 6: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

VERIFICATION AND VALIDATION USING OPEN SOURCE SOFTWARE

AIM

To verify and validate the LED blinking and RGB Pattern applications using industry standard open source ECLIPSE IDE.

TOOLS REQUIRED:

S.NO Name Type1 Eclipse IDE2 LM Flash Programmer3 GNU Make ARM Tool Chain 4 Stellaris Ware Driver library5 FTDI VCP USB Driver

HARDWARE REQUIRED:

S.NO Name Type Quantity1 CortexM3-LM3S608 µC Microcontroller kit 1

ALGORITHM – LED blinking

Include the necessary header files Select the Clock divider value, oscillator type selection and frequency by using

SysCtlClockSet function. Enable the system control for peripheral GPIO Port C using SysCtlPeripheralEnable

function. Configure the Port C Pins 5, 6 and 7 as output using GPIOPinTypeGPIOOutput function.

(Refer appendix c for circuit diagram) Based on the application, write the necessary logic value on the port pins using

GPIOPinWrite function. Call the delay function whenever needed.

ALGORITHM – RGB Pattern Include the necessary header files Select the Clock divider value, oscillator type selection and frequency by using

SysCtlClockSet function. Enable the system control for peripheral GPIO Port C using SysCtlPeripheralEnable

function. Configure the Port C Pins 5, 6 and 7 as output using GPIOPinTypeGPIOOutput function. Based on the application, write the necessary logic value on the port pins using

GPIOPinWrite function. Call the delay function whenever needed.

Result:

Thus the above applications are verified and validated using open source eclipse IDE for ARM Cortex M3 –LM3s608 Microcontroller.

a) BUZZER

6

Port Pin No Description

P0.7 Buzzer

Page 7: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

b) LED

LED No Port Pin No Description

1 P0.15 LED 8

2 P0.16 LED 7

3 P0.17 LED 6

4 P0.18 LED 5

5 P0.19 LED 4

6 P0.20 LED 3

7 P0.21 LE0 2

8 P0.22 LED 1

c) RELAY Port Pin

NoDescription

P1.26 Relay

d) 7 SEGMENT

EXNO: DATE:

7

Sl no Port Pin No Description

1 P1.16 A

2 P1.17 B

3 P1.18 C

4 P1.19 D

5 P1.20 E

6 P1.21 F

7 P1.22 G

8 P1.23 . (dp)H

9 P0.28 S 1

10 P1.24 S 2

11 P0.25 S 3

12 P0.11 S 4

Page 8: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

HIGH LEVEL LANGUAGE PROGRAMMING AND PORTING

AIM

To write the C language program and porting it on the ARM 7 core for the following interfacing

a) Buzzer,

b) LED,

c) Relay,

d) 7 segments LED,

e) 2x16 LCD,

f) UART.

TOOLS REQUIRED:

S.NO Name Type

1 Triton IDE

2 Flash Fusion Fusing software

HARDWARE REQUIRED:

S.NO Name Type Quantity

1 ARM 7 - LPC 2148 Microcontroller kit 1

2 DC source (0-12)V 1

ALGORITHM:

a) BUZZER

Include the header file <LPC21XX.H>. Include the header file <BOADR.H>. Configure the Port 0 pins (P0.7) as GPI0 using Pin Selection one Register (PINSEL0). Configure the Input Output Direction zero register (IODIR 0) for selecting output

operation of Port0 pin (P0.7) To turn ON the Buzzer load the IOSET0 register value as 0x00000080 Call the Delay program. To turn OFF the Buzzer load the IOCLR0 register value as 0x00000080

a) BUZZER#include<LPC21xx.h>

8

Page 9: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

#include<board.h>void delay();void main(){*IODIR0=0X00000080;while (1){*IOSET0 = 0X00000080; delay(); *IOCLR0= 0X00000080; delay();}}void delay(){int i,j;

for(i=1;i<15000;i++);}

b) LED PROGRAM #include<LPC21xx.h>#include<BOARD.H>void delay();void main(){*IODIR0=0x007F8000;while(1){*IOSET0=0x007F8000; delay(); *IOCLR0=0x007F8000; delay();} }void delay(){unsigned int i,j;for (i=1;i<150000;i++); }C)RELAY PROGRAM

#include<LPC21xx.H>#include<BOARD.H>void delay();void main(){*IODIR1=0x04000000;while(1){*IOSET1=0x04000000; delay(); *IOCLR1=0x04000000; delay();}}void delay(){int i,j;for(i=1;i<15000;i++);for(j=0;j<15000;j++);}

b)LED

9

Page 10: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Include the header file <LPC21XX.H>. Include the header file <BOADR.H>. Configure the Port 0 pins (P0.15 – P0.22) as GPI0 using Pin Selection one Register

(PINSEL0). Configure the Input Output Direction zero register (IODIR 0) for selecting output

operation of Port0 pin (P0.15 – P0.22) To turn ON the LED’s load the IOSET0 register value as logic one between the Port Pins

(P0.15 & P0.22 Call the Delay Program. To turn OFF the LED’s load the IOCLR0 register value as logic one between the Port Pins

(P0.15 & P0.22

c) RELAY

Include the header file <LPC21XX.H>. Include the header file <BOADR.H>. Configure the Input Output Direction One register (IODIR 1) for selecting output

operation of Port1 pin (P1.26) To turn ON the Relay load the IOSET1 register value as 0x04000000 Call the Delay Program. To turn OFF the Relay load the IOCLR1 register value as0x04000000

d) 7 SEVEN SEGMENT

Include the header file <LPC21XX.H>. Include the header file <BOADR.H>. Configure the Input Output Direction One register (IODIR 1) for selecting output

operation of Port1 pins (P1.16 – P1.23). To display the hexadecimal number on the 7 segment display Load the corresponding

binary bit formats in the Port1 Input Output Set Register as 003F0000 (for zero) Call the Delay Program. To clear the displayed character ,on the 7 segment display, Load the corresponding

binary bit formats in the Port1 Input Output Clear Register as 003F0000 (for zero)

e) 2x16 LCD DISPLAY

d) 7 SEGMENT PROGRAM#include<lpc21xx.h>#include<BOARD.H>

10

Page 11: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

void delay(){

int i;for(i=0;i<=200000;i++);

}main(){*IOSET0 = 0x12000800; //select Seven Segment S1 ,S3,S4//*IOSET1 = 0X01000000; //Select Seven Segment S2*IODIR1=0X00FF0000;while(1){

*IOSET1=0X003F0000; delay(); *IOCLR1=0X003F0000; delay();*IOSET1=0X00060000; delay(); *IOCLR1=0X00060000; delay()*IOSET1=0X005B0000; delay(); *IOCLR1=0X005B0000; delay();*IOSET1=0X004F0000; delay(); *IOSET1=0X004F0000; delay();*IOSET1=0X00660000; delay(); *IOCLR1=0X00660000; delay();*IOSET1=0X006D0000; delay(); *IOCLR1=0X006D0000; delay();*IOSET1=0X003C0000; delay(); *IOCLR1=0X003C0000; delay();*IOSET1=0X00070000; delay(); *IOCLR1=0X00070000; delay();*IOSET1=0X007F0000; delay(); *IOCLR1=0X007F0000; delay();*IOSET1=0X00670000; delay(); *IOCLR1=0X00670000; delay();*IOSET1=0X00770000; delay(); *IOCLR1=0X00770000; delay();*IOSET1=0X007F0000; delay(); *IOCLR1=0X007F0000; delay();*IOSET1=0X00390000; delay(); *IOCLR1=0X00390000; delay();*IOSET1=0X003F0000; delay(); *IOCLR1=0X003F0000; delay();*IOSET1=0X00790000; delay(); *IOCLR1=0X00790000; delay();*IOSET1=0X00710000; delay(); *IOCLR1=0X00710000; delay();

} }

e) LCD interfacing Include the header file <LPC21XX.H>. & <BOADR.H>. Configure the Input Output Direction One register (IODIR 1) for selecting output port

operation of Port1 pins (P1.16 – P1.23) to send the data’s (D0-D7) Configure the Input Output Direction Zero register (IODIR 0) for selecting output port

operation of Port0 pins (P0.28 –P0.29) to select the Register bank Selection(RS) & Enable signal to the LCD

Send the command words to the LCD through Input Output Set One register (IOSET1) and give the appropriate control signals through IOSET0 Register

Call the delay program , while giving high to low enable signal Send the data words to the LCD through Input Output Set One register (IOSET1) and give

the appropriate control signals through IOSET0 Register

f) UART PROGRAMMING UART Transmitter

Include the <LPC214X.h> & <BOADR.H>.header file.

11

Page 12: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Configure the Port0 pin for UART0 TXD and RXD function for transmitting and receiving the data.

Load the value 83 on the UART Zero Line Control Register (U0LCR) to frame the message format.

Load the Device Latch LSB register (DLL) & Device Latch MSB register (DLM) register to select the baud rate.

Load the value 0x03 on the UART Zero Line Control Register (U0LCR) to latch the baud rate selection values.

load the data in to Transmit Holding Register (U0THR) for data transmissionUART Receiver

Include the <LPC214X.h> & <BOADR.H>.header file. Configure the Port0 pin for UART0 TXD and RXD function for transmitting and receiving

the data. Load the value 83 on the UART Zero Line Control Register (U0LCR) to frame the message format.

Load the Device Latch LSB register (DLL) & Device Latch MSB register (DLM) register to select the baud rate. Load the value 0x03 on the UART Zero Line Control Register (U0LCR) to latch the baud rate selection values.

Copy the received data from Receiver Buffer Register (U0RBR).

d) LCD interfacing

#include<lpc21xx.h>#include<BOARD.H>

12

Page 13: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

void command(unsigned int comm);void lcdout(unsigned int data);void delay_lcd(void);#define RS 0X20000000;#define DIOW 0x10000000;int main(void){*IODIR1=0X00FF0000; *IODIR0=0X30000000;command(0x38); command(0x0c); command(0x01);

lcdout('E'); lcdout('C'); lcdout('E'); lcdout(' '); lcdout('S');lcdout('E'); lcdout('C'); lcdout(' '); lcdout(' '); lcdout('E');lcdout('S'); lcdout(' '); lcdout('L'); lcdout('A'); lcdout('B');}void delay(){ unsigned int i;

for(i=0;i<5000 ;i++); return ;}void command(unsigned int comm){

*IOCLR1=0x00ff0000;*IOCLR0=DIOW;comm=comm<<16;

*IOSET1=comm; *IOCLR0=RS; delay(); *IOSET0=RS; delay();return;

}void lcdout(unsigned int data){ *IOCLR1=0x00ff0000;

*IOSET0=DIOW;data = data << 16;

*IOSET1 = data; *IOSET0=RS; delay(); *IOCLR0=RS;return; }

e) UART Transmitter #include<LPC21xx.h>#include<board.h>int main(void){

char a[ ]="ECE";int i;*PINSEL0=0x01; /* Programming 0.0th Pin - Transmit data Pin */*U0LCR=0x83; /* 8 -> Device lab = 1 , 3 -> 8 bit transmission*/*U0DLM=0x00; /* Device latch MSB = 0 */*U0DLL=0x18; /* Sets Baud rate */*U0LCR=0x03; while(1){

while(!(*U0LSR & 0x20));for(i=0;a[i]!='\0';i++)*U0THR= a[i]; }

return 0; }

13

Page 14: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Receiver#include<LPC21xx.h>#include<board.h>void delay(void){

int j; for (j=0;j<50000;j++);}

int main(void) {unsigned int ALL;

*IODIR0=0x007f8000;*PINSEL0 = 0x05; /* Programming 0.0th Pin - Transmit data Pin */*U0LCR=0x83; /* 8 -> Device lab = 1 , 3 -> 8 bit transmission*/

/* Device latch MSB = 0 */*U0DLL=0x61; /* Sets Baud rate */*U0LCR=0x03; while(1){

while (!(*U0LSR&0x01));{

ALL=*U0RBR;*IOSET0=ALL<<15;delay();

*IOCLR0=ALL<<15;delay();}}}

RESULT

Thus the C language program was written and ported it on the ARM 7 core for the following interfacing

Buzzer, LED, Relay, 7-segment LED, 2x16 LCD, and UART.

STATE DIAGRAM

RESET=1

14

Page 15: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

RTL DIAGRAM

EXNO: DATE:

S0

S1

S2

S3

S4

S5

S66

S7

15

Page 16: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

COUNTER IMPLEMENTATION USING FSM

AIM:

To write the verilog code for a 3 bit counter using Finite State Machine behavior and implement it on FPGA.

HARDWARE REQUIRED:

S.NO Name Type

1 FPGA

spartan3

xc3s400

pq208

-4

Device

architecture,

device

package

speed grade

2 Xilinx 9.1 ISE

THEORY

Finite-state machine (FSM) or finite-state automaton (plural: automata), or simply a state machine, is a behavioral model used to design computer programs. It is composed of a finite number of states associated to transitions. A transition is a set of actions that starts from one state and ends in another (or the same) state. A transition is started by a trigger, and a trigger can be an event or a condition.

Finite-state machines can model a large number of problems, among which are electronic design automation, communication protocol design, parsing and other engineering applications. In biology and artificial intelligence research, state machines or hierarchies of state machines are sometimes used to describe neurological systems

3 bit counter program`define STATE0 3'b000`define STATE1 3'b001

16

Page 17: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

`define STATE2 3'b010`define STATE3 3'b011`define STATE4 3'b100`define STATE5 3'b101`define STATE6 3'b110`define STATE7 3'b111module counter(CLK,RESET, cnt);input CLK,RESET;output [2:0] cnt;

reg [2:0] next_cnt;integer count;assigncnt=next_cnt;always @ (posedge CLK)beginif(RESET)begincount=0;next_cnt=`STATE0;endelsebegincount=count+1;if (count ==1000000)begincase (cnt) `STATE0:beginnext_cnt=`STATE1;count=0;end `STATE1:beginnext_cnt=`STATE2;count=0;end `STATE2:beginnext_cnt=`STATE3;count=0;end `STATE3:beginnext_cnt=`STATE4;count=0;end `STATE4:beginnext_cnt=`STATE5;count=0;end `STATE5:beginnext_cnt=`STATE6;count=0;end `STATE6:beginnext_cnt=`STATE7;count=0;

17

Page 18: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

end `STATE7:beginnext_cnt=`STATE0;count=0;enddefault:next_cnt=`STATE0;endcaseendendendendmodule

Locked Pin constrains NET "CLK" LOC = P79;NET "RESET" LOC = P21;NET "cnt<0>" LOC = P20;NET "cnt<1>" LOC = P26;NET "cnt<2>" LOC = P28;

RESULT:Thus the FSM chart based 3 bit counter was verified and implemented successfully.

MULTIPLE OUTPUT PARALLEL LFSR ORDER 3 TRUTH TABLE

Present state 1,3 1,2 CLK

18

Page 19: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

1 0 0 1 0 1 1 1 1 1

1 1 1 1 10 1 0 0 1

1 0 0 1 0 1 1 1 1 1

1 1 1 110 1

LFSR CODING

modulePPG(clk,reset,sin,sout);inputclk;input reset;input [2:0]sin;output[6:0] sout;reg [2:0]a;reg [2:0]b;reg [2:0]c;reg [2:0]d;reg[6:0]temp;always@(posedgeclk)beginif(reset)temp=0;elsea[2:0]<=sin[2:0];temp[0]=a[2]^a[0];temp[1]=a[1]^a[0];b[2]<=temp[0];b[1]<=temp[1];b[0]<=a[0];temp[2]=b[2]^b[0];temp[3]=b[1]^b[0];c[0]<=b[0];c[1]<=temp[3];c[2]<=temp[2];temp[4]=c[2]^c[0];temp[5]=c[1]^c[0];d[2]<=temp[4];d[1]<=temp[5];d[0]<=c[0];temp[6]=d[2]^d[0];endassign s out=temp;endmoduleEXNO: DATE:

19

Page 20: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

CRYPTO SYSEM IMPLEMENTATION USING ARM & FPGA

AIM

To implement multiple output parallel LFSR using Xilinx FPGA and verify the mono

alphabetic encryption & decryption algorithm using ARM 7 LPC 2148 microcontroller

TOOLS REQUIRED

HARDWARE REQUIRED

SL.NO NAME TYPE QUANTITY

1 LPC2148 Micro controller kit 1

2 FPGA

spartan3

xc3s400

pq208

-5

Device

Architecture,

Device number

Package

Speed grade

1

3 DC Source (0-12)V 1

THEORY

LINEAR FEEDBACK SHIFT REGISTER

A LFSR is a shift-register where the output bit is an XOR function of some input bits. The initial value of the LFSR is called the seed. The outputs that influence the inputs are called taps. A LFSR is represented as a polynomial mod 2. The coefficients of the polynomial are either 1s or 0s.

For example, if the taps are at the 1st, 3rd bits, the polynomial is x3+ x+1. The structure shown is

called a serial architecture. If a polynomial is primitive, the corresponding LFSR can produce 2n-1 distinct patterns.

CRYPTO SYSTEM TRANSMITTER BLOCK DIAGRAM

20

SL.NO NAME TYPE

1 Triton IDE

2 Xilinx 9.1 ISE

Page 21: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

RESET

CLOCK

SIN [2:0]

SOUT [6:0]

NET "clk" LOC = P79;NET "reset" LOC = P21;NET "sin<0>" LOC = P27;NET "sin<1>" LOC = P29;NET "sin<2>" LOC = P35;NET "sout<0>" LOC = P20;NET "sout<1>" LOC = P26;NET "sout<2>" LOC = P28;NET "sout<3>" LOC = P34;NET "sout<4>" LOC = P36;NET "sout<5>" LOC = P39;NET "sout<6>" LOC = P42;PARALLEL LFSR

MULTIPLE OUTPUT PARALLEL LFSR LOGIC DESIGN

Xilinx FPGA XC3S400

21

LPC2148

TXD

BIT SHIFTER

BUFFER

MASKING UNIT

ENCRYPTING

ALGORITHM UART

TRANSMITTER MESSAGE

Page 22: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

The parallel architecture of an LFSR reduces dynamic power consumption and can generate more than one bit output per clock cycle. Here only one flip-flop is updated every clock cycle and instead of the bits moving from left to right in each clock cycle, the taps of the XOR tree move from right to left

The parallel architecture considers x3+ x+1 polynomial for obtaining multiple outputs in a

single clock cycle. The control signal Ti (i = 1, 2 ... N), which is used to connect the shift register to the output tap, is a sequentially occurring waveform. The control signal is high for only i mod N clock cycle, where N is the length of the LFSR The operations (1, 2) and (3, 1) are performed at T1, where (x, y) denotes XOR operation of x and y. These values are stored in flip-flop 2 and flip-flop 3 respectively. The overall operations can be summarized as shown in Table I. With the multiple output architecture, a polynomial, of the form 1+xk1+xk2+xk3+………+xN7 can generate

outputs in a single clock cycle. In the case of x3+ x+1, 2 outputs can be obtained in a single clock

PRIMITIVE POLYNOMIAL

A primitive polynomial may refer to one of two concepts:

1 A polynomial over a unique factorization domain (such as the integers) whose greatest

common divisor of its coefficients is one.

2 The minimal polynomial of a primitive element of the extension field GF (pm).

MAXIMUM LENGTH SEQUENCE PROPERTIES:

When the PN sequence generated by linear feed back shift register has the length of 2 r-1, it is called as maximum length sequence.

2 The length of the PN sequence generated by a primitive polynomial should be 2 r-1. If the output sequence satisfies this property, the polynomial is called as primitive. So the most secured communication is achieved.

3. The number of ones is always one more than the number of zeros in each period of the maximum length sequence whereas in truly randomsequence ones and zeros are equally probable.Maximal length sequence: Tc , Tb=NTc

0 0 1 1 0 1 1

Maximal length sequences

CRYPTOSYSTEM RECEIVER BLOCK DIAGRAM

22

Page 23: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

RESET

CLOCK

SIN [2:0]

SOUT [6:0]

RXD

RUN PROPERTY:

MULTIPLE OUTPUT PARALLEL LFSR LOGIC DESIGN

Xilinx FPGA XC3S400

TO LED’S

23

LPC2148

BIT SHIFTER

BUFFER

MASKING UNIT

DECRYPTION

ALGORITHM

MESSAGE

UART

RECEIVER

Page 24: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

The m n means the sub sequence of identical symbols 1’s or 0’s.With in one period of the sequence. The length of the run is equal to the length of the subsequence. When the maximum length sequence is generated by linear feed back shift register of length‘r’, total number of turns is 2r-1.In each period ofthe maximum length sequence there are one half runs of ones and zeros having length 1.There can be one fourth runs of ones and zeros having length 2 or there can be one eighth runs of ones and zeros having length 3 and so on.

CRYPTO SYSTEM

A cryptographically secure pseudo-random number generator (CSPRNG) is a pseudo-

random number generator (PRNG) with properties that make it suitable for use in cryptography.

Many aspects of cryptography require random numbers, for example:

Key generation

Salts in certain signature schemes, including ECDSA, RSASSA-PSS.

One-time pads

The "quality" of the randomness required for these applications varies. For the generation of a

nonce, only uniqueness might be required. For the generation of a master key, a higher quality is

needed. And in the case of one-time pads, the information-theoretic guarantee of unbreakable

cryptography only holds if the random stream is obtained from a true random source.

CRYPTOSYSTEM TRANSMITTER

Most stream ciphers work by generating a pseudorandom stream of bits that are XORed

with the message; this stream can often be used as a good CSPRNG Here the PN sequence is

masked to generate the secured key then the message (01000100=0x41) is added with the masked

key sequence (00000011=0x03). So we can get the encrypted bits of (01000100=0x44). This

encrypted data is transmitted through UART module of LPC 2148 microcontroller.

CRYPTO SYSTEM RECEIVER

The receiver also performs the same XOR operation but here the encrypted received data

(01000100=0x44) called cipher text is subtracted with the masked key value (00000011=0x03).

Hence we can get the original message signal (01000100=0x41) which is nothing but the original

plain text.

ENCRYPTION ALGORITHM

24

Page 25: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Include the < LPC214x.H> header file Configure the port0 pin of UART0 for transmitting the data Configure the Input Output Direction zero register (IODIR0), to make the Output mode of

Port zero pins (P0.15 to P0.23) Load the value 83 on the UART Zero Line Control Register (U0LCR) to frame the

message format. Load the Device Latch LSB register (DLL) & Device Latch MSB register (DLM) register

to select the baud rate. Load the value 0x03 on the UART Zero Line Control Register (U0LCR) to latch the baud

rate selection values. Fetch the LFSR sequence from FPGA to LPC2148 Micro Controller

Perform right shift operation for two times Based upon the key requirement Mask the shifted bits Encrypt the message using Mono alphabetic encryption algorithm View the encrypted data through UART transmitter or Terminal viewer

ENCRYPTION PROGRAM:

#include<lpc21xx.h>#include<BOARD.h>void delay(){unsigned int i;for(i=0;i<=20000;i++);}int main(void){unsigned int j,k,rt,t;*IODIR0=0x007f8000;*PINSEL0=0x01;/*programming0.0th pin- transmit data pin*/*U0LCR=0x83;/*8->Device lab=1,3->8 bit transmission*/*U0DLM=0x00;/*Device latch MSB=0*/*U0DLL=0x18;/*Set baud rate*/*U0LCR=0x03;while (1){j=*IOPIN0;k=((j& 0x000003fc)>>2);//delay();rt=(k&0x0000000f);while(!(*U0LSR&0x20));//for(i=0;a[i]!=’\0’;i++){t=(0x41+rt);*U0THR=t;*IOSET0=t<<15;delay();delay();*IOCLR0=t<<15;}}return 0; }DECRYPTION ALGORITHM

Include the < LPC214x.H> header file

25

Page 26: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Configure the port0 pin of UART0 for receiving the data Load the value 83 on the UART Zero Line Control Register (U0LCR) to frame the

message format. Load the Device Latch LSB register (DLL) & Device Latch MSB register (DLM) register to select the baud rate. Load the value 0x03 on the UART Zero Line Control Register (U0LCR) to latch the baud rate selection values.

Fetch the LFSR sequence from FPGA to LPC2148 Microcontroller Perform right shift operation for two times Based upon the key requirement Mask the shifted bits Decrypt the message using Mono alphabetic decryption algorithm View the decrypted message through LED

DECRYPTION PROGRAM:

#include<lpc21xx.h>#include<BOARD.h>void delay (void);void delay(){

unsigned int i;for(i=0;i<=20000;i++);}int main(void){unsigned int j,k,rt,r,t,ALL;*IODIR0=0x007f8000;*PINSEL0=0x05;*U0LCR=0x83;*U0DLL=0x18;*U0LCR=0x03;while(1){j=*IOPIN0;delay();while(!(*U0LSR&0x01));{k=(j&0x000007fc)>>2;rt=(k&0x0000000f);ALL=*U0RBR;r=ALL-rt;*IOSET0=r<<15;delay( );*IOCLR0=r<<15;}}return 0;}RESULT

Thus the multiple output parallel LFSR logic was implemented using Xilinx FPGA and the

mono alphabetic encryption and decryption algorithm was verified with LPC 2148

Microcontroller.

4X4 MARTIX KEYPAD

26

Page 27: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

EXNO: DATE:

SPEED CONTROL OF STEPPER MOTOR

27

Page 28: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

AIM

To develop an application to control the Stepper motor speed using LPC 2148 microcontroller.

TOOLS REQUIRED:

S.NO Name Type

1 Triton IDE

2 Flash Fusion Fusing software

HARDWARE REQUIRED:

S.NO Name Type Quantity

1 ARM 7 LPC 2148 Microcontroller kit 1

2 DC source (0-12)V 1

ALGORITHM:

Include the header file <LPC21XX.H>. Include the header file <BOADR.H>. Configure the Port 0 pins (P0.0 & P0.1) as UART0 operation using Pin Selection Zero

Register (PINSEL0). Configure the Input Output Direction One register (IODIR 1) for selecting output operation of

Port1 pins (P1.16 – P1.23) for 7 segment interface. Configure the Input Output Direction Zero register (IODIR 0) for selecting output and input

port operation of Port0 pins (P0.2 –P0.9) for 4x4 matrix keypad interface. Load the value 83 on the UART Zero Line Control Register (U0LCR) to frame the message

format. Load the Device Latch LSB register (DLL) & Device Latch MSB register (DLM) register to

select the baud rate. Load the value 0x03 on the UART Zero Line Control Register (U0LCR) to latch the baud rate

selection values. By using 4x4 matrix keypad select the various speed levels. This activates the motor control

signals respectively

STEPPER MOTOR SPEED CONTROL PROGRAM

#include<lpc21xx.h>#include<board.h>void delay(){unsigned int i;for(i=0;i<=10000;i++);}void delay1(){unsigned int i;for(i=0;i<=20000;i++);}int sendchar0(int ch){

28

Page 29: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

while(!(*U0LSR&0x20));return(*U0THR=ch);}int main(){unsigned int l;//*VICVectCntl0=0x20 |6;*PINSEL0=0x00000005;*U0LCR=0x83; /* 8 -> Device lab = 1 , 3 -> 8 bit transmission*/*U0DLM=0x00; /* Device latch MSB = 0 */*U0DLL=0x18; /* Sets Baud rate */*U0LCR=0x03; //*U0IER=0X02;*PINSEL2= *PINSEL2 & 0xFFFFFFF3;*IODIR1 = 0X01fF0000;*IODIR0=0x007f83fc;*IOCLR0=0x007f8000;{while(1){*IOCLR0=0x00000DFF;*IOSET0=0x00000200; if((*IOPIN0 & 0x0000003C)== 0x00000004){sendchar0 ('C'); *IOSET1 = 0x390000; //Display C*IOSET0=0x00006000;delay();*IOCLR0=0x00006000;*IOSET0=0x0000A000;delay();*IOCLR0=0x0000A000;*IOSET0=0x00009000;delay();*IOCLR0=0x00009000;*IOSET0=0x00005000;delay();*IOCLR0=0x00005000;*IOCLR1 = 0xff0000;}else if((*IOPIN0&0x0000003C)==0x00000008){sendchar0('8');*IOSET1 = 0x7f0000;*IOSET0=0x00006000;delay();delay();*IOCLR0=0x00006000;*IOSET0=0x0000A000;delay();delay();*IOCLR0=0x0000A000;*IOSET0=0x00009000;delay();delay();

29

Page 30: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

*IOCLR0=0x00009000;*IOSET0=0x00005000;delay();delay();*IOCLR0=0x00005000;*IOCLR1 = 0Xff0000;}else if((*IOPIN0&0x0000003C)==0x00000010){sendchar0('4');*IOSET1 = 0x660000; //Display 4*IOSET0=0x00006000;delay();delay();delay();*IOCLR0=0x00006000;*IOSET0=0x0000A000;delay();delay();delay();*IOCLR0=0x0000A000;*IOSET0=0x00009000;delay();delay();delay();*IOCLR0=0x00009000;*IOSET0=0x00005000;delay();delay();delay();*IOCLR0=0x00005000;*IOCLR1 = 0Xff0000;}else if((*IOPIN0&0x0000003C)==0x00000020){sendchar0('0');*IOSET1 = 0x3F0000; //Display 0*IOSET0=0x00006000;delay();delay();delay();delay();*IOCLR0=0x00006000;*IOSET0=0x0000A000;delay();delay();delay();delay();*IOCLR0=0x0000A000;*IOSET0=0x00009000;delay();delay();delay();delay();*IOCLR0=0x00009000;*IOSET0=0x00005000;delay();delay();delay();delay();*IOCLR0=0x00005000;*IOCLR1 = 0Xff0000;}

*IOCLR0=0x00000EFF;*IOSET0=0x00000100;if((*IOPIN0&0x0000003C)==0x00000004){sendchar0('D');*IOSET1 = 0x5E0000;delay1(); //Display D*IOCLR0=0x0ff0000;}

30

Page 31: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

else if((*IOPIN0&0x0000003C)==0x00000008){sendchar0('9');*IOSET1 = 0x6f0000; //Display 9delay1();*IOCLR1 = 0Xff0000;}else if((*IOPIN0&0x0000003C)==0x00000010){ sendchar0('5');*IOSET1 = 0x6d0000; //Display 5delay1();*IOCLR1 = 0Xff0000;}else if((*IOPIN0&0x0000003C)==0x00000020){sendchar0('1');*IOSET1 = 0x060000; //Display 1delay1();*IOCLR1 = 0Xff0000;}*IOCLR0=0x00000F7F;*IOSET0=0x00000080;if((*IOPIN0& 0x0000003C)==0x00000004){sendchar0('E');*IOSET1 = 0x790000; //Display Edelay1();*IOCLR1 = 0xff0000;}else if((*IOPIN0&0x0000003C)==0x00000008){

sendchar0('A');*IOSET1 = 0x770000; //Display Adelay();*IOCLR1 = 0xff0000; }

else if((*IOPIN0&0x0000003C)==0x00000010){ sendchar0('6');*IOSET1 = 0x7d0000; //Display 6

delay();*IOCLR1 = 0Xff0000;}

else if((*IOPIN0&0x0000003C)==0x00000020){

sendchar0('2');*IOSET1 = 0x5b0000; //Display 2

delay();*IOCLR1 = 0Xff0000;}

*IOCLR0=0x00800FBF;

31

Page 32: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

*IOSET0=0x00000040;if((*IOPIN0&0x0000003C)==0x00000004){

sendchar0('F');*IOSET1 = 0x710000; //Display F

delay();*IOCLR1 = 0xff0000;}

else if((*IOPIN0&0x0000003C) == 0x00000008){

sendchar0('B');*IOSET1 = 0x7c0000; //Display Bdelay();*IOCLR1 = 0xff0000;}

else if((*IOPIN0&0x0000003C)==0x00000010){

sendchar0('7');*IOSET1 = 0x070000; //Display 7delay();*IOCLR1 = 0Xff0000;}

else if((*IOPIN0&0x0000003C)==0x00000020){

sendchar0('3');*IOSET1 = 0x4f0000;delay();*IOCLR1 = 0Xff0000;

}}}}

RESULT Thus the Stepper motor speed was controlled by using ARM 7 - LPC 2148 RISC microcontroller.

APPENDIX A

PROCEDURE FOR TRITON IDE

32

Page 33: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

1) To create a new project PROJECT-> NEW-> C Project ->This will open new project

2) Enter the new project name and configure the remaining settings

3) Select debug, Release , Show all project types and show all configurations then give Next

33

Page 34: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

4) This will open a new Project workspace. There you open the C file and type program. In case of RTOS, select the OS as MCOS-II

5) Right Click on the project folder to Select the Build mode in Active build

34

Page 35: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

configurations, Build and Rebuild operations

35

Page 36: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

1) After performing the above operation hex file will be created under the release folder. To download the hex file , open Release folder and right click on the hex file then select download .Make sure that, controller kit must be in ISP mode for programming

36

Page 37: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Circuit Diagram:

Switches and LEDs- circuit diagram

Fig. switch

Fig. LED

37

Page 38: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

APPENDIX B:HOW TO CREATE PROJECT USING ECLIPSE IDE

PROCEDURE

Goto File -> New -> C Project. Enter the project name. Select project type -> empty project and select tool chain -> ARM Windows GCC (Sourcery G++ lite). Click Next.

Select Debug and Release. Then, press Finish. Go to File -> Import -> General -> File System. Press Next. Browse and select the project from “Softwares_Stellaris”. Press Finish.

OrCreate the source files namely main.c, startup_gcc.c, main.ld and readme.text by clicking FILE-> NEW-> SOURCE FILE.

Go to Project Properties. Under C\C++ build -> settings -> Tool Settings -> target processor -> choose cortex M3.

ARM Sourcery Windows GCC C Compiler -> preprocessor -> add source -> type ‘gcc’ and give ok.

ARM Sourcery Windows GCC C Compiler -> Directories. add source -> file system -> select C:\stellarisware., add source -> file system -> select C:\stellarisware\driverlib. add source -> file system -> select C:\stellarisware\utils. add source -> file system -> select C:\stellarisware\inc.

Setting up code optimization -> select ‘function sections’. Including the linker. ARM Sourcery Windows GCC C Linker -> General.

Browse ‘main.ld’ file and select ‘do not use standard start files’, ’do not use default libraries’ and ‘remove unused sections’.

Add the libraries. ARM Sourcery Windows GCC C Linker ->Libraries. add source -> file system -> select C:\stellarisware. add source -> file system -> select C:\stellarisware\driverlib\gcc_

cm3. In the Project Properties window, go to C/C++ General -> Paths and Symbols ->

Source Location -> Link Folder. Include the ‘driverlib’ and ‘utils’ folder that contain the C source files. In the Project Properties window, go to C/C++ Build -> Settings -> Build Steps -

> Post Build Steps Command and type the following.arm-none-eabi-objcopy -S -O binary "${ProjName}.elf“ "${ProjName}.bin“

Click Apply and then click ok. Develop the application in main.c file and then perform build operation. Go to Run -> External Tools -> External Tools Configuration. In the window, set the location to LMFlash.exe located under “C:/Program

Files/Texas Instruments/” and click run. After clicking Run, one window will pop up. In the configuration tab, choose the

COM port depending on the port the device is attached to. Go to the Program tab, and select the .bin file by browsing to your project in the

38

Page 39: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Eclipse workspace folder. Make sure the address offset is 0800. Connect the kit with the system and the press program. The application will get

downloaded into the kit. (Refer Appendix C)

Step 1: Goto File -> New -> C Project. Enter the project name. Make sure the

selections are as shown in Figure. Click Next.!

Step 2: Select Debug and Release as shown in Figure. Then, press Finish.

39

Page 40: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Step 3: Go to File -> Import -> General -> File System.

Step 4: Press Next. Browse and select the project from “Softwares_Stellaris” . Press

Finish. Or

Create the source files namely main.c, startup_gcc.c, main.ld and readme.text by clicking FILE-> NEW-> SOURCE FILE.

40

Page 41: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Your screen should look similar to it!

Step 5: Go to Project Properties. Under C\C++ build -> settings -> Tool Settings -> target processor -> choose cortex M3.Step 6: ARM Sourcery Windows GCC C Compiler -> preprocessor -> add source -> type ‘gcc’ and give ok.

41

Page 42: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Step 7: Go to Project Properties. Under Settings -> Tool Settings -> ARM Sourcery Windows GCC C Compiler -> Directories.

Step 8: Include all directory paths as shown in the above Figure.

42

Page 43: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Step 9: Setting up code optimization.

Step 10: Including the linker. In the Project Properties window, go to Tool Setting -

> ARM Sourcery Windows GCC C Linker -> General.

Step 11: Add the libraries. In the Project Properties window go to Tool Setting ->

43

Page 44: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

ARM Sourcery Windows GCC C Linker ->Libraries.

Add the two directory paths as shown in Figure.

Step 12: In the Project Properties window, go to C/C++ General -> Paths and

44

Page 45: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Symbols -> Source Location -> Link Folder.

Step 13: Include the driverlib and utils folder, which contain the C source files.

Your screen should look similar to it!

45

Page 46: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Step 14 : In the Project Properties window, go to C/C++! Build -> Settings ->

Build Steps -> Post Build Steps Command and type the following.

arm-none-eabi-objcopy -S -O binary "${ProjName}.elf“ "${ProjName}.bin“

Step 15: Right click on the project opened in the workspace, go to Build

Configurations and build and clean the project.

46

Page 47: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Step 16: Go to Run -> External Tools -> External Tools Configuration

Step 17: In the window, set the location to LMFlash.exe located under “C:/Program

47

Page 48: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Files/Texas Instruments/” and click run.

Step 18: After clicking Run, a window similar to below should display on the

screen. In the configuration tab, choose the COM port depending on the port the

device is attached to.

Step 19: Go to the Program tab, and select the .bin file by browsing to your project

in the Eclipse workspace folder. Make sure the address offset is 0800.

48

Page 49: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Step 20: Clicking on Program starts transferring the application binary file to the

Stellaris Guru board.

APPENDIX C

LPC 2148 PIN selection and CPU Registers

Binary Value function

49

Page 50: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

 00 First alternate function

 01 Second Alternate function

 10 Third Alternate function

 11 Fourth alternate function

PINSEL0 Register Lower order two bytes

PINSEL1 Register higher order bytes

50

Page 51: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

PINSEL2 Register

UART0 Line Status Register Bit Description:U0LSR Function Description Reset

Value0 Receiver 0: U0RBR is empty 0

51

Page 52: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Data Ready (RDR)

1: U0RBR contains valid dataU0LSR0 is set when the U0RBR holds an unread character and is cleared when the UART0 RBR FIFO is empty.

1Overrun

Error(OE)

0: Overrun error status is inactive.1: Overrun error status is active.

0

2Parity Error

(PE)

0: Parity error status is inactive.1: Parity error status is active. 0

3Framing

Error(FE)

0: Framing error status is inactive.1: Framing error status is active. 0

4Break

Interrupt(BI)

0: Break interrupt status is inactive.1: Break interrupt status is active. 0

5

TransmitterHoldingRegisterEmpty

(THRE)

0: U0THR contains valid data.1: U0THR is empty.THRE is set immediately upon detection of an empty UART0 THR and is cleared on a U0THR write.

1

6Transmitter

Empty(TEMT)

0: U0THR and/or the U0TSR contains valid data.1: U0THR and the U0TSR are empty.TEMT is set when both U0THR and U0TSR are empty; TEMT is cleared when either the U0TSR or the U0THR contain valid data.

1

7Error in Rx

FIFO(RXFE)

0: U0RBR contains no UART0 Rx errors or U0FCR0=0.1: UART0 RBR contains at least one UART0 Rx error.

0

Baud Rate Calculation:

Clock frequency / (16 * baud rate) = decimal Hex DLM & DLL

UART0 Line Control Register Bit Description:U0LCR

Function Description ResetValue

1:0 Word Length 00: 5 bit character length 0

52

Page 53: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Select 01: 6 bit character length10: 7 bit character length11: 8 bit character length

2 Stop Bit Select 0: 1 stop bit1: 2 stop bits (1.5 if U0LCR[1:0]=00)

0

3Framing

Error (FE)

0: Framing error status is inactive.1: Framing error status is active. 0

5:4 Parity Select

00: Odd parity01: Even parity10: Forced “1” stick parity11: Forced “0” stick parity

0

6 Break Control

0: Disable break transmission1: Enable break transmission.Output pin UART0 TxD is forced to logic 0 when U0LCR is active high.

0

7Divisor Latch

Access Bit0: Disable access to Divisor Latches1: Enable access to Divisor Latches

0

ADCR A/D CONTROL REGISTER

ADCR Function DescriptionReset

Value

23:22Reserved, user software should not write ones to reserved bits. The value read from areserved bit is not defined.

NA

26:24START

000When the BURST bit is 0, these bits control whether and when an A/D conversion isstarted:No start (this value should be used when clearing PDN to 0).001 Start conversion now.010 Start conversion when the edge selected by bit 27 occurs onP0.16/EINT0/MAT0.2/CAP0.2 pin.011 Start conversion when the edge selected by bit 27 occurs on P0.22/CAP0.0/MAT0.0 pin.100 Start conversion when the edge selected by bit 27 occurs on MAT0.1.101 Start conversion when the edge selected by bit 27 occurs on MAT0.3.110 Start conversion when the edge selected by bit 27 occurs on MAT1.0.111 Start conversion when the edge selected by bit 27 occurs on MAT1.1.

0

27EDGE

1- This bit is significant only when the START field contains 010-111. In these cases:Start conversion on a falling edge on the selected CAP/MAT signal.0 Start conversion on a rising edge on the selected CAP/MAT signal.

0

31:28 -

Reserved,user software should not write ones to reserved bits. The value read from areserved bit is not defined.

NA

APPENDIX D

VIVA QUESTIONS

53

Page 54: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

VERIFICATIONAND VALIDATION USING Eclipse IDE

1) What are the features of cortex LM3S608? ARM® Cortex™ -M3 v7-M Processor Core

Upto 80 MHz, Upto 100MIPS (at80MHz) On-ChipMemory 256KB Flash, 96KBSRAM.

ROM Loaded with Stellaris Driver Lib Boot loader, AES Tables and CRC. External Peripheral Interface (EPI)

32 bit dedicated parallel bus for external peripherals. Supports SDRAM, SRAM/Flash, M2M.

Advanced Serial Integration 10/100 Ethernet MAC and PHY CAN 2.0 A/B Controllers. USB Full Speed, OTG/Host/Device. UARTs with IrDA and ISO 7816 support. 2 I2Cs, 2 Synchronous Serial Interfaces (SSI), Integrated Inter chip Sound

(I2S). System Integration

32 Channel DMA Controllers. Internal precision 16MHz oscillator, 2 watchdog times with separate clock domains.

ARM Cortex SysTick timer. 4x32 bit timers with RTC capability. Lower power battery backed hibernation module. Flexible pin muxing capability.

Advanced Motion Control 8 advanced PWM outputs for motion and energy applications. 2 Quadrature Encoder Inputs (QEI).

Analog 2 x8Channel 10 bit ADC (for a total of 16 channels). 3 analog comparators. On chip voltage regulator (1.2V internal operation).

2) What are the advantages of open source product over licensed product? Low cost and no license fees. Open standards that facilitate integration with other Systems. It is easily customizable.

3) What is Eclipse IDE?Eclipse is a multi-language software development environment comprising an

integrated development environment (IDE) and an extensible plug-in system. It is written mostly in Java. It can be used to develop applications in Java and, by means of various plug-ins, other programming languages including Ada, C, C++, COBOL, etc.

4) What is code sourcery?

CodeSourcery develops Sourcery G++, an Eclipse based Integrated Development Environment (IDE) that incorporates the GNU Toolchain (gcc, gdb, etc.) for cross

54

Page 55: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

development for numerous target architectures. CodeSourcery provides a "lite" version for ARM, Coldfire, MIPS, SuperH and Power architectures. The toolchains are always very up to date. CodeSourcery contributes enhancements it makes to the GNU Toolchain upstream continually, making it the single largest (by patch count) corporate contributor. 5) Difference between debug mode and release mode?

In debug mode, many of the compiler optimizations are turned off which allow the generated executable match up with the code. This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time. Debugging information is also generated help the debugger figure out where it is in the source code.

In release mode, most of the compiler's optimizations are turned on. Chunks of your code could be completely deleted, removed, or rewritten. The resulting executable will most likely not match up with your written code. However, normally release mode will run faster then debug mode due to the optimizations.

6) What is the need for header files?

A header file is a file containing C declarations and macro definitions to be shared between several source files. The use of a header files in our program by including it, with the C preprocessing directive `#include'.

Header files serve two purposes.

System header files declare the interfaces to parts of the operating system. It should be included in our program to supply the definitions and declarations that need to invoke system calls and libraries.

Header files contain declarations for interfaces between the source files of our program. Each time a group of related declarations and macro definitions all or most of which are needed in several different source files, it is a good idea to create a header file for them.

7) What is the need for driver library?The Driver Library includes drivers for all classes of Stellaris microcontrollers.This directory contains the source code for the drivers.

8) What is the need for inc file?This directory holds the part specific header files used for the direct register access

programming model. 9) What is the use of GNU MAKE?

It converts .elf file to .bin file.10) What are the different header files used in our program and mention it uses?

Header files, one per peripheral that describe all the registers and the bit fields within those registers for each peripheral. These header files are used by the drivers to directly access a peripheral, and can be used by application code to bypass the peripheral driver library API.

#include "inc/hw_memmap.h"- defines the base address of the memories and peripherals.

#include "inc/hw_types.h"- defines the common types and macros. #include "driverlib/gpio.h" - defines macros for GPIO API. #include "driverlib/sysctl.h" - defines the prototypes for the system control driver.

55

Page 56: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

#include "utils/uartstdio.h" - defines the utility driver to provide simple UART console functions.

#include "driverlib/uart.h" - defines the Macros for UART API.11) What is the use of SysCtlClockSet function?

It sets the clocking of the device. This function configures the clocking of the device. The input crystal frequency, oscillator to be used, use of the PLL, and the system clock divider are all configured with this function.

12) What is the use of SysCtlPeripheralEnable function?This function enables peripherals. At power-up, all peripherals are disabled; they

must be enabled in order to operate or respond to register reads/writes.13) What is the use of GPIOPinTypeGPIOOutput function?

It Configures pin(s) for use as GPIO outputs. The pin(s) are specified using a bit-packed byte, where each bit that is set identifies the pin to be accessed, and where bit 0 of the byte represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.

14) What is the use of GPIOPinWrite function?It writes a value to the specified pin(s).

15) What are the parameters present in UARTConfigSetExpClk function?ulBase is the base address of the UART port.ulUARTClk is the rate of the clock supplied to the UART module.ulBaud is the desired baud rate.ulConfig is the data format for the port (number of data bits, number of stop bits, and parity).

16) What will UARTCharPut and UARTCharGet functions do?UARTCharGet (It waits for a character from the specified port)-This function

gets a character from the receive FIFO for the specified port. If there are no characters available, this function waits until a character is received before returning.

UARTCharPut (It waits to send a character from the specified port)- This function sends the character ucData to the transmit FIFO for the specified port. If there is no space available in the transmit FIFO, this function waits until there is space available before returning.

17) What will SysCtlDelay function do?It provides a small delay. It utilizes the system control register for making delay.

The system control block has 24 bit register to provide time delay.

VERIFICATIONAND VALIDATION USING KEIL IDE1. What do you meant by verification and validation?

The verification process is performed after developing hardware, software and integrating both. The main aim of this process is to verify the developed or designed module, whether meets the specified objective or not. If the result goes wrong, the

56

Page 57: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

designer has to do the redesign. If the results are satisfied we can go for validation. The validation process is used to analyze the performance of the system.

2. What is ARM 7 TDMI?Advanced RISC Machine core 7, which supports Thumb instruction, Debugger support, enhanced Multiplier, In circuit emulator.

3. What do you meant by interfacing?Interfacing is the process of making communication between master and the

peripheral device. The communication may be hardware or software level.4. What is the use of IOSET and IOCLR (clear) register?

IOSET register is used send the logic 1 on the particular port pin.IOCLR register is used to make the logic 0 on the port pin.In order to change the port pin status from high to low, IOCLR to be used

5. What is the use of IODIR (direction) register?IO Direction register is used to set the direction path of a port pin that is either input or output.

6. What are various types of switches?Toggle switches, Push Button switches, SPST, SPDT

7. What are the various types of output devices?LED, 7 segment LED, LCD, Motors

8. What is the need for delay program?In order to communicate properly between the IO device and master

(microprocessor) speed of operation of the devices to be matched. Delay programs are used to match the speed.

9. Why the PIN SELECTION registers must be configured?The port pins are multiplexed in nature that is, a single port pin can perform 4

different operations. In order to select the particular feature the PIN Selection must be configured. By default all the pins are configured as general purpose IO pin.

10. What is the necessity to use infinite loop?Master executes the codes written on this loop continuously. If you want to execute the code for a time, you can use it below the main function.

11. What is the need for delay program?In order to communicate properly between the IO device and master

(microprocessor) speed of operation of the devices to be matched. Delay programs are used to match the speed.

12. What is the necessity to use infinite loop?Master executes the codes written on this loop continuously. If you want to execute the code for a time, you can use it below the main function.

13. What will be the effect if you not include the .h file?The compiler can’t convert the appropriate machine code for the target processor.The supporting data’s cannot be taken.

14. What are various integer initialization types?unsigned int -32 bitsigned int - 31 bit for a 32 bit microcontroller

15. How do you convert the data’s from working host system to target system?The Hexa decimal file is created by the IDE in the project name. the hex file is downloaded to the memories of the target processor.

57

Page 58: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

VERIFICATIONAND VALIDATION USING RTOS ( µCOS-II)1.What do you meant by multitasking?

Multi-tasking is the ability to execute more than one task at the same time.2.What do you meant by RTOS?

RTOS stands for Real time Operating system. Not only the logical correctness of the computation and the time at which the result is produced. In RTOS “a late answer is a wrong answer.”

3.What are the features of RTOS?Multi-Tasking, communication between tasks like semaphore management, mailboxes,

queues, time delays4.Differentiate between application task and startup task.

The start-up task is executed by the OS first

Application tasks are executed from the startup task itself

OS initialization done at here only Initialization of OS can’t be performedApplication tasks are created from here only

Creation of task is not possible but another task can be invoked

Timing dead line can be given Timing dead line can be given5.Name few RTOS based embedded application.

Mobile phone, network router, missile systems, satellites, ATM etc6. What are the software used to build the embedded system?

Triton IDE / keil IDE - Integrated Development EnvironmentFlash Fusion – fusing softwareXilinx ISE- Integrated Software Environment

7. What are the debuggers used to test the embedded systems?Many tools are used for debugging and testing embedded systems. A few of them are •Remote debugger: for monitoring and debugging the state of the embedded system software•In Circuit Simulator: for monitoring and controlling the state of the processor in the embedded systems•Simulators: used before the design of the embedded systems and are used to simulate the functioning of the ES on the host machine•Logic analyzer: used to check the logical level of the various components of the ES•Oscilloscopes: to checking the analog signal and also for hardware debugging

FSM IMPLEMENTATION ON FPGA

1. Name any two applications based on FSM?I2C bus, SPI Bus

2. What are the various types modeling in Verilog HDL? Data flow, Gate level, Switch level, behavior model

3. What type of modeling involved in FSM design code?Behavior model

4. Differentiate between Verilog HDL and C language?

Embedded C Language Verilog HDL

Sequential language Concurrent language

58

Page 59: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Used for algorithm based modeling the system

Used for detailed hardware implementation

5. Differentiate between Microcontroller and FPGA.

Microcontroller FPGA.

Programmable device that can be used as a processing device in system design

programmable devices that can be used to implement digital logic

ALU, memory, control unit, UART, ADC, DAC, etc. are the internal hardware

Internally logic cell based hardware which imitates the any hardware logic

Microcontrollers are custom built mini computers in an IC

FPGAs are only composed of logic blocks that can be rewired electrically

There are ready built microcontrollers being sold for specific uses

FPGAs take a considerably longer time to set-up

Expt 5 1. What are the steps involved in embedded application design?

Thoroughly analyze the specification, hardware development, software development, hardware software integration, Verification, validation.

2. How do you control the speed of the stepper motor?The various speed levels are programmed with the help of delay program. By

pressing switches in the 4x4 matrix, the corresponding programs are called.3. How can you make this application to work with wireless module?

If we add the UART module programming with the existing code, the data can betransmitted / received through either TXD/ RXD. We can easily interface wireless modules with LPC 2148 microcontroller.

PARTITIONING BETWEEN ARM AND FPGA1. What is LFSR?

A linear feedback shift register (LFSR) is a shift register whose input bit is alinear function of its previous state.2. What is seed?

The initial value of the LFSR is called seed, and because the operation of theregister is deterministic, the stream of values produced by the register is completelydetermined by its current (or previous) state.3. What are taps?

The outputs that influence the inputs are called taps.4. What is the use of parallel LFSR?

The parallel architecture of an LFSR reduces dynamic power consumption andcan generate more than one bit output per clock cycle.

5. What are the applications of LFSRs?Applications of LFSRs include generating pseudo-random numbers, pseudo-noise

sequences, fast digital counters, and whitening sequences.6. What is encryption?

59

Page 60: Embedded Systems Lab Manual

SEC - ECE EMBEDDED SYSTEMS LAB RECORD

Encryption is the conversion of data into a form, called a cipher text, that cannotbe easily understood by unauthorized people.7. What is decryption?

Decryption is the process of converting encrypted data back into its original form,so it can be understood.8. What is primitive polynomial?

A primitive polynomial may refer to one of two concepts:1. A polynomial over a unique factorization domain (such as the integers) whose greatestcommon divisor of its coefficients is one.2. The minimal polynomial of a primitive element of the extension field GF (pm).9. What are the properties of maximum length sequence?1. When the PN sequence generated by linear feed back shift register has the length of 2r-1, it is called as maximum length sequence.2. The length of the PN sequence generated by a primitive polynomial should be 2r-1. Ifthe output sequence satisfies this property, the polynomial is called as primitive. So themost secured communication is achieved.3. The number of ones is always one more than the number of zeros in each period of themaximum length sequence whereas in truly random sequence ones and zeros are equallyprobable. Maximal length sequence: Tc , Tb=NTc.

60