41
MSRSAS - Postgraduate Engineering and Management Programme - PEMP i ASSIGNMENT Module Code ESD 526 Module Name Embedded processors and microcontrollers Course M.Sc in Real time embedded systems Department Computer engineering Name of the Student Bhargav Rajivbhai Shah Reg. No CHB0911001 Batch Full-Time 2011. Module Leader Sanket Dessai POSTGRADUATE ENGINEERING AND MANAGEMENT PROGRAMME (PEMP) M.S.Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programmes(PEMP) #470-P Peenya Industrial Area, 4 th Phase, Peenya, Bengaluru-560 058 Tel; 080 4906 5555, website: www.msrsas.org

Assignment 1

Embed Size (px)

Citation preview

Page 1: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

i

ASSIGNMENT

Module Code ESD 526

Module Name Embedded processors and microcontrollers

Course M.Sc in Real time embedded systems

Department Computer engineering

Name of the Student Bhargav Rajivbhai Shah

Reg. No CHB0911001

Batch Full-Time 2011.

Module Leader Sanket Dessai

PO

STG

RA

DU

ATE

EN

GIN

EER

ING

AN

D M

AN

AG

EM

EN

T P

RO

GR

AM

ME –

(P

EM

P)

M.S.Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programmes(PEMP)

#470-P Peenya Industrial Area, 4th Phase, Peenya, Bengaluru-560 058

Tel; 080 4906 5555, website: www.msrsas.org

Page 2: Assignment 1

ii

Declaration Sheet Student Name Bhargav Rajivbhai Shah

Reg. No CHB0911001

Course Real time embedded systems Batch Full-Time2011

Batch Full-Time2011

Module Code ESD 526

Module Title Embedded processor and microcontroller

Module Date 10.10.2011 to 5.11.2011

Module Leader Sanket Dessai

Extension requests: Extensions can only be granted by the Head of the Department in consultation with the module leader.

Extensions granted by any other person will not be accepted and hence the assignment will incur a penalty.

Extensions MUST be requested by using the „Extension Request Form‟, which is available with the ARO.

A copy of the extension approval must be attached to the assignment submitted.

Penalty for late submission Unless you have submitted proof of mitigating circumstances or have been granted an extension, the

penalties for a late submission of an assignment shall be as follows:

Up to one week late: Penalty of 5 marks

One-Two weeks late: Penalty of 10 marks

More than Two weeks late: Fail - 0% recorded (F)

All late assignments: must be submitted to Academic Records Office (ARO). It is your responsibility to

ensure that the receipt of a late assignment is recorded in the ARO. If an extension was agreed, the

authorization should be submitted to ARO during the submission of assignment.

To ensure assignment reports are written concisely, the length should be restricted to a limit

indicated in the assignment problem statement. Assignment reports greater than this length may

incur a penalty of one grade (5 marks). Each delegate is required to retain a copy of the

assignment report.

Declaration The assignment submitted herewith is a result of my own investigations and that I have conformed to the

guidelines against plagiarism as laid out in the PEMP Student Handbook. All sections of the text and

results, which have been obtained from other sources, are fully referenced. I understand that cheating and

plagiarism constitute a breach of University regulations and will be dealt with accordingly.

Signature of the student Date

Submission date stamp (by ARO)

Signature of the Module Leader and date Signature of Head of the Department and date

Page 3: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

iii

Abstract ____________________________________________________________________________

Now a day‟s requirements of processing speed and power consumption are the major

issue in the world of processor. By increasing these need lots of new processor technology is

also developing. Cortex is a latest version of ARM technology. ARM is the very popular

among high processing requirements. But cortex is a good platform to build large scale

embedded systems. In part A, Architecture, instruction operation and MMU of ARM 11 and

cortex A9 are compared briefly.

The main objective of part B is to design electronic circuit, algorithm and develop codes

to for BEVERAGE VENDING MACHINE with the help of the ARM. The BVM is a consumer

product that deliver beverage by adding right preposition of ingredient are pre stored in the

machine. An optimum algorithm using RFID, coin detection and Database real time database

management are used to develop BEVERAGE VENDING MACHINE.

The main idea behind a coffee and tea vending machine is to offer piping hot coffee or

tea, or any other liquid drink for that matter, at the touch of a button without the need to

manually prepare the drink. The vending machine itself usually contains one or more insulated

containers to hold the drink of choice. Furthermore, some container has its own independent

electric heating element which can either be used to maintain the temperature of the drink all

day.

In this design normal users can pay and use the machine for the beverage they require

and regular users will be provided RFID card who make payments with concession at the

beginning or ending of the any time period [1 month \ 3 months].Only authenticated person has

some special option to register the users and check the consumption at his wish by log in as

admin mode.

Page 4: Assignment 1

iv

Contents ____________________________________________________________________________

Contents

Declaration Sheet ......................................................................................................................... ii Abstract ....................................................................................................................................... iii Contents ........................................................................................................................................iv

