Top Banner
(Revision-10) FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100) PART-A (Maximum marks : 10) I. Answer all questions in one or two sentences. Each question carries two marks. 1. Give the size of on-chip program ROM and Data RAM in ATmega32. Ans: ATmega32 has Program ROM (Flash memory) of 32KB and Data RAM of 2KB. 2. The largest number that can be loaded into the GPR is ………...in hex. Ans: $FF, because each GPR in AVR is of 8bit size. 3. On power up, to which address SP points to? Ans: On power up, the SP register contains the value 0, which is the address of R0. 4. Write a program in C, to toggle all bits of PORTC. Ans: LDI R20, 0X55 OUT PORTC, R20 L1: COM R20 OUT PORTC, R20 JMP L1 5. How many single ended inputs are available on the ATmega32 ADC? Ans: 10 PART B II. Answer any five questions. Each question carries 6 marks. 1. Discuss the data RAM memory space allocation in AVR microcontroller. Ans: The data memory of AVR is composed of 3 parts: GPRs: General Purpose Registers I/O Memory Internal data SRAM Size of AVR Data Memory = Size of GPRs + Size of I/O Memory+ Size of Internal SRAM
20

EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

Apr 29, 2018

Download

Documents

phamxuyen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

(Revision-10)

FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/

TECHNOLOGY-MARCH 2014

EMBEDDED SYSTEMS

(Common for CT,CM)

[Time: 3 hours]

(Maximum marks : 100)

PART-A

(Maximum marks : 10)

I. Answer all questions in one or two sentences. Each question carries two marks.

1. Give the size of on-chip program ROM and Data RAM in ATmega32.

Ans: ATmega32 has Program ROM (Flash memory) of 32KB and Data RAM of

2KB.

2. The largest number that can be loaded into the GPR is ………...in hex.

Ans: $FF, because each GPR in AVR is of 8bit size.

3. On power up, to which address SP points to?

Ans: On power up, the SP register contains the value 0, which is the address of R0.

4. Write a program in C, to toggle all bits of PORTC.

Ans: LDI R20, 0X55

OUT PORTC, R20

L1: COM R20

OUT PORTC, R20

JMP L1

5. How many single ended inputs are available on the ATmega32 ADC?

Ans: 10

PART – B

II. Answer any five questions. Each question carries 6 marks.

1. Discuss the data RAM memory space allocation in AVR microcontroller.

Ans: The data memory of AVR is composed of 3 parts:

GPRs: General Purpose Registers

I/O Memory

Internal data SRAM

Size of AVR Data Memory = Size of GPRs + Size of I/O

Memory+ Size of Internal SRAM

Page 2: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

The General Purpose Registers in the AVR

AVR microcontrollers have many registers for arithmetic

and logic operations.

In the CPU, registers are used to store information

temporarily.

Information could be a byte of data to be processed, or an

address pointing to the data to be fetched.

The majority of AVR registers are 8-bit.

In AVR, there are 32 GPRs (R0-R32)., and located in the lowest location of

memory.

Same as accumulators in microprocessor, and used for all arithmetic and logic

operations.

I/O Memory (SFRs)

I/O memory is dedicated to specific functions such as status register, timers,

serial communication, I/O ports, ADC, etc.

The function of each I/O memory is fixed by the CPU designer at the time of

design.

Made of 8-bit registers.

No. of locations in the data memory set aside for data memory depends on

the pin numbers and peripheral functions of the chip.

All of the AVR have at least 64 bytes of I/O memory locations. This section

is called Standard I/O memory.

In AVRs with more than 32 pins(Eg: ATmega128, ATmega64,..), there is

also an Extended memory, which contains the registers for controlling the

extra ports and the extra peripherals.

Page 3: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

In other microcontrollers, the I/O registers are called SFRs(Special Function

Registers), since each one is dedicated to specific functions.

In contrast to SFRs, GPRs do not have any specific function and used for

general storing.

Internal Data SRAM

Used for storing data and parameters by AVR programmers and C compilers.

Generally, this is called Scratch pad.

Each location of the SRAM can be accessed directly by its address.

Each location is 8-bit wide and can be used to store any data of 8-bit size.

The size of SRAM can vary from chip to chip, even if its same family.

2. Compare and contrast microcontroller with general purpose microprocessor.

Ans:

Microprocessor Micro Controller

Microprocessor is heart of Computer system.

