Вы находитесь на странице: 1из 93

List of Experiments

1. Study of ARM Evaluation System


2. Interfacing ADC and DAC
3. Interfacing PWM and LED
4. Interfacing Real-time clock and Serial Port
5. Interfacing Keypad and LCD
6. Interfacing EEPROM and Interrupt
7. Mailbox
8. Interrupt performance characteristics of ARM and FPGA
9. Flashing of LED
10. Interfacing Stepper motor and Temperature sensor
11. Interfacing Zig-bee Protocol and ARM

1
EC6711 Embedded Systems Laboratory

Experiment 1

Study of ARM Evaluation System

Aim

To learn about the evolution, core features, general characteristics and applications of
ARM processors.

Theory

The LPC2148 microcontrollers are based on a 32/16 bit ARM7TDMI-S CPU with
real-time emulation and embedded trace support, that combines the microcontroller with
embedded high speed flash memory ranging from 32 kB to 512 kB. A 128-bit wide
memory interface and unique accelerator architecture enable 32-bit code execution at the
maximum clock rate. For critical code size applications, the alternative 16-bit Thumb
mode reduces code by more than 30 % with minimal performance penalty.

Due to their tiny size and low power consumption, LPC2148 are ideal for
applications where miniaturization is a key requirement, such as access control and point-
of-sale. A blend of serial communications interfaces ranging from a USB 2.0 Full Speed
device, multiple UARTS, SPI, SSP to I2Cs and on-chip SRAM of 8 kB up to 40 kB,
make these devices very well suited for communication gateways and protocol
converters, soft modems, voice recognition and low end imaging, providing both large
buffer size and high processing power. Various 32-bit timers, single or dual 10-bit
ADC(s), 10-bit DAC, PWM channels and 45 fast GPIO lines with up to nine edge or
level sensitive external interrupt pins make these microcontrollers particularly suitable for
industrial control and medical systems.

2
EC6711 Embedded Systems Laboratory

FEATURES
 16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.

 8 to 40 kB of on-chip static RAM and 32 to 512 kB of on-chip flash program


memory.
 128 bit wide interface/accelerator enables high speed 60 MHz operation.

 In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader


software.

 Single flash sector or full chip erase in 400 ms and programming of 256 bytes in
1 ms.

 Embedded ICE RT and Embedded Trace interfaces offer real-time debugging


with the on-chip Real Monitor software and high speed tracing of instruction
execution.

 USB 2.0 Full Speed compliant Device Controller with 2 kB of endpoint RAM.
In addition, the LPC2146/8 provides 8 kB of on-chip RAM accessible to USB by
DMA.

 One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total
of 6/14 analog inputs, with conversion times as low as 2.44 s per channel.
 Single 10-bit D/A converter provide variable analog output.

 Two 32-bit timers/external event counters (with four capture and four compare
channels each), PWM unit (six outputs) and watchdog.

 Low power real-time clock with independent power and dedicated 32 kHz clock
input.

 Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus
(400 Kbit/s), SPI and SSP with buffering and variable data length capabilities.
 Vectored interrupt controller with configurable priorities and vector addresses.
 Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.

3
EC6711 Embedded Systems Laboratory

 Up to nine edge or level sensitive external interrupt pins available.

 60 MHz maximum CPU clock available from programmable on-chip PLL with
settling time of 100s

 On-chip integrated oscillator operates with an external crystal in range from 1


MHz to 30 MHz and with an external oscillator up to 50 MHz
 Power saving modes include idle and Power-down.

 Individual enable/disable of peripheral functions as well as peripheral clock


scaling for additional power optimization.

 Processor wake-up from Power-down mode via external interrupt, USB, Brown-
Out Detect (BOD) or Real-Time Clock (RTC).
 Single power supply chip with Power-On Reset (POR) and BOD circuits:
- CPU operating voltage range of 3.0 V to 3.6 V (3.3 V 10 %) with 5 V
tolerant I/O

ARCHITECTURE OVERVIEW
The LPC2148 consists of an ARM7TDMI-S CPU with emulation support, the
ARM7 Local Bus for interface to on-chip memory controllers, the AMBA Advanced
High-performance Bus AHB for interface to the interrupt controller, and the VLSI
Peripheral Bus (A compatible superset of ARM’s AMBA Advanced Peripheral Bus) for
connection to on-chip peripheral functions. The LPC2148 configures the ARM7TDMI-S
processor in little-endian byte order. AHB peripherals are allocated a 2 megabyte range
of addresses at the very top of the 4 gigabyte ARM memory space. Each AHB peripheral
is allocated a 16 kB address space within the AHB address space. LPC2148 peripheral
functions are connected to the VPB bus. The AHB to VPB Bridge interfaces the VPB bus
to the AHB bus. VPB peripherals are also allocated a 2 megabyte range of addresses,
beginning at the 3.5 gigabyte address point. Each VPB peripheral is allocated a 16 kB

4
EC6711 Embedded Systems Laboratory

address space within the VPB address space. The connection of on-chip peripherals to
device pins is controlled by a Pin Connect Block. This must be configured by software to
fit specific application requirements for the use of peripheral functions and pins.

ARM7TDMI PROCESSOR
The ARM7TDMI-S is a general purpose 32-bit microprocessor, which offers high
performance and very low power consumption. The ARM architecture is based on
Reduced Instruction Set Computer (RISC) principles, and the instruction set and related
decode mechanism are much simpler than those of micro programmed Complex
Instruction Set Computers. This simplicity results in a high instruction throughput and
impressive real-time interrupt response from a small and cost-effective processor core.
Pipeline techniques are employed so that all parts of the processing and memory
systems can operate continuously. Typically, while one instruction is being executed, its
successor is being decoded, and a third instruction is being fetched from memory. The
ARM7TDMI-S processor also employs a unique architectural strategy known as
THUMB, which makes it ideally suited to high-volume applications with memory
restrictions, or applications where code density is an issue. The key idea behind THUMB
is that of a super-reduced instruction set. Essentially, the ARM7TDMI-S processor has
two instruction sets:
 The standard 32-bit ARM instruction set.

 A 16-bit THUMB instruction set.


The THUMB set’s 16-bit instruction length allows it to approach twice the density
of standard ARM code while retaining most of the ARM’s performance advantage over a
traditional 16-bit processor using 16-bit registers. This is possible because THUMB code
operates on the same 32-bit register set as ARM code. THUMB code is able to provide
up to 65% of the code size of ARM, and 160% of the performance of an equivalent ARM
processor connected to a 16-bit memory system.

5
EC6711 Embedded Systems Laboratory

BLOCK DIAGRAM

EC6711 Embedded Systems Laboratory


6
Result
The evolution, core features, general characteristics and the applications of ARM
processors has been studied and is evaluated.

7
EC6711 Embedded Systems Laboratory

Experiment 2

Interfacing ADC and DAC

Aim

To develop a C-Language program for reading an on-chip ADC, convert into


decimal and to display it in PC and to generate a square wave depending on this ADC
reading. The ADC input is connected to any analog sensor/ on board potentiometer.

Apparatus & Software Required

1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic.

4. CRO

5. USB cable.

Theory
i) ADC

The LPC 2148 has 10-bit successive approximation analog to digital converter. Basic
clocking for the A/D converters is provided by the VPB clock. A programmable divider
is included in each converter, to scale this clock to the 4.5 MHz (max) clock needed by
the successive approximation process. A fully accurate conversion requires 11 of these
clocks. The ADC cell can measure the voltage on any of the ADC input signals.