List of Figures .............................................................................................................................. v List of Symbols ............................................................................................................................vi PART-A ......................................................................................................................................... 7 CHAPTER 1 .................................................................................................................................. 7

1.1 Introduction ......................................................................................................................... 7 1.2 Architecture ......................................................................................................................... 7 1.3 Instructions operation and memory utilization .................................................................... 8

1.4 MMU ................................................................................................................................... 8 1.5 Conclusion ........................................................................................................................... 9

PART-B ...................................................................................................................................... 10 CHAPTER 2 .............................................................................................................................. 10

2.1 Introduction ....................................................................................................................... 10 2.2 Requirements for BVM ..................................................................................................... 10

2.3 Block diagram of ARM interfaces with various components ........................................... 11 2.2.1 Valve 1 ....................................................................................................................... 11 2.2.2 Valve 2 to Valve 4 ...................................................................................................... 12

2.2.3 Temperature sensor .................................................................................................... 12

2.2.4 Water heater ............................................................................................................... 12

2.2.5 S\W 1 to S\W4 ............................................................................................................ 12 2.2.6 Coin acceptor .............................................................................................................. 13

2.2.8 RFID decoder ............................................................................................................. 13 2.3 General Flow chart for BVM firmware ............................................................................. 14 2.4 Calculation for making beverages ..................................................................................... 16 2.5 Further implementation ..................................................................................................... 17

2.6 Comparison with existing BVM ........................................................................................ 17 PART-C ...................................................................................................................................... 18 CHAPTER 3 .............................................................................................................................. 18

3.1 Implementation on LPC 2129 ........................................................................................... 18 3.1 Testing algorithm .............................................................................................................. 19

3.3 Testing results .................................................................................................................... 19 CHAPTER 4 .............................................................................................................................. 24

4.1 Benefits of this assignment ................................................................................................ 24 4.2 Module learning outcomes ................................................................................................ 24

References .................................................................................................................................. 25 Bibliography ............................................................................................................................... 26 Appendix .................................................................................................................................... 27

Page 5: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

v

List of Figures ____________________________________________________________________________

Figure 2.1: Block diagram of ARM with various interfaces ..................................... 11 Figure 2.2: Solenoid valve ......................................................................................... 11 Figure 2.3: Screw Conveyer Mechanism .................................................................. 12

Figure 2.4: Circuit for multiplexing U0 Rx pin ......................................................... 13 Figure 2.5:General flow chart of BVM firmware ..................................................... 14

Figure 2.6: functional flow graph for normal user .................................................... 15 Figure 2.7: Functional flow graph for admin mode .................................................. 15 Figure 2.8: functional flow graph for registered user ................................................ 16

Figure 3.1: Heater state ............................................................................................. 19

Figure 3.2: welcome screen ....................................................................................... 20 Figure 3.3: Ask for admin ID .................................................................................... 20

Figure 3.4: Log output ............................................................................................... 21 Figure 3.5: Asking for user ID .................................................................................. 21

Figure 3.6: Milk powder ............................................................................................ 22 Figure 3.7: Tea powder ............................................................................................. 22 Figure 3.8: Relay operation ....................................................................................... 23

Figure 3.9: Normal login ........................................................................................... 23

Page 6: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

vi

List of Symbols ____________________________________________________________________________

Symbol Description

A.C

FPU

GHZ

IRQ

MIPS

MHZ

Alternating current

Floating point unit

Giga hertz

Interrupt request

Million instruction per second

Mega hertz

mlPM

TLB

TTW

Mile liter per Minuit

Translation look aside buffer

Translation table walk

Page 7: Assignment 1

PART-A

CHAPTER 1

1.1 Introduction

Now a days in embedded world there are growing requirements of higher processing power

with lower power consumption.ARM is the one of the famous processor core to meet this kind of

requirements.ARM is the platform that comes with single core and multi core processing unit.ARM

is a 32-bit microprocessor platform. ARM has different version based on designs.ARM 11 is the

first implementation of ARMv6 architecture with a typical clock of 412MHZ. On other hand

cortexA9 is implementation of ARMv7 architecture. That typically works on 1GHZ.

1.2 Architecture

ARM11

ARM 11 is Reduced Instruction Set Computer (RISC) type CPU core. The ARM11 micro

architecture targets a performance range of 400 to 1,200 Dhrystone MIPS. It‟s a load and store

architecture. This is bi-Endean it can operate in little or big Endean format. Its Harvard architecture

with 32 bit interface with instruction catch and 64 bit interface with data catch.Arm11 micro

architecture contains barrel shifter. ARM 11 has 16 general purpose register named R0-R15.R13 is

known as stack pointer, R14 is known as link register.R15 is known as program counter.

There are 17 general purpose mode specific register.7 status register for each operating

mode. Operating modes are like user, FIQ, IRQ, Abort, System, Undefined, secure monitor,

supervisory. For low processing of 16 bits thumb instruction set is provided. In thumb mode R0-R7