Micro Controller is heart of embedded system.

It is just a processor. Memory and I/O components have to be connected externally

Micro controller has processor along with internal memory and I/O components

Since memory and I/O has to be connected externally, the circuit becomes large.

Since memory and I/O are present internally, the circuit is small.

Cannot be used in compact systems and hence inefficient

Can be used in compact systems and hence it is an efficient technique

Cost of the entire system is high. Cost of the entire system is low

Due to external components, the entire power consumption is high. Hence it is not suitable to use with devices running on stored power like batteries.

Since external components are low, total power consumption is less and can be used with devices running on stored power like batteries.

Most of the microprocessors do not have power saving features.

Most of the micro controllers have power saving modes like idle mode and power saving mode.

Page 4: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

3. Explain three unconditional branch instructions.

Ans: 3 unconditional branch instructions:

1. JMP (Jump)

2. RJMP (Relative Jump)

3. IJMP (Indirect Jump)

Since memory and I/O components are all external, each instruction will need external operation, hence it is relatively slower.

Since components are internal, most of the operations are internal instruction, hence speed is fast.

Microprocessor have less number of registers, hence more operations are memory based.

Micro controller have more number of registers, hence the programs are easier to write.

Microprocessors are based on von Neumann model/architecture where program and data are stored in same memory module

Micro controllers are based on Harvard architecture where program memory and Data memory are separate

Mainly used in personal computers Used mainly in embedded systems like washing machine, MP3 players, printer.

Page 5: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

4. Discuss the methods used in AVR to increase the processing power.

Ans: 3 Ways to increase processing power of CPU:

1. Increase the clock frequency of the chip.

Drawback: Higher the frequency, more heat and power dissipation; problem for

hand-held devices.

2. Use Harvard architecture by increasing the number of buses to bring more

information (code and data) into the CPU to be processed.

3. Change the internal architecture of CPU and use RISC architecture.

5. With necessary diagram explain ATmega 32 connection to RS232.

Ans: RS232 (DB-25 Connector)

• An interfacing std that provides compatibility among data communication

equipment (DCE).

• Not compatible with TTL logic

• To connect any microcontroller system to a RS232, use Voltage convertors

like MAX232.

• MAX232 is commonly referred to as Line drivers.

ATmega32 Connection to RS232

RS232 is not TTL compatible, so a line driver MAX232 chip is required to

convert RS232 voltage levels to TTL levels.

RX and TX pins of ATmega32

• Pins used specifically for transferring and receiving data serially .

• They are part of PORT D group (PD0 and PD1) of the pin package.

• Pin 15 of ATmega32 assigned to TX

• Pin 14 of ATmega32 assigned to RX

Page 6: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

• These are TTL compatible, so they require a line driver to make them

compatible with RS232 such as MAX232

MAX232

• From Maxim. Corp

• Converts from RS232 voltage level to TTL voltage level.

• One advantage of MAX232 chip is that it uses +5V power source, which is

same as the source voltage for the AVR.

• So no need of dual voltage supply for AVR and MAX232.

• MAX232 has 2 sets of line drivers for transferring and receiving data.

6. List the features of built in ADC in ATmega 32.

Ans:

7. Distinguish between fast PWM mode and phase correct PWM mode.

Ans:

Page 7: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

The ATmega32 has 3 timers, which can be used as wave generators. The advantage of

using the built-in PWM feature of the AVR is that it gives us the option of

programming the period and duty cycle, there for load of CPU is reduced.

i. Fast PWM mode:

In the Fast PWM mode, the counter counts like it does in the Normal

mode. After the timer is started, it starts to count up until it reaches its

limit of 0XFF. When it rolls over from 0XFF to 00, it sets the HIGH

the TOV0 flag.

ii. Phase correct PWM mode:

In the Phase correct PWM, the TCNT0 goes up and down like a yo-yo.

First it counts up until it reaches the top value, then it counts down

until it reaches zero.

PART-C

(Maximum marks: 60)

(Answer one full question from each unit. Each question carries 15 marks)

UNIT--I

III.

a) Discuss various criteria for choosing a microcontroller for various applications. 8

Ans: Three criteria in choosing a microcontroller:

i. Meeting the computing needs of the task at hand efficiently and cost

effectively: considers speed, packaging, power consumption, amount of RAM

and ROM on the chip, ease of upgrade to higher or lower versions, cost.