8
EC6711 Embedded Systems Laboratory

VSK-2148 has one potentiometer for working with A/D Converter. Potentiometer outputs
are in the range of 0V to 3.3V. Short the J4 jumper for reading the Potentiometer
value by ADC.

Procedure

1. Follow the steps 1 of How to create a New project


2. Type the below code and save it with the name dac.c (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

9
EC6711 Embedded Systems Laboratory

Program

/* - - - - - HEADER FILES - - - - -
*/ #include<nxp/iolpc2148.h>
#include<stdio.h>
#include "uart.h"
#include "adc.h"
/* - - - - - User defined Variables - - - - - */

unsigned int val=0,volt;

/* - - - - - MAIN FUNCTION STARTS HERE - - - - - */

void main(void)
{
PINSEL1_bit.P0_28=1;
init(); /* Call the initialization function. Function definition is in
“uart.h” */
uart_inital(); /* Call the uart function. Function definition is in “uart.h” */
adc(); /* Call adc function. Function definition is in “adc.h” */
PINSEL1=0X01000000; //ADC0.1
while(1)
{
while(AD0DR_bit.DONE==0); // Start A/D Conversion
val=AD0DR1_bit.RESULT;

printf("adc = %d \n\r",val);

}
}

10
EC6711 Embedded Systems Laboratory

Procedure to View the Result:


Compile, Debug & Simulate the above code in IAR.

Connect the RS232 cable/USB cable provided to the PC/Laptop and the VSK-
2148 Board, and Power on the Board.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code on to the board using Flash Magic through UART0/USB.

Now change the Mode-Selection-Switch to EXEC position and reset the board.

Open Win X-Talk, and select the COM port and the baud rate as 9600.


Now vary the on board potentiometer knob and observe the values displayed in
PC.

As you tune the knob, the values displayed in the PC/Laptop should vary from 0 to
1023 and there will be a shift in the position of the load line depending on the
values in the ADC.

You can interface any other analog sensor also (range 0-3.3V) to measure and
display the following parameters: temp./pressure/force/flow/acceleration/humidity
etc.

11
EC6711 Embedded Systems Laboratory

ii) DAC
The two 10-bit buffered DAC channels can be used to convert digital signals
into analog voltage signal outputs.
The features of the DAC in LPC2148 are
1. 10 bit digital to analog converter
2. Resistor string architecture
3. Buffered output
4. Power-down mode
5. Selectable speed vs. power

Procedure

1. Follow the steps 1 of How to create a New project


2. Type the below code and save it with the name dac.c (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

12
EC6711 Embedded Systems Laboratory

Program

/* - - - - - Header Files - - - - - */

#include<nxp/iolpc2148.h>

#define DAC_BIAS 0x00010000 /*The settling time of the DAC is 2.5 µs and the maximum
current is 350 µA when BIAS=1*/

/* - - - - - delay routine - - - - - */

void delay(unsigned int x)

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

/* - - - - - main function - - - - -*/

void main()

PINSEL1=0X00080000;

while(1)

DACR = (1023 << 6) | DAC_BIAS; /* The Datas has to be passed or moved on to the VALUE bits
i.e 15 - 6 and the result will be (VALUE/(1024*Vref)) */

delay(100000); delay(100000);

delay(100000); delay(100000);

DACR = (0 << 6) | DAC_BIAS; /* The Datas has to be passed or moved on to the VALUE bits
i.e 15 - 6 and the result will be (VALUE/(1024*Vref)) */

delay(100000);
delay(100000);
delay(100000);
delay(100000);
13
}

EC6711 Embedded Systems Laboratory

Procedure to View the Result:


Compile, Debug & Simulate the above code in IAR.

Connect the RS232 cable/USB cable provided to the PC/Laptop and the VSK-
2148 Board, and Power on the Board.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code on to the board using Flash Magic through UART0/USB.

Now change the Mode-Selection-Switch to EXEC position and reset the board.

Connect the +ve terminal of the CRO probe to Aout and _ve terminal to AGND
pins on the board to see the variation in the pulse.

EC6711 Embedded Systems Laboratory

14
Experiment 3

Interfacing LED and PWM

Aim

To write a C program to generate a PWM and to vary the brightness of the LED
depending on the duty cycle.

Apparatus & Software Required

1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic.

4. CRO

5. LED board Setup

Theory

The PWM is based on the standard timer block and inherits all of its features, although
only the PWM function is pinned out on the LPC2148. The timer is designed to count
cycles of the peripheral clock (PCLK) and optionally generate interrupts or perform other
actions when specified timer values occur, based on seven match registers. The PWM
function is also based on match register events

15
EC6711 Embedded Systems Laboratory

Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

16
EC6711 Embedded Systems Laboratory

Program pwm.c

/* - - - - - Header Files - - - - - */
#include<nxp\iolpc2148.h>
/* - - - - - User Defined Variables - - - - - */
int x;
/* - - - - - delay Routine - - - - - */
void delay()
{
for( int i=0;i<=1500;i++);
}
/* - - - - - PWM function - - - - - */

17
void pwm(int x)
{

PINSEL0 = 0X000A0005; /* To select Port pin P0.8 and also p0.9 as pwm4 and
pwm6 */
PWMPR = 0X00000000; /* To set Prescaler register value to one */
PWMPCR = 0X00005000; /* To select pwm2 as single edge controlled */
PWMMCR = 0X00000002; /* To Reset pwm timer counter when matches occur
PWMMR0 = 1200 ; */ /* To set total time period of pwm output */
PWMMR4 = x; PWMMR6
= 600; PWMTCR =
0X00000002; PWMTCR = /* To reset pwm timer */
0X00000009;
}

18
/* - - - - - main function starts here - - - - - */
void main()
{

PINSEL1_bit.P0_21=1;
IO0DIR_bit.P0_21=1;

PINSEL2 = 0X00000000;
IO1DIR = 0XFF000000;

int i;
while(1)
{

19
EC6711 Embedded Systems Laboratory

for(i=0;i<=1200;i++)
{

pwm(x);
delay();
x=x+1;

if(i>=1200)
{
x=0;
}
}
}
}

EC6711 Embedded Systems Laboratory


20
Procedure To View the Result

1. Compile, Debug & Simulate the above code in IAR.


2. Connect the RS232 cable/USB cable provided to the PC/Laptop and the VSK-
2148 Board, and Power on the Board.
3. For seeing the output in real-time, select the PROG mode, reset the board and
download the code on to the board using Flash Magic through UART0/USB.
4. Now change the Mode-Selection-Switch to EXEC position and reset the board.
5. Press the Switch and we can observe the variation in the intensity of the LEDs
depending on the duty cycle of the PWM

Result
The C code to generate a PWM and to vary the intensity of the LEDs is developed and is
verified.

21
EC6711 Embedded Systems Laboratory

Experiment 4

Interfacing Real Time Clock and Serial Port

Aim

To develop a C-Language program for reading the RTC, convert into decimal and to
display it.

Apparatus & Software Required

1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic.

Theory

RTC

The Real Time Clock (RTC) is a set of counters for measuring time when system power
is on, and optionally when it is off. It uses little power in Power-down mode. On the
LPC2141/2/4/6/8, the RTC can be clocked by a separate 32.768 KHz oscillator, or by a
programmable prescale divider based on the VPB clock. Also, the RTC is powered by its
own power supply pin, VBAT, which can be connected to a battery or to the same 3.3 V
supply used by the rest of the device