registers are the general purpose registers. Thumb 2 instructions are provided for low power

processing. This architecture is having 8 stage pipelining with Dynamic and static branch

predication unit. Due to 8 stages of pipelining parallel load and store can be possible.

In the status register bit 0 to bit 4 determines the processor modes. Bit 5 represents whether

processor is in arm mode or thumb mode. And bits 28 to bit 31 are the CPU flags.

CORTEX-A9

A multi core ARM cortexA9 processor is application class processor. Cortex a9 MPCORE

is a multi-core processor that delivers the second generation of the ARM MPCORE technology for

increased performance scalability and increased control over power consumption. The Cortex-A9

MPCORE multi-core processor provides a design configurable processor supporting between 1 and

Page 8: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

8

4 CPU in an integrated cache coherent manner. Cortex A9 is having performance 2.50

DMIPS/MHz per core. Each processor may be independently configured for their cache sizes and

whether the FPU, MPE or PTM interface will be supported.

It‟s having 9 stage pipelining. This architecture is having 32 kb catch for instruction cache

and data cache with additional 64-bit and 128-bit register set supporting a rich set of SIMD

operations over 8,16 and 32-bit integer and 32bit Floating point data every cycle. Cortex a9

architecture is having in built NEON media processing. The Cortex-A9 MPE engine offers both the

performance and functionality of the Cortex-A9 Floating-Point Unit plus an implementation of

the NEON Advanced SIMD instruction set for further acceleration of media and signal processing

functions.

1.3 Instructions operation and memory utilization ARM11

Basically, ARM 11 instruction set can be divided in 6 classes of instructions: Branch

instructions, Data processing instructions, Status register transfer instructions, Load and store

instructions, Coprocessors instructions, and Exception generating instructions. ARM11 architecture

uses 32 bit for every instruction. To deliver enhanced performance pipeline is used in this

architecture is. It implements 8 stages of pipeline. So ARM 11 avoids delays in pipeline by using

forwarding and branch prediction and pipeline issues one instruction at the time. Improved

memory access gives better overall performance significantly in ARM 11. Instructions and data

remain in a cache longer which in turn reduces cache misses. One of the major improvements in

ARM 11 cores is non blocking operation of memory.

Cortex-A9

Cortex A9 is having superscalar decoder capable of decoding two full instructions per cycle.

It has pipeline of 9 stages. The shallower stage is very important for low power consumption data

transfer. In this heavy pipeline stage there is out of order execution .That saves the wastage of CLK

cycle due to some pipeline stages. It provides advanced processing of instruction fetch and branch

prediction. This architecture is having advance L2 catch controller. Supports up to 224 independent

interrupts, under software control, each interrupt can be distributed across CPU.

1.4 MMU ARM 11

MMU is the hardware component to handle memory request generated by CPU. In ARM11

architecture translation process is based on the TTW and TLB.TLB contain the mapping of physical

Page 9: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

9

address to virtual address. There are two types of TLB in ARM11 architecture. This TLBS are

stored in main memory virtual Address generated by CPU will be searched in TLB. If TLB is not

having any physical address for that virtual address then TTW will be done by MMU. It can access

address location in the three different sizes of pages. ARM 11 is having Standard ARMv6 MMU

mapping sizes, domains, and access protection scheme.

Cortex-A9:

In cortexA9 MMU works with L1 and L2 catch memory. Page table entry supports four

different page sizes. It‟s having global and application-specific identifiers to remove the

requirement for context switch TLB flushes. There are three kind of TLB in Cortex

architecture.MMU in this processor contains three types of TLBS. One for instruction one for data

and one is unified TLB.

1.5 Conclusion

The topic is based on the discussion of ARM 11 and cortex A9. From the above fact we can

conclude that ARM 11 and CortexA9 are having their own application area in the embedded world.

But for butter power consumption and faster speed execution CortexA9 will be preferable.

Page 10: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

10

PART-B

CHAPTER 2 ________________________________________________________________________________

2.1 Introduction BVM is a consumer product that can be used to serve the beverages to customers in place of

making manually. This machine is basically designed for public places. Where there are some

regular user and some infrequent user. For satisfying this both needs this BVM is having coin box

for infrequent user and RFID interface for regular user. For regular user in place of coin they will

be provided a RFID card, no need to arrange coin for beverages daily. After swiping card BVM will

check arability of user in database. Or after inserting the appropriate coin in coin box machine will

make exact ratio of appropriate ingredients is controlled by ARM processor.

2.2 Requirements for BVM

Lpc2129 evaluation board

Induction heater

Four push button switches

Lm34a temperature sensor

Solenoid valve with capacity 400 mlPM.

Three servo motors with screw conveyers.

One coin acceptor

RFID transmitter and receiver

Page 11: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

11

2.3 Block diagram of ARM interfaces with various components

Figure 2.1: Block diagram of ARM with various interfaces