ii. Availability of software and hardware development tools such as compilers,

assemblers, and emulators: how easy to develop products around it.

iii. Wide availability and reliable sources of microcontroller.

b) Explain the bit format of status register in AVR. 7

Ans:

Page 8: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

Like all microprocessor, the AVR has a flag register to indicate arithmetic

conditions such as the carry bit.

The flag register in AVR is called as Status register (SReg).

The status register is an 8-bit register., also referred to as the Flag register.

The bits C,Z, N, V, S and H are called Conditional flags, thats they indicate

some conditions that result after an instruction is executed., and each of them can

be used to perform a conditional branch (jump).

Flag bits of the status register:

C, the carry flag:

This flag is set when there is a carry out from the D7 bit.

Its affected after an 8-bit addition or subtraction.

Z, the zero flag:

Reflects the result of an arithmetic or logic operation.

If the result is zero, then Z=1, else Z=0.

N, the negative flag:

Binary representation of signed numbers uses D7 as the sign bit.

The negative flag reflects the results of signed number’s arithmetic operation.

If the D7 bit of the result is zero, then N=0 and the result is positive. If, D7=1,

then N=1, and result is negative.

V, the overflow flag:

Set whenever the result of a signed no. operation is too large, causing the

high-order bit to overflow into signed bit.

Overflow flag is used to detect errors in signed arithmetic operations.

S, the Sign bit:

This flag is the result of the Exclusive-ORing of N and V flags.

H, the Half carry bit:

If there is a carry from D3 to D4 during an ADD and SUB operation, this bit

is set, otherwise its cleared.

Used by instructions using BCD (Binary Coded Decimal) operations.

In some microprocessors, this is called AC flag(Auxiliary Carry).

(OR)

IV.

a) Draw the simplified diagram of AVR. Explain each block. 7

Ans:

Page 9: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

AVR microcontroller program ROM:

First microcontroller to use on-chip flash memory (can be erased in sec) for

program storage.

In microcontroller, the ROM is used to store program, so its called Program or

Code ROM.

AVR has 8MB of program ROM space., and can vary from 1K to 256K

depending on the family member.

AVR microcontroller data RAM and EEPROM:

The RAM space is for data storage., max 64KB.

The data RAM space has 3 components:

• 32 general purpose registers

• I/O memory

• Internal SRAM (size varies from chip to chip).

A small amount of EEPROM stores critical data that does not need to be

changed very often.

AVR microcontroller I/O pins:

Have 3 to 86 pins for I/O.

No. of I/O pins depends on no. of pins in I/O package(from 8 to 100)

In 8-pin AT90S2323, we have 3 I/O pins and in 100-pin ATmega1280, 86 I/O

pins.

AVR microcontroller peripherals:

ADC (Analog-to-digital converter): The ADC is 10 bit and the number of

ADC channels in AVR chips varies and can be up to 16.

Timers: The AVR can have 6 timers besides the watchdog timer.

USART (Universal Synchronous Asynchronous Receiver Transmitter ): The

USART Peripheral allows us to connect the AVR based system to serial ports

such as COM port of the x86 IBM PC.

Most of the AVR family has SPI (Serial Peripheral Interface) and I²C (Inter-

Integrated Circuit) buses, and some have USB or CAN bus.

b) Explain the various families of AVR and its features 8

Page 10: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

Ans: Various AVR families:

1. Classic AVR (AT90Sxxxx):

Original AVR chip, replaced by newer AVR

Not recommended for new designs

Program Memory: 2K to 4K bytes.

Package: 28 pins.

Eg: AT90S2313, AT90s2323, etc.

2. Mega AVR (ATmegaxxxx):

Powerful microcontroller with more than 120 instructions-Extended instruction

set.

Extensive peripheral set, which can be used in different design.

Program memory: 4K to 256K bytes.

Package: 28 to 100 pins.

Eg: ATmega8, ATmega16, etc

3. Tiny AVR (ATtinyxxxx):

Have less instruction or limited instruction set. Eg: Some of them do not have the

multiply instruction.

Smaller package: 8 to 28 pins.

Program memory: 1K to 8K bytes

Limited peripheral set.

Used to design low cost systems with low power consumption.

Eg: ATtiny13, ATtiny25, etc.

4. Special purpose AVR:

ICs of this group can be considered as a subset of other groups.