Serial Communication

Serial communication takes a byte of data and transmits the 8 bits in the byte one at a
time. The advantage is that a serial port needs only one wire to transmit the 8 bits (while

22
EC6711 Embedded Systems Laboratory

a parallel port needs 8). The disadvantage is that it takes 8 times longer to transmit the
data than it would if there were 8 wires. Serial ports lower cable costs and make cables
smaller.

Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name rtc.c (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

23
EC6711 Embedded Systems Laboratory

Program rtc.c
/* - - - - - Header Files - - - - - */

#include<nxp/iolpc2148.h>
#include<stdio.h>
#include<string.h>
#include "uart.h"
/* - - - - - Real Time Clock Initialization - - - - - */

void RTC_Init()
{
ILR = 3; /* Disable 32'768 interrupt */

CCR = 0x11; /* Clock enable + 32'767Hz quartz enable; starts the RTC */

CIIR = 0x01; /* Interupt every second */

PREINT = 0x0000016D; /* the integer portion of the prescale value */

PREFRAC = 0x00001B00; /* fractional portion of the prescale value */


YEAR = 2015; /* Year */

MONTH = 05; /* Month */

DOM = 09; /* Day of month loads the date as 09.05.2015 */

DOY = 129; /* Day of year */

DOW = 04; /* Day of week */

HOUR = 10; /* Hours */

MIN = 21; /* Minutes loads the time as 10:21:00 */

SEC = 00; /* Seconds */

/* Hint: ARM processor crystal freq. = 12 MHz = 12,000,000 Hz


RTC crystal freq. = 32.768 KHz = 32,768 Hz
Calculate,
PREINT = (12,000,000 / 32,768)-1 = 365 in Decimal = 0x16D in Hex.

24
EC6711 Embedded Systems Laboratory
.

PREFRAC = 12,000,000 - (365+1)*32,768 = 6912 in Decimal = 0x1B00 in Hex.

And, for
CIIR = Counter Increment Interrupt Register,
CCR = Clock Control Register
ILR = Interrupt Location Register

Refer, "Volume 1: LPC214x User Manual" PDF Document */


}
/* - - - - - Start the Clock - - - - - */

25
void RTCStart( void )

{
CCR |= 0x01; /* CTC Reset */

ILR = 0x01; /* Interrupt location Register */

26
/* - - - - - Read Clock - - - - - */

void Read_rtc( void )


{

printf("TIME--->%d:%d:%d\t",HOUR,MIN,SEC);
printf("DATE--->%d:%d:%d\n",DOM,MONTH,YEAR);

}
/* - - - - - main function starts - - - - - */

27
void main()
{
baudrate_settings(); /* call function baudrate_settings */

RTC_Init(); /* call function RTC_Init */

RTCStart(); /* call function RTCStart */

28
EC6711 Embedded Systems Laboratory

while(1)
{
Read_rtc(); /* call function Read_rtc */

}
}

29
EC6711 Embedded Systems Laboratory

Procedure to View the Result:


Compile, Debug & Simulate the above code in IAR.

Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -
2148 Board, and Power on the Board.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code in the board using Flash Magic through UART0.

Now change the Mode-Selection-Switch to EXEC position and reset the board.

Open Win X- Talk, Select COM port and Baud rate as 9600


Now observe the output data in the PC, it should display the digital clock running
with Hr., Min., & Sec. Digits following format: “HH:MM:SS “. along with the
Day as “DD:MM:YYYY”

Digital Clock will start running from 10:21:00 as programmed by default, you can
modify the code and you can load your desired timing also.

Apart from timing it can be programmed to display AM-PM (12Hr mode) also.

Result

The C-Language program for reading RTC and displaying it in PC was written &
output is verified with running the RTC from a default/specified time.

30
EC6711 Embedded Systems Laboratory

Experiment 5

Interfacing Keyboard and LCD

Aim

To develop a C-Language program for displaying the Key pressed in the Keypad in the
LCD module. The display should come in the desired line and column.
Apparatus & Software Required

1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic.

Theory

Keypad

The Matrix keyboard is used to minimize the number of I/O lines. Normally it is possible
to connect only one key or switch with an I/O line. If the number of keys in the system
exceeds the more I/O lines are required. To reduce the number of I/O lines the keys are
connected in the matrix circuit. Keyboards use a matrix with the rows and columns made
up of wires. Each key acts like a switch. When a key is pressed a column wire makes
contact with row wire and completes a circuit.
For example 16 keys arranged in a matrix circuit uses only 8 I/O lines.
In VSK-2148 board Dip-switch and matrix keypad lines are multiplexed.

EC6711 Embedded Systems Laboratory


31
LCD

Liquid crystals are a phase of matter whose order is intermediate between that of a liquid
and that of a crystal. The molecules are typically rod-shaped organic matters about 25
Angstroms in length and their ordering is a function of temperature. The molecular
orientation can be controlled with applied electric fields.

CHARACTER BASED LCD

A standard character LCD is probably the most widely used data Visualization
component.
Character LCDs are available in various kinds of models.
1. No. Of characters x Lines: 8x1, 16x1, 16x2, 16x4, 20x4, 40x4…
2. Color: Yellow, Green, Gray, Blue…

EC6711 Embedded Systems Laboratory


32
The Character LCD communicates with the microcontroller via 8 bit data bus. The pin
description for character LCD is given below.
VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively; V0
is used for controlling LCD contrast.
RS (Register Select) - If RS = 0, the instruction command code register is selected,
allowing the user to send a command such as clear display, cursor at home, etc.
If RS = 1, the data register is selected, allowing the user to send data to be displayed on
the LCD.
RW (Read/Write) - RW allows the user to write information to the LCD or read
information from it. RW=1 when reading; RW=0 when writing.
EN (Enable) - The LCD to latch information presented to its data pins uses the enable
pin. When data is supplied to data pins, a high to low pulse must be applied to this pin in
order for the LCD to latch in the data present at the data pins.
D0 – D7 - The 8-bit data pins, are used to send information to the LCD or read the
contents of the LCD’s internal registers. To display letters and numbers, we send ASCII
codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS = 1.

EC6711 Embedded Systems Laboratory

33
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name keypad.c (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

EC6711 Embedded Systems Laboratory

Program keypad.c
/* Keypad Interface

/ K1 TO K8 : P0.16 TO P0.23

34
/ Key Value is displayed on UART0

// SCAN LINES : P0.20 TO P0.23 (OUTPUT)

// READ LINES : PO.16 TO P0.19 (INPUT) */

/* - - - - - Header Files - - - - - */

#include<nxp/iolpc2148.h>
#include<stdio.h>
# include "lcd.h"
#include "key.h"
/* - - - - - main function starts here - - - - - */

35
void main()
{
PINSEL2 = 0x00000000; /* P0.16 TO P0.23 Configured as GPIO. */

IO0DIR = 0X00F00F05; /* P0.20 TO P0.23 (O/P), P0.16 TO P0.19(I/P) */

IO1DIR=0x00FF0000; /* LCD data pins as output */

comm(command); /* function to call LCD commands */

data1("Press any Key"); /* call the function to display the data in LCD */

while(1)
{

36
scomm(0xC0); /* function to write single datas in LCD location C0 */

key(); /* call the keypad function*/

}
}

EC6711 Embedded Systems Laboratory

37
Procedure to see OUTPUT:

Compile, Debug & Simulate the above code in IAR.

Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -
2148 Boards, and Power on the Board.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code in VSK-2148 board using Flash Magic through UART0.

Now change the Mode-Selection-Switch to EXEC position and reset the board.

Now observe the LCD output, it should display the Alphabets & Numbers.

 st
1 line (upper line) should display the Alphabets Press any Key and the
 nd
2 line (lower line) should display the corresponding data as the Key is Pressed

You can change Address for upper line from 0x80 to 0x8F and

For lower line from 0xC0 to 0xCF.

Result

The C-Language program for displaying the Key pressed in the Keyboard is displayed in
the LCD module and the output was verified on the LCD on the desires line and
column/address.

EC6711 Embedded Systems Laboratory


38
Experiment 6

Interfacing EEPROM and Interrupt

Aim

To develop a C-Language program to write and read a data in EEPROM and also to
analyze its performance with the interrupt

Apparatus & Software Required

1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic.

Theory

Serial-interface EEPROM’s are used in a broad spectrum of consumer, automotive,


telecommunication, medical, industrial and PC related markets. Primarily used to store
personal preference data and configuration/setup data, Serial EEPROM’s are the most
flexible type of nonvolatile memory utilized today. Compared to other NVM solutions,
Serial EEPROM devices offer a lower pin count, smaller packages, lower voltages, as
well as lower power consumption.

EC6711 Embedded Systems Laboratory

39
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

EC6711 Embedded Systems Laboratory

Program
40
/* - - - - - Header Files - - - - - */

#include<nxp\iolpc2148.h>
#include<stdio.h>
#include "intrinsics.h"
void TIMER0(void);
void TIMER1(void);
#include "int.h"
#include "uart.h"
#include "timer.h"

/* - - - - - main function starts here - - - - - */

41
void main()
{
uart_init(); /* call the uart initialization function. Function definition is in “uart.h” */
timer_config(); /* call the timer configuration function. Function definition is in “timer.h”*/

timerenable(); /* call the timer interrupt function. Function definition is in “int.h” */

while(1)
{
printf("\n Welcome... ");
}
}

42
EC6711 Embedded Systems Laboratory

Procedure to see OUTPUT:



Compile, Debug & Simulate the above code in IAR.

Connect the RS232 cable /USB cable provided to the PC / Laptop and the VSK -
2148 Syllabus Board, and Power on the Board.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code in VSK-2148 board using Flash Magic through UART0.

Now change the Mode-Selection-Switch to EXEC position and reset the board.

Open Win X – Talk and select the COM port and the Desired Baud rate as 9600.


The main function will execute continuously. The Timer Interrupt function will
execute for every 1 second.

For every 1 second the Interrupt data will be printed in the PC

Result

The C-Language program to write and read a data in EEPROM and also to analyze its
performance with the interrupt is developed and is verified.

EC6711 Embedded Systems Laboratory


43
Experiment 7

Mailbox

Aim

To develop a ‘C’ code to create a mailbox and to understand the RTOS functions.

Apparatus & Software Required

1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic.

Theory

Real-time and embedded systems operate in constrained environments in which computer


memory and processing power are limited. They often need to provide their services
within strict time deadlines to their users and to the surrounding world. It is these
memory, speed and timing constraints that dictate the use of real-time operating systems
in embedded software.

The "kernel" of a real-time operating system ("RTOS") provides an "abstraction layer"


that hides from application software the hardware details of the processor (or set of
processors) upon which the application software will run.

EC6711 Embedded Systems Laboratory

44
In providing this "abstraction layer" the RTOS kernel supplies five main categories of
basic services to application software

The most basic category of kernel services is Task Management. This set of services
allows application software developers to design their software as a number of separate
"chunks" of software -- each handling a distinct topic, a distinct goal, and perhaps its own
real-time deadline. Each separate "chunk" of software is called a "task." The main RTOS
service in this category is the scheduling of tasks as the embedded system is in operation.

The second category of kernel services is Intertask Communication and Synchronization.


These services make it possible for tasks to pass information from one to another, without
danger of that information ever being damaged. They also make it possible for tasks to
coordinate, so that they can productively cooperate with one another. Without the help of
these RTOS services, tasks might well communicate corrupted information or otherwise
interfere with each other.

Since many embedded systems have stringent timing requirements, most RTOS kernels
also provide some basic Timer services, such as task delays and time-outs.

Many (but not all) RTOS kernels provide Dynamic Memory Allocation services. This
category of services allows tasks to "borrow" chunks of RAM memory for temporary use
in application software. Often these chunks of memory are then passed from task to task,
as a means of quickly communicating large amounts of data between tasks. Some very
small RTOS kernels that are intended for tightly memory-limited environments, do not
offer Dynamic memory allocation.

Many (but not all) RTOS kernels also provide a "Device I/O Supervisor" category of
services. These services, if available, provide a uniform framework for organizing and
accessing the many hardware device drivers that are typical of an embedded system.

EC6711 Embedded Systems Laboratory

45
Procedure
1. Follow the steps 1 of How To Create Rtos Programs
2. Type the below code and save it with the name main.c (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

EC6711 Embedded Systems Laboratory

Program main.c

/* - - - - - Header Files - - - - - */

46
#include <includes.h>
#include <intrinsics.h>
#include<stdio.h>
#include “uart.h”

/* - - - - - User Defined Variables - - - - - */

OS_EVENT *comm;
INT8U err;

/* - - - - - OS TASK STACK ALLOCATION - - - - - */

OS_STK Task1stk[100];
OS_STK Task2stk[100];

/* - - - - - TASK FUNCTION - - - - - */

void Task1(void *pdata)


{
pdata = pdata;
INT32U temp;
while(1)
{
temp=123; OSMboxPost(comm,
(void *)&temp);
OSTimeDlyHMSM(0, 0, 0, 10);
}
}

void Task2(void *pdata)


{
INT8U err;
INT8U *msg;
char val1;
while(1)
{
msg = OSMboxPend(comm,0,&err);

47
EC6711 Embedded Systems Laboratory

48
val1 = *msg;
printf("\n data = %d ",val1);
OSTimeDlyHMSM(0, 0, 0, 100);
}
}

void main (void)


{

uart_init(); /* call the Uart initialization functions */


//BSP_IntDisAll(); /* Disable all interrupts until we are ready to accept them */
BSP_Init(); /* Call Board Supporting packages */

49
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
OSTaskCreate(Task1,0,&Task1stk[99],0);
OSTaskCreate(Task2,0,&Task2stk[99],1);

comm = OSMboxCreate((void *)0);


OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */

50
EC6711 Embedded Systems Laboratory

Procedure to see OUTPUT:



Compile, Debug & Simulate the above code in IAR.

Connect the RS232 cable /USB cable provided to the PC / Laptop and the VSK -
2148 Syllabus Board, and Power on the Board.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code in VSK-2148 board using Flash Magic through UART0.

Now change the Mode-Selection-Switch to EXEC position and reset the board.

Open Win X – Talk and select the COM port and the Desired Baud rate as 9600.


The tasks will run alternatively. The first task will post a data whereas the second
task will receive the data and display it in PC.

Result

The C-Language program to create a mailbox and to understand the about the RTOS
functions is developed and is verified.

51
EC6711 Embedded Systems Laboratory

Experiment 8

Interrupt Performance Characteristics of ARM and FPGA

Aim

To study about the Interrupt performance characteristics between ARM and FPGA

Apparatus & Software Required


1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic

4. Xilinx FPGA Spartan 6

5. Xilinx ISE Design suite

6. ModelSim SE

7. JTAG 5.5

8. CRO

Theory

The ARM7 CPU has two external interrupt lines for the fast interrupt request (FIQ) and
general purpose interrupt IRQ request modes. As a generalization, in an ARM7 system
there should only be one interrupt source which generates an FIQ interrupt so that the
processor can enter this mode and start processing the interrupt as fast as possible. This
means that all the other interrupt sources must be connected to the IRQ interrupt. In a
simple system they could be connected through a large OR gate. This would mean that

EC6711 Embedded Systems Laboratory


52
when an interrupt was asserted the CPU would have to check each peripheral in order to
determine the source of the interrupt. This could take many cycles. Clearly a more
sophisticated approach is required. In order to handle the external interrupts efficiently an
on-chip module called the Vector Interrupt Controller (VIC) has been added.

Procedure for ARM

1. Follow the steps 1 of How to create a New project


2. Type the below code and save it with the name led.c (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code

EC6711 Embedded Systems Laboratory

53
Program (ARM)

#include<nxp\iolpc2148.h>

#include<stdio.h>

#include "intrinsics.h"

#define led1 IO0PIN_bit.P0_12

#define led2 IO0PIN_bit.P0_13

void TIMER0(void);

void TIMER1(void);

#pragma vector=0x18

__irq __arm void irq_handler (void)

void (*intrrupt_function)();

unsigned int vector; vector

= VICVectAddr;

intrrupt_function = (void(*)())vector;

(*intrrupt_function)();

VICVectAddr = 0;

__fiq __arm void fiq_handler(void)

while(1);

void timerenable()

54
{

VICIntSelect&=~(1<<VIC_TIMER0);

VICVectAddr0=(unsigned int)& TIMER0;

VICVectCntl0=0X20|(VIC_TIMER0);

VICIntEnable|=(1<<VIC_TIMER0);

VICIntSelect&=~(1<<VIC_TIMER1);

VICVectAddr1=(unsigned int)& TIMER1;

VICVectCntl1=0X20|(VIC_TIMER1);

VICIntEnable|=(1<<VIC_TIMER1);

__enable_interrupt();

void TIMER0(void)

led2=0;

printf("\n vimicrosystem \n");

T0IR=1;

void TIMER1(void)

led1=0;

led2=0;

printf("\n chennai \n");

T1IR=1;

int putchar(int ch)

55
if (ch=='\n')

while ((U0LSR&0x20)!=0x20); //wait until Transmit Holding Register is empty

U0THR=0x0d; //then store to Transmit Holding Register

U0THR=ch;

while ((U0LSR&0x20)!=0x20) ; //wait until Transmit Holding Register is empty

return(ch); //then store to Transmit Holding Register

void main()

PINSEL0=0X00000005;

IO0DIR=0X00003000;

VPBDIV=0X01;

U0LCR=0X83;

U0DLL=0X4E;

U0DLM=0X00;

U0LCR=0X03;

T0IR=0XFF;

T0TC=0;

T0PR=0;

//T0MR0=0X00000000C;

T0MR0=0X002255100;

T0MCR=3;

T0TCR=1;

T1IR=0XFF;

56
T1TC=0;

T1PR=0;

T1MR0=0X000002EE0;

T1MCR=3;

T1TCR=1;

while(1)

timerenable(); printf("\n

working... \n"); led1=1;

EC6711 Embedded Systems Laboratory

Procedure to View Result In ARM



Compile, Debug & Simulate the above code in IAR.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code in board using Flash Magic through UART0.

57

Now change the Mode-Selection-Switch to EXEC position and reset the board.

Run/Execute the program on the VSK – 2148 board and observe the variation in
the main process as an interrupt occurred.

The variations can be viewed in the CRO.

Interrupt performance in FPGA

Procedure for FPGA

Step 1: Create a “New project” in Xilinx ISE Project Navigator from File
Button.

Step 2: Assign a “Name” of the project and click “Next”

Step 3: Check/ modify the properties for the FPGA hardware and click
“Next”.

Step 4: Click “Finish” for the Summary window.(Now the new project
window has been displayed in the ISE Project Navigator.)

Step 5: Right click on the Xilinx FPGA hardware in the Hierarchy window pane
and select add “New Source”.

Step 6: Select “VHDL Module” and enter the file name before clicking
“Next”.
Step 7: Define the “port details” of the VHDL module and click “Next”.

Step 8: Now click “Finish” the Summary window pane.

Step 9: Now copy and paste the below program in the module.
(Follow the same procedure from “Step 5 to Step 8” for adding the
VHDL modules for the below program.)

Step 10: Right click on the Xilinx FPGA hardware in the Hierarchy window
pane and select add “New Source”.
58
Step 11: Select “Implementation Constraint File” and enter the file name
before clicking “Next”.

Step 12: Copy and Paste the Implementation Constraint File module in the
appropriate module.

Step 13: Click “Generate Programming File” in the Processes pane for the entire
project.(Now the .bit file has been generated for the project)

Step 14: Before continuing with the further process please Connect the FPGA
hardware kit with the CPU by using serial cable and Switch
“ON”.

Step 15: Now Open the JTAG 5.5 software from Start menu in your computer
and initialize the FPGA device for dumping the program into it.

Step 16: While initializing please “Assign” the “.bit file” and “Program” your
FPGA by in the JTAG 5.5 application.

(Now the coded instructions have been loaded in the FPGA hardware kit.

EC6711 Embedded Systems Laboratory

Program (FPGA)

Top module

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- DECLARATION OF THE PORT DETAILS IN TOP MODULE SECTION
ENTITY TOP_MODULE IS
PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC;
59
INPUT1 : IN STD_LOGIC; ---- SQUARE SIGNAL

INPUT2 : IN STD_LOGIC; ---- SQUARE SIGNAL


INPUT3 : IN STD_LOGIC; ---- SQUARE SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC;
RISING_INTERRUPT1: OUT STD_LOGIC;
RISING_INTERRUPT2: OUT STD_LOGIC
);
END TOP_MODULE;

ARCHITECTURE BEHAVIORAL OF TOP_MODULE IS


-- DECLARATION OF THE PORT DETAILS IN INPUT SIGNAL MODULE--
COMPONENT CLK_GEN IS PORT ( CLK : IN STD_LOGIC;
GEN_CLK1
: OUT STD_LOGIC;
GEN_CLK2
: OUT STD_LOGIC;
GEN_CLK3
: OUT STD_LOGIC
);
END COMPONENT;

-- DECLARATION OF THE PORT DETAILS IN INTERRUPT ROUTINE MODULE--


COMPONENT INTERRUPT IS PORT ( CLK : IN STD_LOGIC;
INPUT1
: IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT2
: IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT3
: IN STD_LOGIC; ---- SQUARE SIGNAL

RISING_INTERRUPT : OUT STD_LOGIC;

RISING_INTERRUPT1: OUT STD_LOGIC;

RISING_INTERRUPT2: OUT STD_LOGIC );

END COMPONENT;

EC6711 Embedded Systems Laboratory

BEGIN
--DECLARING THE SIGNAL DETAILS OF THE COMPONENTS FOR PORT MAPPING --
CLK_SECTION :CLK_GEN PORT MAP
(CLK,GEN_CLK1,GEN_CLK2,GEN_CLK3);
INTERRUPT_SECTION :INTERRUPT PORT MAP
(CLK,INPUT1,INPUT2,INPUT3,RISING_INTERRUPT,RISING_INTERRUPT1,RISING
_INTERRUPT2);

END BEHAVIORAL;

60
CLK_GEN

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- DECLARATION OF PORT DETAILS --
ENTITY CLK_GEN IS
PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC);
END CLK_GEN;
ARCHITECTURE BEHAVIORAL OF CLK_GEN IS

SIGNAL FREQ :INTEGER :=0; -- SIGNAL DECLARATION OF FREQ


BEGIN
PROCESS(CLK) -- INPUT CLOCK SIGNAL FOR GENERATING 3 INPUT SIGNALS
BEGIN
IF RISING_EDGE (CLK) THEN -- ROUTINE FOLLOWS WITH REFERENCE TO THE
CLOCK SIGNAL
FREQ <= FREQ +1; -- GENGERATING THE COUNTER FOR THE SIGNAL
FREQ
IF(FREQ >0 AND FREQ <= 10000)THEN -- FOR GETTING 1KHZ SIGNAL WE
ARE EQUALLY SPLITTING UP THE TIMING VALUES '0' FOR 10000 COUNTS AND
'1' FOR 10000 COUNTS
GEN_CLK1 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK2 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK3 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
ELSIF (FREQ >10000 AND FREQ <= 20000)THEN
GEN_CLK1 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK2 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK3 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ

EC6711 Embedded Systems Laboratory

ELSIF (FREQ > 20000)THEN


FREQ <= 0; -- COUNTER RESETS TO '0' IT IT EXCEEDS 20000 COUNTS
END IF;
END IF; -- PROCESS ENDS BY GENERATING THE 3 INPUT SIGNALS
END PROCESS;
END BEHAVIORAL;

Interrupt

-------------------------------------------------------------------------
-- LIBRARY PART --

61
-------------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-------------------------------------------------------------------------
-- PORT DECLARATION PART --
-------------------------------------------------------------------------

ENTITY INTERRUPT IS
PORT ( CLK : IN STD_LOGIC ; -- INPUT
CLOCK
INPUT1 : IN STD_LOGIC; -- SQUARE
SIGNAL
INPUT2 : IN STD_LOGIC; -- SQUARE
SIGNAL
INPUT3 : IN STD_LOGIC; -- SQUARE
SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC; -- INTERRUPT OUTPUT
1
RISING_INTERRUPT1 : OUT STD_LOGIC; -- INTERRUPT OUTPUT
2
RISING_INTERRUPT2 : OUT STD_LOGIC -- INTERRUPT OUTPUT
3
);
END INTERRUPT ;
-------------------------------------------------------------------------
--DESIGN ARCHITECTURE BEGIN'S --
-------------------------------------------------------------------------

ARCHITECTURE BEHAVIORAL OF INTERRUPT IS


SIGNAL C1,C2,C3 : INTEGER :=0 ; --
INTERNAL INTEGER SIGNAL DECLARATION FOR GLOBAL PURPOSE
SIGNAL RISING,RISING1,RISING2,X,Y,Z: STD_LOGIC:='0'; --INTERNAL BINARY
OR SINGLE BIT SIGNAL FOR GLOBAL USE
BEGIN

--------------------------------------------------------------------------
-- FIRST INTERRUT DESIGN --
--------------------------------------------------------------------------

PROCESS(CLK,INPUT1) --SENSITIVITY LIST


FOR INPUT USE
VARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N : INTEGER :=0 ; --INTERNAL
VARIABLE'S DECLARATION FOR INTERNAL PROCESS
BEGIN
IF RISING_EDGE(CLK) THEN --CLOCK SIGNAL
RISING_INTERRUPT<= RISING;
-- ASSIGNING RISING_INTERRUPT AS RISING VALUE
CASE X IS
-- SUBJECTING X VALUE WITH THE STANDARD LOGIC
FUNCTION '0' AND '1'
WHEN '0' =>
IF INPUT1='1' THEN --ROUTINE WILL CONINUE IF INPUT1
IN ON CONDITION
RISING<='1'; -- RISING VALUE SHOULD BE
ON & X VALUE SHOULD BE ON
X<='1';

62
END IF;
WHEN '1'=>
IF INPUT1='0' THEN --ROUTINE WILL CONTINUE IF INPUT
1 IN OFF CONDITION
X<='0'; -- VALUE OF X TENDS
TO '0'
END IF;
WHEN OTHERS=> -- IF ANY CONDITION OTHER
THAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.
END CASE;
IF RISING='1' THEN -- IF THE SIGNAL FOUND AS RISING EDGE
THEN THE BELOW OPERATION SHOULD BE FOLLOWED BY THE PROCESSOR

A := 30000+300000; -- ADDITION OPERATION


B:= 5669*6587; --MULTIPLICATION OPERATION
C:= 5456496/564; --DIVISION OPERATION
E:=684986-546657; --SUBTRACTION OPERATION
F:=4858*555; --MULTIPLICATION OPERATION
G:=45587486/6484; --DIVISION OPERATION
H:=5847962-45134; --SUBTRACTION OPERATION
I:=6872678+2587; -- ADDITION OPERATION
J:=245231+5454; -- ADDITION OPERATION
K:=86748/654; --DIVISION OPERATION
L:=816784*864; --MULTIPLICATION OPERATION
M:=54341/64112; --DIVISION OPERATION
N:=46845*4816; --MULTIPLICATION OPERATION
C1<=C1+1; -- HERE THE COUNTER STARTS TO SUPPORT THE DELAY

EC6711 Embedded Systems Laboratory

IF C1>= 9000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OUR


CONVENIENCE
RISING<='0'; -- ONCE THE COUNTER
EXCEEDS THE VALUE OF 9000 THEN THE STATE OF RISING SHOULD BE '0'. THEN THE
ROUTINE WILL END UP.
C1<=0; --ONCE THE COUNTER
EXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.
END IF; -- RISING = '1' CONDITION
ENDS HERE.
END IF;

END IF; -- ENTIRE PROCESS


ENDS UP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH THE GIVEN
ARITHMETIC OPERATIONS..
END PROCESS; -- THESE ABOVE CONDITIONS
PROVIDE US THE INTERRUPT PERFORMANCE OFTHE GIVEN INPUT SIGNAL THRU
RISING_INTERRUPT SIGNAL.
--------------------------------------------------------------------------

63
-- SECOND INTERRUPT DESIGN --
--------------------------------------------------------------------------
PROCESS(CLK,INPUT2) --SENSITIVITY LIST FOR INPUT USE
VARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N:INTEGER :=0; --INTERNAL VARIABLE'S
DECLARATION FOR INTERNAL PROCESS
BEGIN
IF RISING_EDGE(CLK) THEN --CLOCK SIGNAL

RISING_INTERRUPT1<= RISING1; -- ASSIGNING RISING_INTERRUPT AS


RISING VALUE

CASE Y IS WHEN '0' => -- SUBJECTING Y VALUE WITH THE


STANDARD LOGIC FUNCTION '0' AND '1'
IF INPUT2='1' THEN --ROUTINE WILL CONINUE IF
INPUT1 IN ON CONDITION

RISING1<='1'; -- RISING VALUE SHOULD BE '1' &


X VALUE SHOULD BE ON

Y<='1';
END IF;
WHEN '1'=>
IF INPUT2='0' THEN --ROUTINE WILL CONTINUE IF INPUT 1 IN
'0' CONDITION

Y<='0'; -- VALUE OF X
TENDS TO '0'
END IF;

WHEN OTHERS=> -- IF ANY CONDITION OTHER


THAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.

END CASE;

IF RISING1 ='1' THEN -- IF THE SIGNAL FOUND AS


RISING EDGE THEN THE BELOW OPERATION SHOULD BE FOLLOWED BY THE PROCESSOR

A := 30000+300000; -- ADDITION OPERATION


B:= 5669*6587; --MULTIPLICATION OPERATION
C:= 5456496/564; --DIVISION OPERATION
E:=684986-546657; --SUBTRACTION OPERATION
F:=4858*555; --MULTIPLICATION
OPERATION
G:=45587486/6484; --DIVISION OPERATION
H:=5847962-45134; --SUBTRACTION OPERATION
I:=6872678+2587; -- ADDITION OPERATION
J:=245231+5454; -- ADDITION OPERATION
K:=86748/654; --DIVISION OPERATION
L:=816784*864; --MULTIPLICATION OPERATION
M:=54341/64112; --DIVISION OPERATION
N:=46845*4816; --MULTIPLICATION OPERATION

C2<=C2+1; -- HERE THE COUNTER


STARTS TO SUPPORT THE DELAY OF THE SIGNAL

IF C2>= 6000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OUR

64
CONVENIENCE
RISING1<='0'; -- ONCE THE COUNTER EXCEEDS
THE VALUE OF 6000 THEN THE STATE OF RISING SHOULD BE '0'. THEN THE ROUTINE
WILL END UP.

C2<=0; --ONCE THE


COUNTER EXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.

END IF; --THE RISING =


'1' CONDITION ENDS HERE.

END IF; -- ENTIRE


PROCESS ENDS UP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH THE
GIVEN ARITHMETIC OPERATIONS..

END IF; -- THESE ABOVE


CONDITIONS PROVIDE US THE INTERRUPT PERFORMANCE OF THE GIVEN INPUT SIGNAL
THRU RISING_INTERRUPT SIGNAL.

END PROCESS;
END BEHAVIORAL;

EC6711 Embedded Systems Laboratory

Procedure to View Result in FPGA

By connecting the probes of CRO/MSO/DSO to the Desired Input and Output pins of the
I/O connectors we will acquire the result of the Interrupt performance of FPGA device.

Procedure to View Result in Simulation:

Step 1: Run the Simulation process of the Project by selecting “Simulation” in the
“View” pane and select the Simulator (ModelSim) in the Processes pane.

Step 2: Force clock input to the CLK variable by right clicking the variable Step

3: Now you can observe the Input and output result in the Simulator.

65
EC6711 Embedded Systems Laboratory

Experiment 9

Flashing of LEDS

Aim

To develop a ‘C’ program to make the LED blink (including delay routine). Upon change
in the delay program the speed should vary.

Apparatus & Software Required

9. LPC2148 syllabus board.

10. IAR IDE software.

11. Flash Magic.

Theory

66
LEDs are based on the semiconductor diode. When the diode is forward biased (switched
on), electrons are able to recombine with holes and energy is released in the form of light.
This effect is called electroluminescence and the color of the light is determined by the
energy gap of the semiconductor.
VSK-2148 has 8 LEDs that are connected to the Microcontroller Port
Line. Used Port Lines: LED0 – LED7: P1.24 – P1.31

EC6711 Embedded Systems Laboratory

Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name led.c (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

67
EC6711 Embedded Systems Laboratory

Program led.c

/* - - - - - Header File - - - - - */

#include<nxp/iolpc2148.h>
/* - - - - - delay Routine - - - - - */

void delay()
{

for(int i=0x00;i<=0xff;i++)
for(int j=0x00;j<=0xFf;j++);

/* - - - - - mian function starts - - - - - */

68
void main()
{

PINSEL2 = 0X00000000; /* P1.24 TO P1.31 as GPIO */

IO1DIR = 0XFF000000; /* P1.24 TO P1.31 Configured as Output port. */

while(1)
{

IO1SET=0XFF000000; /* P1.24 TO P1.31 goes to high state */

delay(); /* delay */

IO1CLR=0XFF000000; /* P1.24 TO P1.31 goes to low state */

delay(); /*delay */

}
}

69
EC6711 Embedded Systems Laboratory

Procedure to View the Result:


Compile, Debug & Simulate the above code in IAR.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code in board using Flash Magic through UART0.

Now change the Mode-Selection-Switch to EXEC position and reset the board.

Run/Execute the program on the VSK – 2148 board and observe the LED blink
duration (on/off).

Result

The C-Language program to make the LED blink was developed and output was
verified. Upon change in the delay program the speed variation was verified.

EC6711 Embedded Systems Laboratory


70
Experiment 10

Interfacing Stepper Motor and Temperature Sensor

Aim

To write C Programs for running stepper motor either in clock-wise or counter-clock-


wise and the direction of the rotation of the stepper motor depends on the variation in the
temperature sensor.

Apparatus & Software Required

1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic.

4. Stepper motor

Theory
Stepper motors, effectively have multiple "toothed" electromagnets arranged around a
central metal gear. To make the motor shaft turn, first one electromagnet is given power,
which makes the gear's teeth magnetically attracted to the electromagnet's teeth. When
the gear's teeth are thus aligned to the first electromagnet, they are slightly offset from the
next electromagnet.
So when the next electromagnet is turned on and the first will turn off, the gear rotates
slightly to align with the next one and from there the process is repeated. Each of those
slight rotations is called a "step." In that way, the motor can be turned to a precised angle.
There are two basic arrangements for the electromagnetic coils: bipolar and unipolar.

EC6711 Embedded Systems Laboratory

71
Jumper Position
Closed 1 and 2 - Internal voltage for stepper motor.
Closed 2 and 3 - External voltage for stepper motor.

Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name step.c (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

EC6711 Embedded Systems Laboratory

Program step.c
72
/* - - - - - header files - - - - - */

#include<nxp/iolpc2148.h>
#include<stdio.h>
#include "uart.h"
#include "stepper.h"
#include "adc.h"
/* - - - - - user defined variables - - - - - */

unsigned int temp;


/* - - - - - main function - - - - - */

73
void main()
{
init(); /* call function initializations. Function definition is in “uart.h”*/

adc(); /* call function adc. Function definition is in “adc.h” */

uart_inital(); /* call function uart initializations. Function definition is in


“uart.h”*/

printf( "%d \n" ,


temp ); while(1)
{
temp=AD0DR_bit.RESULT; /* When DONE is 1, this field contains a binary fraction
representing the voltage on the AIN pin, divided by
the voltage on the VREF pin (V/VREF). */

74
if(temp>=70)
{
fwd(); /* call the forward rotation function of stepper motor. Function definition is in
“stepper.h” */

else if(temp<=70)
{
rev(); /* call the reverse rotation function of stepper motor. Function definition is in
“stepper.h” */

}
}
}

EC6711 Embedded Systems Laboratory


75
Procedure to see OUTPUT:

Compile, Debug & Simulate the above code in IAR.

Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -
2148 Board, and Power on the Board.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code in VSK-2148 board using Flash Magic through UART0.

Now connect/interface the stepper motor at the motor port available in the VSK -
2148 Board with proper polarity.

Now check the jumpers J4 and J6. Jumper J4 has to be left opened whereas
jumper J6 has to be closed.

Now change the Mode-Selection-Switch to EXEC position and reset the board.

Open Win X- Talk and select the COM port and the desired baud rate as 9600.


The variations in the temperature is displayed in the PC and the motor will rotate
in clock-wise direction if the temperature in below 70 and will rotate in anti –
clock-wise, if the temperature is above 70.

Modify the program as per your desire/logic and verify the output.

Result

The C-Language program for running stepper motor either in clock-wise or


counter-clock-wise depending on the temperature is developed and the output is verified.

EC6711 Embedded Systems Laboratory


76
Experiment 11

Implementing Zigbee Protocol with ARM

Theory

The X Bee/X Bee-PRO ZNet 2.5 (formerly known as Series 2 and Series 2 PRO) RF
Modules were directed to operate within the ZigBee protocol. The modules provide
reliable delivery of data between remote devices. Zigbee is the communication protocol
like wifi and Bluetooth. Xbee is the module using Zigbee protocol

Some of its features are:

 ZigBee is targeted at radio-frequency (RF) applications

 Low data rate, long battery life, and secure networking

 Transmission range is between 10 and 75 meters (33~246 feet)

 The addressing space allows of extreme node density—up to


18,450,000,000,000,000,000 devices (64 bit IEEE address)

 using local addressing, simple networks of more than 65,000 nodes can be
configured, with reduced address overhead

 The radios use direct-sequence spread spectrum coding, which is managed


by the digital stream into the modulator.

 To ensure reliable data transmission

 Binary phase shift keying (BPSK) in the 868/915 MHz


 Offset quadrature phase shift keying (O-QPSK) at 2.4 GHz

77
EC6711 Embedded Systems Laboratory

Xbee interfacing with PC

78
EC6711 Embedded Systems Laboratory

Xbee interfacing with microcontroller

11.1 Interfacing ADC and Stepper Motor via Xbee

Aim

To write C Programs to control the rotation of a stepper motor connected with a


controller from the variation in the ADC of another controller and the controllers
has to communicate via Xbee.

Apparatus & Software Required

1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic.

4. Xbee modules 2 Nos.

Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

79
EC6711 Embedded Systems Laboratory

Program main.c

/* - - - - - header files - - - - - */

#include<nxp/iolpc2148.h>
#include<stdio.h>
#include "stdlib.h"
#include "uart.h"
#include "stepper.h"
/* - - - - - user defined variables - - - - - */

unsigned int temp;


int i,z;
char s,out[20];
/* - - - - - main - - - - - */

80
void main()
{

init(); /* call initialization function */

uart_inital(); /* call uart initialization */

while(1)
{
for(i=0;i<4;i++)
{
out[i]= serial_rx(); /* receive the datas serially and store it in an array */

}
out[i]='\0';
z=atoi(out); /* convert array to integer */

81
EC6711 Embedded Systems Laboratory

82
printf("%d ",z);

if(z >70)
{
fwd(); /* stepper motor forward rotation */

}
}
}

83
EC6711 Embedded Systems Laboratory

Procedure to see OUTPUT:



Compile, Debug & Simulate the above code in IAR.

Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK
- 2148 Boards, and Power on the Board.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code in VSK-2148 board using Flash Magic through UART0.

Connect 2 Xbee modules with 2 VSK-2148 boards.

Now change the Mode-Selection-Switch to EXEC position and reset the board.


Based on the Variation in the ADC value the stepper motor will start rotating in
the clock-wise direction.

Result

The C Programs to control the rotation of a stepper motor connected with a controller
depending on the variation in the ADC of another controller is developed and is
verified.

84
EC6711 Embedded Systems Laboratory

Experiment 11

11.2
Keypad
Aim
To transmit the data or the key pressed in the keypad via Xbee and view the
output
data in the PC.

Apparatus & Software Required

1. LPC2148 syllabus board.

2. IAR IDE software.

3. Flash Magic.

4. Xbee modules 2 Nos.

Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build
the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.

EC6711 Embedded Systems Laboratory

Program main.c
85
/* Keypad Interface

/ K1 TO K8 : P0.16 TO P0.23

/ Key Value is displayed on UART0

// SCAN LINES : P0.20 TO P0.23 (OUTPUT)

// READ LINES : PO.16 TO P0.19 (INPUT) */

/* - - - - - header files - - - - - */

#include<nxp/iolpc2148.h>
#include<stdio.h>
#include "uart.h"
/* - - - - - user defined variables - - - - - */

int i;
unsigned char dat[16]="Press Any Key";
/* - - - - - delay routine - - - - - */

void delay()
{

long int i;
for(i=0;i<50000;i++);

}
/* - - - - - main function - - - - - */

86
void main()
{
PINSEL2 = 0x00000000; /* P0.16 TO P0.23 Configured as GPIO. */

IO0DIR = 0X00F00F05; /* P0.20 TO P0.23 (O/P), P0.16 TO P0.19(I/P) */

IO1DIR=0x00ff0000;
uart_inital();

87
88
printf("\n\r 4 x 4 Matrix Key Pad Interface ");
printf("\n\r Press any Key Pad Interface ");
while(1)
{
IO0PIN=0x00E00000; /* Scan First Line */

if(( IO0PIN & 0x000F0000 )!= 0x000F0000) /* Check if any key is pressed in 4th row */
{
switch(IO0PIN & 0x000F0000) /* Check which one of the key is pressed */

{
case 0x00070000 : printf("F"); break;
case 0x000B0000 : printf("B"); break;
case 0x000D0000 : printf("7"); break;
case 0x000E0000 : printf("3"); break;
}
}
IO0PIN=0x00D00000; /* Scan second line */

if(( IO0PIN & 0x000F0000 )!= 0x000F0000) /* Check if any key is pressed in 3rd row */

{
switch(IO0PIN & 0x000F0000) /*check which one of the key is pressed.*/

{
case 0x00070000 : printf("E"); break;
case 0x000B0000 : printf("A"); break;

case 0x000D0000 : printf("6"); break;


case 0x000E0000 : printf("2"); break;
}

89
EC6711 Embedded Systems Laboratory

90
IO0PIN=0x00B00000; /* Move 3rd scan data to port line */

if(( IO0PIN & 0x000F0000 )!= 0x0F000000) /* Scan any key is pressed in 2nd row */

{
switch(IO0PIN & 0x000F0000) /* Check which one of the key is pressed in 2nd row */

case 0x00070000 : printf("D"); break;


case 0x000B0000 : printf("9"); break;
case 0x000D0000 : printf("5"); break;
case 0x000E0000 : printf("1"); break;
}
}

91
IO0PIN=0x00700000; /* Move 4th scan data to port line */

if(( IO0PIN & 0x000F0000 )!= 0x000F0000) /* Check any key is pressed in 1st row */

{
switch(IO0PIN & 0x000F0000) /*Check which one of the key is pressed in 1st row */

case 0x00070000 : printf("C"); break;


case 0x000B0000 : printf("8"); break;
case 0x000D0000 : printf("4"); break;
case 0x000E0000 : printf("0"); break;
}
}
}
}

92
EC6711 Embedded Systems Laboratory

Procedure to see OUTPUT:



Compile, Debug & Simulate the above code in IAR.

Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK -
2148 Boards, and Power on the Board.

For seeing the output in real-time, select the PROG mode, reset the board and
download the code in VSK-2148 board using Flash Magic through UART0.

Connect 1 Xbee module with the board and other with the PC.

Now change the Mode-Selection-Switch to EXEC position and reset the board.


The keys that are pressed in the board will be displayed in the PC.

Result

The C-Language program for displaying the Key pressed in the Keyboard is displayed in
PC via Xbee.

93

Вам также может понравиться