The Figure 2.1 shows us the general diagram of the LPC 2129 with all its interfaces and

different components that have been used for various purposes so that they can assist in the proper

working of the system. Each component used in the block diagram is mentioned briefly below.

2.2.1 Valve 1

The valve 1 is used as output valve connected with the IO port 0.20 to ARM controller. This

valve is simple valve solenoid valves that can be operate with relay. Normally open valve is capable

of transferring 200 ml liquid per Minuit. The main function of the valve is to pore 50 ml of hot

water in the user‟s cup. This valve is working on 230v A.C. Operating temperature of this valve is

50 -120 degree c.

Figure 2.2: Solenoid valve[6]

Page 12: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

12

2.2.2 Valve 2 to Valve 4

This all valves are the output ports that are connected with ULN 2003 which is connected

IO port 8 to 19.This valve is having servo motor connected with the screw conveyer mechanism.

That is responsible for pouring all powder contain like coffee\tea\milk powder to the user‟s cup.

Quantity of the powder is depending upon the number of rotation of servo motor and size of groves

on converging screw. Operating voltage for servo motor is 12v dc. The middle shaft is connected

with servo motor. When servo motor will rotate any powder contain can conveyed in groves.

Figure 2.3: Screw Conveyer Mechanism [7]

2.2.3 Temperature sensor

Lm35a is connected as input device to the ARM controller on the IO port 0.27.port 0.27 is

the analog input channel 0. Lm35 will provide analog input according to the temperature of

environment. Internal ADC is configured to convert this analog voltage to the 8 bit digital data.

This temperature sensor is used to maintain the temperature of water storage. One heater is used to

make water hot .Heater is controlled by relay which is connected with IO port 0.6.If temperature is

going beyond limit it will off the heater.

2.2.4 Water heater

Induction water heater is used to make water hot. That is connected as output on IO port 0.6

with relay. Heater is in the close loop control system with temperature sensor. If the container

temperature is increasing beyond limit state of p0.6 will be changed to off. This heater is working

on 230V A.C.

2.2.5 S\W 1 to S\W4

This all are the push buttons switches. That is connected as the input on the ARM on IO port

0.2 to 0.5.that is used to collect the data from the user.

Page 13: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

13

2.2.6 Coin acceptor

Wave future coin acceptor ac5[8] is interfaced with ARM as serial communicator. This coin

accepter will send same string while inserting of same coin .It will send that string data through

USB. By using serial to USB converter data is converting in RS-232 format. This is connected with

U0.

2.2.8 RFID decoder

RFID decoder is interfaced with ARM as serial communicator. Basically it will provide

input to the ARM. Rx pin of processer is multiplexed using relay and ULN 2003.So before

receiving data from RFID detector that relay position should be set to appropriate device .IO port

0.21 is the controlling terminal for this relay. Common terminal of relay is connecter with the ULS

2003. ULN 2003 will provide high operating current to relay. The mechanism is shown in Figure

2.4 below.

Figure 2.4: Circuit for multiplexing U0 Rx pin

Page 14: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

14

2.3 General Flow chart for BVM firmware

Figure 2.5:General flow chart of BVM firmware

Above Figure 2.5 is functional flow graph of BVM. By the starting of the program will set

UART with 9600 baud rate for serial communication, 30 MHZ of PCLK and configure A0 channel

as analog input channel for temperature sensor. After that state program will check for the

temperature of the hot water cane .If the temperature is above 60 degree C then it will switch of the

heater or else heater will we switched on.

Normal user mode is design for those who want to insert five rupee coin for beverage. In

this mode program will ask for coin. If user enters rite coin then program will allow user to enter

the choice for beverage. On occurrence of wrong coin program will ask again for coin.

Page 15: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

15

Figure 2.6: functional flow graph for normal user

Admin mode which is showed in Figure 2.7 is available in this program. Admin RFID card

is required to access admin functions. If the admin ID number match with the predefine admin

number then this functions can be accessible. There are two function dedicated to admin mode.

First is adding user. In which admin can register user. Second is log mode. In which admin can

view log of consumption of beverages by every registered user.

In add user function it will ask for swapping the users RFID card. After swapping the user‟s

RFID card it string attached with that RFID tag will be saved. In log mode admin is able to see the

log of the consumption of beverages by reg. user.

Figure 2.7: Functional flow graph for admin mode

Page 16: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

16

Registered user mode is design for registered user. In this mode program will ask to swipe

the RFID card provided by the admin. After swiping the card program will check user‟s ID in

database and then allow user to take tea or coffee. Only admin is having rights to make user and

delete user. All the users‟ transactions can be calculated and his payment can be on monthly basis

or three months depending on the requirement.

Figure 2.8: functional flow graph for registered user

Admin change mode is one of important mode of this design. In this mode admin can give

his authorities to anyone. After changing admin new admin will have all powers of admin and

previous admin will be deleted.

2.4 Calculation for making beverages