Their special capabilities are made for designing specific applications.

Special capabilities are: USB controller, CAN controller, LCD controller, Zigbee,

Ethernet controller, FPGA and PWM.

Eg: AT90CAN128, AT90USB1287, etc.

UNIT—II

V.

a) Explain the need for initializing the stack pointer. Give an example for

initializing the stack pointer. 8

Ans:

Page 11: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

b) Write a program in Assembly language to add 45A7H and 3C9AH and store the

result in memory locations 0X60 and 0X61. 7

Ans: Here 45A7H and 3C9AH are 16bit Hexadecimal numbers, so we need two

registers to load each number (Since GPRs of AVR are 8bit).

LDI R16, 45H

LDI R17, A7H

LDI R18, 3CH

LDI R19, 9AH

ADD R17, R19 ; Add LSB of both numbers (A7+9A)

ADC R16, R18 ; Add with carry (45+3C+Carry)

STS 0x60, R16

STS 0x61, R17

(OR)

VI.

a) Write a program to convert the packed BCD 35H into ASCII and store the result

in R21 and R22. 7

Ans: LDI R20, 0X35

MOV R21, R20

ANDI R21, 0X0F

ORI R21, 0X30

MOV R22, R20

SWAP R22

ANDI R22, 0X0F

ORI R22, 0X30

HERE: JMP HERE

Page 12: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

b) Show how AVR represent -38H. 4

Ans: Steps:

1. 0011 1000 38H in binary

2. 1100 0111 Invert each bit

3. 1100 1000 Add 1 (Which is C8 in hex)

Therefore, -38 = C8H, the signed number representation in 2’s

compliment for 38H. The D7=N=1, indicates the number is negative.

c) What are the conditions to set OV flag in AVR? 4

Ans: V, the overflow flag:

UNIT—III

VII.

a) Draw the block diagram of timer 0 and show how it work on normal and CTC

mode. 9

Ans: WGM01:00- Mode selection bits of timer

Different modes of Timer0:

1. 00:Normal mode

2. 01:Phase correct PWM mode

3. 10:CTC mode

4. 11:Fast PWM mode

Page 13: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

Normal Mode:

In this mode, the content of the timer increments with each clock. It counts until it

reaches a maximum value 0xFF.

When it rolls over from 0xFF to 0x00, it sets high a flag bit called TOV0 (Timer

Overflow)

CTC Mode (Compare Match):

The OCR0 register is used with the CTC mode.

In the CTC mode, the timer is incremented with each clock pulse.

But it counts up until the content of TCNT0 register becomes equal to the content of

OCR0 register (compare match occurs).

Then the timer will be cleared, and OCF0 flag will be set with next clock pulse.

The OCF0 flag locates in TIFR (Timer Interrupt Flag Register).

Page 14: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

b) Give the steps in programming the AVR to transfer data serially. 6

Ans: Data Serialization in C:

OR

VIII.

a) Explain the following terms:

i. Interrupt priority

ii. Interrupt latency. 8

Ans:

i.

ii. Interrupt latency:

The time from the moment an interrupt is activated to the moment the

CPU starts executing the task.

During this time, the PC register is pushed onto the stack and the I bit of

the status register is cleared, causing all the register to be disabled.

Interrupt latency duration can be affected by:

Type of instruction that the cpu is executing when the interrupt comes

in.

b) A door sensor is connecter to the PORTB pin 1, and an LED is connected to

PORTC 7. Write an AVR C program to monitor the door sensor and when it

opens, turn on the LED. 7

Page 15: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

Ans:

UNIT—IV

IX.

a) Explain the steps in sending data and command to LCD. 7

Ans:

Page 16: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

b) Explain the interfacing of DAC0808 with ATmega 32. 8

Ans:

Page 17: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

OR

X.

a) Explain the steps involved in scanning a matrix keyboard using AVR. 7

Ans:

Page 18: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.

b) Draw the interfacing of temperature sensor with AVR and write a program in C

to read the sensor and displays it on PORT D. 8

Ans:

LM34 and LM35 are linear temperature sensor devices available in market.

Page 19: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.
Page 20: EMBEDDED SYSTEMS - Madin Polytechnic Collegemadinpoly.com/pdf/solved/5/s5-ct-ES_Mar-14.pdf ·  · 2016-10-14Used mainly in embedded systems like washing machine, MP3 players, printer.