In BVM valve opening and closing timing are important for making good beverages. Two

different types of mechanism are used. Solenoid valve for water and screw conveyer mechanism for

powder ingrains. Opening and closing timings of these two mechanisms are mention below.

Calculation for water

Page 17: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

17

Water bottle is adjusted as if solenoid valve is open so water can flow with gravitational force. In

this mechanism solenoid valve is having capacity of 400 MLPM. That menace in fully open

conditions it can curry 400 ml of liquid per Minuit.

Time for water = (50 ml*60sec)/400 ml

So, for a cup of 50 ml BVM will open that valve for 7.5 sec.

Calculation for powder

For pouring coffee\tea\milk powder, screw conveyer is used. So the amount of powder is

depending upon the area of one grove on screw. After every one rotation of servo motor one

grove power can be delivered.

Servo motor will rotate conveyer five time 4 g of coffee powder will be poured in cup. By

changing the number of rotation of servo motor quantity will be changed.

Quantity in one Rotation = (Diameter of shaft*depth of grooves*periphery of shaft)

2.5 Further implementation

In further implementation admin can set the limit of beverages for each user. If user is going

beyond his limit BVM will ask to insert coin. It‟s like recharge and drink.

The user database will be on server and all BVMs are connected with server through

medium of internet. Whenever user try to enter RFID card BVM search user‟s database in

common sever.

Money return mechanism can interfaced be with BVM.

2.6 Comparison with existing BVM

Existing BVMs does not support Reg. user. Its only contains normal users. So, regular users

have to arrange coin every day for beverages. Daily arranging coin is a major issue for

regular user. This BVM is designed to solve the issue of daily arranging coin for beverages.

Page 18: Assignment 1

PART-C

CHAPTER 3 ________________________________________________________________________________

3.1 Implementation on LPC 2129

Every firmware is divided in several no of functions to decreases the complexity of

algorithm. In this firmware of BVM is divided in to the 23 functions. in which the main

functions are second(), admin_mode(), temp_chk() ,read_rfid(), tea() ,coffee(), test().

Before main a structure named data is used to store the information regarding registered

user. So, by every login of registered user firmware can search and make log of users‟

beverages consumption.

In the second function program will ask in which mode user wants to login. After getting

input by user program will deliver controls to appropriate function. If the user made choice

to login in the admin mode the second will call admin_mode(). That will check users RFID

whether that ID have admin permission or not. If ID has admin rites then user will allowed

to admin mode. After entering the admin mode there are two functions.

o Add user

o View log

Add user is used to add the member in the structure. String of the hex numbers which is

received is assigned as mem[x].ID, and initially record of no of beverages consumed by user

mem[x].no_bev will be zero.

View log is used to see the log of whole members. In this function admin can see the

consumption of beverages by registered user.

Temp_chk () is the function for reading ADC converted data. Temperature sensor is

connected with the analog pin 0.27.At every iteration of while (1), program will check the

temperature of water can. If the temperature is beyond 60 it will off the heater which is

connected on port 0.6.

rfid_read() is dedicated for reading the serial port0 and store received string in the global

array named read[14].two serial transmission devices are connected on the with the Rx

port of UART 0.UART is multiplexed using the relay. Common terminal of the relay is

Page 19: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

19

connected with the p0.22. So before calling this function programmer have to make sure the

relay is in proper direction or not.

Tea () is responsible for making tea. After calling this function stepper motor which is

connected with the port 8 to port 11 will rotate 25 times for the insertion of 25 g milk

powder. After the another stepper motor which is connected with the port 12 to port 15 will

rotate 10 times for insertion of 10 g of tea powder. After this relay which is connected on

the port 0.20 will be on that turn on the solenoid valve for a while.

In the coffee () in place of motor which is connected with the port 16 to port 19 will rotate

for 15 times that is responsible for insertion of 15 g of coffee powder

3.1 Testing algorithm

Test () is the algorithm that is used for testing only. By calling, function will create three

members in the structure with data of their ID and consumption of beverages. So by calling the log

function all data of these user can be retrieve.

3.3 Testing results

Figure 3.1: Heater state

Initially

temperature is

less then 60, so

heater is on.

Page 20: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

20

Figure 3.2: welcome screen

Figure 3.3: Ask for admin ID

Welcome screen and

mode selection of BVM.

In admin mode

program is asking to

swap admin ID .After

swapping appropriate

ID shows that you are

authorised for admin

or not.

Admin

mode is

selected

from switch

1.

Page 21: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

21

Figure 3.4: Log output

Figure 3.5: Asking for user ID

Log is generated by

log mode on the

basis of testing

valves.

Switch 4 is

pressed for log

mode.

In registered user

mode asking to swap

RFID card of user.

Switch 2 is pressed

to enter in

registered user.

Page 22: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

22

Figure 3.6: Milk powder

Figure 3.7: Tea powder

After swapping

reg. user’s RFID

it will ask for

tea/coffee.

After selection tea first motor for

milk powder is rotating.

Another

motor is

started

for tea

powder.

Switch 1 is

pressed for

tea

Page 23: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

23

Figure 3.8: Relay operation

Figure 3.9: Normal login

After milk and tea

one relay is on that

operates solenoid

valve for hot water.

Switch 3 is

pressed

for normal

user

Asking to

insert coin for

normal user

Page 24: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

24

CHAPTER 4

4.1 Benefits of this assignment

After solving part A of this assignment I became familiar with the two new 32 bit processor

named arm11 & cortex A9.

After solving part B of this assignment I come to know about “how to design whole

systems?” and practical issues while designing a system.

After solving part C of this assignment I come to know about the programming pattern of 32

bit processors and various interfaces.

4.2 Module learning outcomes

Different microcontroller architectural designs and programming skills were gained from

this module.

In this module I gained Interfacing of ARM with different peripherals.

Improve the knowledge of assembly and another higher level programming language like

„c‟.

Became more familiar with compiler like keil.

Page 25: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

25

References ________________________________________________________________________________

[1] Steve Furber, ARM System-on-Chip Architecture, 2nd edition, Addison-Wesley Professional,

2000

[2]http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0409f/Chdceejc.html

[3]http://www.arm.com/files/pdf/ARMCortexA-9Processors.pdf

[4] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0409f/Chdceejc.html

[5]http://infocenter.arm.com/help/topic/com.arm.doc.ddi0360f/DDI0360F_arm11_mpcore_r2p0_tr

m.pdf

[6] http://www.giplindia.com/pdf/water-valve-catalogue.pdf

[7]http://www.google.co.in/imgres?q=screw+conveyer&hl=en&safe=active&sa=G&gbv=2&biw=1

366&bih=643&tbm=isch&tbnid=vYpPhdRVAZMmyM:&imgrefurl=http://rhengineers.tradeind

ia.com/Exporters_Suppliers/Exporter14729.220193/Screw-

Conveyor.html&docid=X7Omiaq71jq

[8] http://coin-acceptor.com/pdf/WeavefutureCoinAcceptor.pdf

Page 26: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

26

Bibliography ________________________________________________________________________________

www.google.com

www.arm.com

www.keil.com

Page 27: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

27

Appendix ________________________________________________________________________________

Here is code for beverage vending machine.

#include<lpc21xx.h>

#include<string.h>

#include <stdio.H>

/* function prototype*/

void test(void);

void set_serial0(void);

void set_pll(void);

void send_string(char *p,int b);

void send_char(unsigned char f);

void delay(unsigned int x);

void first(void);

void second(void);

void add_user(void);

void prep_bav(void);

void log_mode(void);

void admin_func(void);

void read_rfid(void);

void make_db(void);

void send_in(int *A );

void disp(void);

void ask_admin(void);

void adc_init(void);

void temp_chk(void);

void tea(void);

void coin_accept(void);

void coffee(void);

Page 28: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

28

char final[14]="12345678901234";

char read[14];

int b,I=2;

char user[];

char ADMIN[14]="09876543210987";

/* structure to store the reg. user data*/

struct data

{

int no_m;

char ID[14];

int no_bev;

};

struct data mem[10];

/* main starts*/

int main()

{

PINSEL0=0x00000005;

PINSEL1=0x00400000; //confuguring p0.27 as analog input;

IODIR0=0x003FFF40; // for making input port p0.2,p0.3 switches; P0.6

Output Hot Water Relay inlet ; p0.8,p0.19 output ULN

set_serial0();

set_pll();

adc_init();

while(1)

{

test();

temp_chk();

first();

second();

}

Page 29: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

29

return 0;}

/* configure pll,pclk=30 mhz ,cclk =60mhz*/

void set_pll(void)

{

PLLCFG=0x04; // cclk will be 60mhz;

PLLCON=0x01;

PLLFEED=0xaa;

PLLFEED=0x55;

while(!(PLLSTAT & 0x400));

PLLCON=0x03;

PLLFEED=0xaa;

PLLFEED=0x55;

VPBDIV=0x02; // pclk will be 30 mhz;

}

/* this is admin change mode which can call by pressing switch 1 and 2*/

void ask_admin(void)

{

char c[50]=" SWAP YOUR CARD TO MAKE IS AS DEFAULT ADMIN";

send_string(c,strlen(c));

delay(100);

read_rfid();

strcpy(ADMIN,read);

}

/* for configuring serial 0*/

void set_serial0(void)

{

U0LCR=0x83;

U0DLL=0xc3;

U0LCR=0x33;

}

Page 30: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

30

/* for sending string serially*/

void send_string(char *p,int b)

{

int i;

for (i=0;i<=b;i++)

{ send_char(*p++);

}

}

/* sending integer to serial*/

void send_in(int *A)

{

{ send_char(*A);

}

}

/* sending character to serial*/

void send_char(unsigned char f)

{

while (!(U0LSR & 0x20));

U0THR=f;

}

/* sending log to uart*/

void disp(void)

{

char e[30]="user ";

char f[50]=" RFID NO IS : ";

char g[50]=" NO OF BEVERAGES CUPS CONSUMED BY THIS USER IS :";

int x,z ;

for(x=0;x<=I;x++)

{

send_string(e,strlen(e));

Page 31: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

31

send_char(mem[x].no_m);

send_string(f,strlen(f));

for(z=0;z<14;z++)

{

send_char(mem[x].ID[z]);

} send_char('\n');

send_string(g,strlen(g));

send_char(mem[x].no_bev);

send_char('\n');

}

}

/*for welcome screen */

void first(void)

{ char k[50]="*****************************************\n\r";

char f[50]="**:WELCOME TO BEVERAGE VENDING MACHINE:**\n\r";

char j[50]="*****************************************\n\n\n\n\r";

send_string(k,strlen(k));

send_string(f,strlen(f));

send_string(j,strlen(j));

}

/* for reading string from uart0 and storing in to read global variable*/

void read_rfid(void)

{

Page 32: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

32

int it,ir=0 ;

for (it=0;it<=13;it++)

{

while (!(U0LSR & 0x01));

read[ir]=U0RBR;

ir++;

}

}

/* first screen in log mode*/

void log_mode(void) // opration for log mode;

{

char c[60]="YOU ARE IN LOG MODE\n\n\n";

send_string(c,strlen(c));

disp();

}

/* for making database of user it edits the structure */

void make_db(void)

{

mem[I].no_m=I;

strcpy (mem[I].ID,read);

mem[I].no_bev=0;

}

/* for adding user procedural */

void add_user(void) //for adding user

{

int q;

char w[50]=" YOUR ID IS :" ;

Page 33: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

33

char t[50]=" PRESS 4 TO SAVE\n";

char d[100]=" SCAN USERS CARD \n" ;

//char ga[50]="YOUR CHOICE IS NOT VALID";

IOSET0=0x00200000;

send_string(d,strlen(d));

read_rfid();

send_string(w,strlen(w));

I++;

send_char('I');

delay(50);

send_string(t,strlen(t));

delay(100);

q=((IOPIN0&0x00000020)>>5);

if (q == 0x01)

{

make_db();

send_string("USER IS CREATED SUCSSFULLY",27);

}

else

{

// send_string(ga,strlen(ga));

I--;

}

}

/* for choice of tea and coffee*/

void prep_bav(void)

{

int ax;

char w[50]=" PRESS 1 FOR TEA\n";

char t[50]=" PRESS 2 FOR COFFEE\n\n\n";

send_string(w,strlen(w));

send_string(t,strlen(t));

Page 34: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

34

delay(50);

ax=((IOPIN0&0x0000000c)>>2); // masking of p0.0,p0.1 and all other ports;

if(ax==0x01)

{

tea();

}

else if(ax==0x02)

{

coffee();

}

}

/* 10ms delay*/

void delay(unsigned int x)

{

unsigned int g,h,kcf;

for (g=0;g<=x;g++)

{

for (h=0;h<=8200;h++)

{

for(kcf=0;kcf<=10;kcf++)

{;}

}}}

/* for admin functions*/

void admin_func(void)

{

int s,po;

char k[50]=" YOU NOT AUTHORISED FOR ADMIN LOGIN\n";

char j[50]=" YOU ARE AUTHORISED FOR ADMIN LOGIN\n\n\n";

char u[50]=" YOU ARE IN ADMIN MODE\n\n\n";

char c[50]=" PRESS 3 TO ADD THE USER\n\n"; //sw1=p0.0,sw2=p0.1,sw2=p0.3;

char z[50]=" PRESS 4 TO SEE LOG\n\n"; //sw4=p0.4

Page 35: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

35

char m[50]=" PLEASE SWAP YOUR ID CARD !!!\n\n\n";

IOSET0=0x00200000;

send_string(m,strlen(m));

read_rfid();

po= strcmp(ADMIN,read);

if(po==0) //chk for admin permision;

{

send_string(j,strlen(j));

delay(10);

send_string (u,strlen(u));

delay(10);

send_string (c,strlen(c));

delay(10);

send_string (z,strlen(z));

delay(10);

s=((IOPIN0&0x00000030)>>4);

switch(s)

{ //for adding user

case 0x01:

add_user();

break;

case 0x02: //for log

log_mode();

break;

}

} else

send_string(k,strlen(k));

Page 36: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

36

}

/* for mode selection */

void second(void)

{

int ir,a,hi;

char h[80]=" SCAN YOUR RFID TO MAKE IT AS ADMIN";

char g[80]=" You ARE IN REG.USER MODE\n\n";

char t[80]=" FOR ADMIN MODE PRESS SWITCH 1\n\n";

char d[80]=" FOR REG.USER MODE PRESS SWITCH 2 \n\n" ;

char y[80]=" YOU HAVE SUSSCESSFULLY CHANGED ADMIN ID";

char z[80]=" FOR NORMAL USER PRESS SWITCH 3\n\n\n";

char w[80]=" YOU ARE IN NORMAL USER MODE\n\n " ;

delay(50);

send_string(t,strlen(t));

send_string(d,strlen(d));

send_string(z,strlen(z));

delay(50);

a=((IOPIN0&0x0000003c)>>2); // masking of p0.0,p0.1 and all other ports;

if (a==0x01) //for admin mode;

{

admin_func();

}

else if (a==0x02)

//for user mode;

{

send_string (g,strlen(g));

send_char(13);

send_string("enter the RFID\n\n ",19);

send_char(13);

IOSET0=0x00200000;

read_rfid();

Page 37: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

37

for (ir=1;ir<=10;ir++)

{

hi=strcmp(read,mem[ir].ID);

if(hi==0)

{ // p=&mem[ir].no_bev;

mem[ir].no_bev++;

prep_bav();

}

}

}

else if (a==0x04)

{

send_string(w,strlen(w));

coin_accept();

}

else if (a==0x03) //switch 1 &2 will allow you chage the admin;;

{

send_string(h,strlen(h));

read_rfid();

strcpy(ADMIN,read);

send_string(y,strlen(y));

send_string("ADMIN HAS SUCESSFULLY CHANGED",30);

}}

/* adc initialization*/

void adc_init(void) //for temperature measurement and temperature limitation;

{

ADCR=0x00270601; // adc is at 3mhz;;

Page 38: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

38

ADCR|=0x01000000; // to start conversation;

}

/* for maintaining temperature of hot water*/

void temp_chk(void)

{

unsigned int v = 0;

if((ADDR&0x80000000)==0x00000000);

v=ADDR;

v = ((v >> 6) & 0x03FF); //Extract the A/D result

if(v>=0x3c)

{

IOCLR0=0x00000040; //if temp = 0x60 switch of the relay.

}

else

{

IOSET0=0x00000040; // by default heater will on;

}}

/* for rotating appropriate motor while tea is selected*/

void tea(void)

{

int io;

for(io = 0; io < 25; io++)

{

IOSET0=0x00000c00; // milk insertion motor shaft runs 5times = rotary feeder

1 time for approriate mixture of milk

IOSET0=0x00000900;

IOSET0=0x00000300;

IOSET0=0x00000600;

IOCLR0=0x00000f00;

Page 39: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

39

}

IOCLR0=0x00000f00;

for(io = 0; io < 15; io++)

{

IOSET0=0x0000c000; // tea insertion motor shaft runs 5times = rotery feeder 1

time for approriate mixture of tea

IOSET0=0x00009000;

IOSET0=0x00003000;

IOSET0=0x00006000;

IOCLR0=0x0000f000;

}

IOCLR0=0x0000f000;

IOSET0=0x00100000;

delay (1000);

IOCLR0=0x001000000;

send_string("here is your tea",30);

}

/* for rotating appropriate motor while coffee is selected*/

void coffee(void)

{

int io;

for(io = 0; io < 25; io++)

{

IOSET0=0x00000c00; // milk insertion motor shaft runs 5times = rotery feeder

1 time for approriate mixture of milk

IOSET0=0x00000900;

IOSET0=0x00000300;

IOSET0=0x00000600;

IOCLR0=0x00000f00;

}

Page 40: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

40

IOCLR0=0x00000f00;

for(io = 0; io < 10; io++)

{

IOSET0=0x000c0000; // tea insertion motor shaft runs 5times = rotery feeder 1

time for approriate mixture of tea

IOSET0=0x00090000;

IOSET0=0x00030000;

IOSET0=0x00060000;

IOCLR0=0x000f0000;

}

IOCLR0=0x000f0000;

IOSET0=0x00100000;

delay (1000);

IOCLR0=0x00100000;

send_string("here is your coffee",30);

}

/* for coin acceptor*/

void coin_accept()

{

int a;

IOCLR0=0x00200000; // To activate RX

delay(1);

send_string(" PLEASE ENTER 5 RS COIN IN COIN BOX\n",38);

delay(10);

read_rfid();

a=strcmp(final,read);

if (a==0)

{

prep_bav();

}

else

send_string("PLEASE ENTER VALID COIN",23);

Page 41: Assignment 1

MSRSAS - Postgraduate Engineering and Management Programme - PEMP

41

}

/* testing algoreathem*/

void test(void)

{

char qw[14]="2f3bac9d9ab632";

char er[14]="129232abcdef12";

char re[14]="00112233445566";

mem[0].no_m='1';

mem[1].no_m='2';

mem[2].no_m='3';

strcpy(mem[0].ID,qw);

strcpy(mem[1].ID,er);

strcpy(mem[2].ID,re);

mem[0].no_bev='5';

mem[1].no_bev='4';

mem[2].no_bev='8';

}