Showing posts with label Embedded System. Show all posts
Showing posts with label Embedded System. Show all posts

Wednesday 2 July 2014

The AVR Microcontroller

by Unknown  |  in The AVR Microcontroller at  07:55
                                       The AVR Microcontroller
The AVR enhanced RISC microcontrollers [1] are based on a new RISC architecture
that has been developed to take advantage of semiconductor integration and software
capabilities of the 1990's. A block diagram of the AVR architecture is given in figure 1.
The memory sizes and peripherals indicated in the figure are for the AT90S8414
microcontroller.Central in the AVR architecture is the fast-access RISC register file, which consists of
32 x 8-bit general purpose working registers. Within one single clock cycle, AVR can
feed two arbitrary registers from the register file to the ALU, do a requested operation,
and write back the result to an arbitrary register. The ALU supports arithmetic and
logic functions between registers or between a register and a constant. Single register
operations are also executed in the ALU.
As can be seen from the figure, AVR uses a Harvard architecture, where the program
memory space is separated from the data memory space. Program memory is accessed
with a single level pipelining. While one instruction is being executed, the next
instruction is being pre-fetched from the program memory.
Due to the true single cycle execution of arithmetic and logic operations, the AVR
microcontrollers achieve performance approaching 1 MIPS per MHz allowing the
system designer to optimize power consumption versus processing speed.
Figure 1: The AVR Architecture (AT90S8414)
The Architecture allows for up to 8M Bytes program memory, and 16MBytes of Data
memory, and covers a wide range of applications.
Fine tuning AVR
There are several advantages in using HLLs in stead of using Assembly language when
developing microcontroller applications. There has, however, traditionally been one
major disadvantage: the size of the code increases. The AVR microcontroller was
developed with the C language in mind in order to make it possible to construct a code
efficient C compiler for AVR. To improve this feature even more, the development of
the C compiler was started before the architecture and the instruction set were
completed. By allowing professional compiler developers at IAR Systems in Sweden
to comment on the architecture and instruction set, we were able to make a
microcontroller very well suited for C compiler generated code.
This section describes the modifications that were done in order to tune the
architecture and instruction set towards even more towards the C language.
Addressing modes
In order for the compiler to generate efficient code, it is important that the supplied
addressing modes matches the needs of the C language. The AVR architecture was
originally equipped with two pointer registers. These two pointers could be used for
indirect addressing, indirect addressing with post increment, indirect addressing with
pre-decrement, and indirect addressing with displacement, giving good support for
operation on pointers. In addition, there was a paged direct addressing mode for
accessing variables placed in the data memory.
Displacements
The indirect addressing mode with displacement is a very useful addressing mode, also
from a C compilers point of view. For example, by setting the pointer to the first
element in a struct, you can reach as far in the struct as the displacement allows
you, without having to change the 16-bit pointer. The indirect addressing with
displacement mode is also frequently used for accessing variables placed on the
software stack. Function parameters, and autos are often placed on the software stack,
and can be read and written without having to change the pointers. The displacement
addressing is also very useful in addressing elements in an array.
Even though the displacement mode is very useful in many cases, there was a problem
with the reach of this addressing mode. Originally, the displacement was limited to 16
locations, whereas the displacement needed in real applications often exceeds this
number. In the case where the location can not be reached by the displacement mode, a
new pointer needs to be loaded. To expand the reach of the displacement mode, we
needed to change other parts of the instruction set to get enough coding space. At the
same time, we were informed that the paged direct accessing mode was difficult to use
from the compilers point of view. By removing the paged direct addressing mode,
space was made available for expanding the displacement to 64 locations, which is
large enough to meet most demands for indirect addressing. The paged direct
addressing mode was changed to a two word unpaged direct addressing mode, see
below.
The number of memory pointers
The AVR microcontrollers were originally equipped with two 16-bit memory pointers.
From a C Compilers point of view, one of these pointers must be used as a dedicated
software stack, leaving only one memory pointer for general usage. In many cases, you
need to copy memory from one area to another. Having only one memory pointer, you
would need to read one byte, set the pointer to the destination area, write the byte and
then set the pointer back to the source data area. By including a third memory pointer
(with reduced functionality), data can be copied from one memory area to another
memory area without having to set the pointers. By exploiting the post increment
mode of pointer addressing very efficient loops can be constructed for this purpose
(assuming Z points to first byte in source, X points to first byte in destination):
LDI R16,0x60 ; Load byte count
loop: LD R17,Z+ ; Load byte, increment pointer
ST X+,R17 ; Store byte, increment pointer
SUBI R16,1 ; Decrement counter
BRNE loop ; Branch if more bytes
The possibility to post-increment and pre-decrement also makes the pointers very
efficient for implementing stacks. This is of course utilized in the software run-time
stack.
Direct addressing
As described in the displacement section, we originally had a paged direct addressing
mode which was difficult and inefficient to use by the compiler. Since we needed
coding space for an increased displacement, the paged direct addressing mode was
removed. It is, however, inefficient not having any direct addressing mode, since we in
some cases need to access variables placed in the data memory area. Especially when
dealing with static characters, the code overhead will be large (50%), since
static variables needed to reside in data memory and can not automatically be
placed in registers. In order to overcome this problem with inefficient code, we
decided to include unpaged direct addressing instructions taking a 16-bit address,
making it possible to address 64KByte data memory in one instruction. In order to
access such a large amount of memory, these instructions had to be two 16-bit words.
Using this addressing mode is more efficient than using pointers when the number of
bytes to be accessed is small, for instance when a character is read. For larger areas, it
may still be more effective to use indirect addressing (see example below).
Loading of a character:
Indirect addressing (6 Bytes): Direct addressing (4 Bytes):
LDI R30,LOW(CHARVAR) LDS R16,CHARVAR
LDI R31,HIGH(CHARVAR)
LD R16, Z
Loading of a long integer:
Indirect addressing (12 Bytes) Direct addressing (16 Bytes)
LDI R30,LOW(LONGVAR) LDS R0,LONGVAR
LDI R31,HIGH(LONGVAR) LDS R1,LONGVAR+1
LDD R0,Z LDS R2,LONGVAR+2
LDD R1,Z+1 LDS R3,LONGVAR+3
LDD R2,Z+2
LDD R3,Z+3
Zero flag propagation
In order to make conditional branches, a number of the instructions manipulates the
AVR status register, which consists of a number of flags. A conditional branch
instruction following such an instruction, will branch or not branch, depending on the
settings of these flags. The arithmetic instructions manipulate the flags, making it
possible to check whether a number A is smaller than, equal to or greater than another
number B. When the numbers in question are eight bit numbers, there are no problems,
since all the flags are depending on the flag setting done by one instruction only. When
using 16 or 32 bit numbers, which is common in the C language, the problem is
somewhat more tricky, since a 32 bit subtraction, for instance, is calculated as 4
consecutive 8 bit subtractions, and after each subtraction, a new set of flags is
generated.
For propagating the carry flag, most processors have incorporated instructions which
takes into account the previous setting of the carry flag, for instance SBC - subtract
with carry where SBC A,B means A=A minus B minus Carry-bit. There is however,
another flag that needs to be propagated in order to be able to correctly do all
conditional branches. This is the Zero flag.
Example:
A=R3:R2:R1:R0, B=R7:R6:R5:R4
We want to subtract B from A and jump to a specific location if A is equal to B. If the
Zero flag is only dependent on the last arithmetic instruction, the following sequence
will not do:
SUB R0,R4
SBC R1,R5
SBC R2,R6
SBC R3,R7 ; R3=R7 => Zero flag set
BREQ destination
since the flag settings present during the BREQ instruction only depends on the flags
set by the last SBC instruction. If the most significant bytes are equal, the Zero flag
will be set and the branch will be done, even if the 32 bit numbers are not equal. This
problem also applies to other conditional branches.
There are two ways of overcoming this problem. One is to save the flags produced by
each instruction, and then check all the zero flags after the fourth subtraction is done.
The other, more elegant way, is to propagate the zero flag in the carry instructions like
this:
Znew =Not(R7) AND
Not(R6) AND
...
Not(R0) AND
Zold
By propagating the Zero flag in this way, all conditional branches can be done after the
final subtraction, since all the rest of the interesting flags (overflow and positive flag)
are only dependent on the most significant byte.
Tuning the arithmetic instructions
Some tuning of the arithmetic instructions was also done. This tuning is described
here.
Addition and subtraction
We originally planned to have both addition and subtraction with eight bit constants -
ADDI and SUBI. We did, however, not have space for having Carry instructions with
constants, so a 16 bit add with a constant would look like this:
ADDI R16,0x44
LDI R18,0x55
ADC R17,R18
An addition can, however, be realized as a subtraction and vice versa, so it was
decided that the ADDI instruction should be changed to a SBCI instruction, thereby
enabling 16 and 32 bit additions and subtractions with constants, thereby reducing
code size substantially in 16 and 32 bit cases and with no code size penalty for 8 bit
cases.
Compare with constant
The original instruction set did not include any instruction for comparing a register
with a constant. In order to do such an operation, a constant had to be loaded into a
register, and then the two registers could be compared. This is a very frequently used
operation, and as a result of removing one of the original addressing modes, space was
found in the instruction coding for this instruction.
Non-destructive comparison
If you want to compare two eight bit numbers, then this can be done by using a
compare instruction. If you want to compare 16 or 32 bit numbers however, you
would originally have to compare use subtraction with carry in order to get the flag
setting right. The problem with using subtraction with carry is that it overwrites the
contents of one of the numbers you are comparing. One solution to this problem is to
copy this number over to new locations before subtracting, but such a solution will
require more instructions and will use more registers. In order to overcome this
problem, we decided to include a Compare with carry instruction, thereby enabling
nondestructive comparison of numbers larger than eight bit.

Monday 19 May 2014

Embedded System

by Unknown  |  in The AVR Microcontroller at  03:15
Embedded System

Introduction:

            A system is a way of working, organizing or doing one or many tasks according to afixed Plan, program, or set of rule.

            An embedded system is a system that has embedded software and computer hardware, which makes it a system dedicated for an application or specific part of an application or product or a part of a larger system.

It is not easy to give precise definition of embedded system as it is complex   system but in simple words we can say that:

“It is the system which is on a single chip or employs a combination of hardware (computational engine) and software to perform a specific function.”

It is one type of computing device but not like PC. We can better understand such systems by examining common examples and common characteristics. Embedded system is found in a variety of common electronic devices such as consumer electronics, home appliances, office automation, business equipment and automobiles.

Characteristics of embedded system:

  1. It acts as single functioned or has tightly bound set of functions means it is not used as general purpose.
  2. It is very reactive and real time constrained.
  3. Increasingly high performance.
  4.  
  5. Application specific processor design can be a significant component of some embedded system.

Requirements of embedded systems:


 Types of requirements imposed by embedded applications:

 1 Functional requirement
 2 Temporal requirements
 3 Dependability requirements

1. Functional Requirements
Ø  Data Collection
Ø  Direct Digital Control
Ø  Man-Machine Interaction

2. Temporal Requirements
Ø  Tasks may have deadlines
Ø  Minimal latency jitter
Ø  Minimal error detection latency
Ø  Timing requirements due to tight software control loops
Ø  Human interface requirements.

3. Dependability Requirements.
Ø  Reliability
Ø  Safety
Ø  Maintainability
Ø  Availability
Ø  Securit



Classification

There are three types of embedded system are classify.



1). Small scale embedded system:
          
           These system are designed with a single 8 or 16 bit microcontroller; they have little

hardware and software complexities and involve board-level design. They may even be battery

operated. When developing embedded software for these, an editor, assembler and cross

assembler, an integrated development environment tool specific to the microcontroller or

processor used, are the main programming tools

2) Medium scale embedded system :
          
           These system are usually designed with a single or a few 16 or 32 bit microcontrollers,

DSPs or RISCs.These system may also employ the readily available single purpose processors

and IPs for the various function –for example, bus interfacing.Mediam scale embedded system

have both hardware and software complexities.

3) Sophisticated embedded systems:

           Sophisticated embedded system have enormous hardware and software complexities and

may need several IPs, ASIPs, scalable processors or configurable processors and programmable

logicarrays.They are used for cutting edge application that need hardware and software co-

design and components that have to be integrated in the final system .They are constrained by

the processing speeds available in their hardware units.




Block diagram of embedded system 




An embedded system typically comprises the embedded hardware, embedded RTOS, device drivers, communication stacks and embedded application software.

  1. Hardware: processors, ASICs (application specific ics), memory. It is used for performance and sometimes.
  2. Software: C or Assembly language is used as software. It is used for providing features and flexibilities.


Major Components in Embedded Systems
Ø  Data acquisition and processing
Ø  Communication
Ø  System logic and control algorithm
Ø  Interface
Ø  Auxiliary units
§  Display
§  Storage
§  Monitoring and protection
§  Test and diagnosis.
ARCHITECTURE

Embedded hardware

Functioning of any embedded system is depended on three aspects processing, storage, and communication. We use processor to implement processing, memory to implement storage and buses to communicate.

  1. Processor:

A processor is a digital circuit designed to perform computation tasks. A processor consists of data lines capable of storing and manipulating data and controller capable of moving data through the data lines.


Processor Types Used in New Embedded Designs
 
 



In many applications we use micro controllers in place of processors.” A micro controller is a device that includes microprocessor, memory and I/O signal lines on a chip.”e.g.families of  MC68HC11,MC68HC12 .                            

  1. ASICs: (Application Specific Integrated Circuits)
It is the silicon chip with an array of unconnected transistors. It includes gate arrays and standard cell ICs. It is the basic part of embedded system. It is a semi custom device. The function is defined by the designer for particular application but not defined by the manufacture.


  1. Memory:
A fixed size volatile memory such as DRAM or SRAM & non-volatile    memory such as flash or EPROM, connected to microprocessor or micro controller, is used. So the range of memory is depend upon the application means according to microprocessor or micro controller Memory access refers to either read or write. Some types of memory write ability refers to the manner & speed. Depending upon various memory types of writing that particular memory.
           
At the high end of the range, we have types of memory where we simply or quickly write. At the middle range, we can slowly write.  At the lower end of range, we have types memory that can be only written by programmer. In some cases the available memory is larger then needed this becomes easy to deal with but if the available memory is smaller than needed, then we must imposed several smaller memories to behave as a large memory.

4.      Peripherals:
According to the block diagram of embedded system as shown in the figure above analog I/O consists of the several peripherals according to the requirement or the application. Some of the peripherals are listed below:

·         Timer, counter
Timer is the most common peripheral device that measures time intervals. It can be used to either generate events at specific times or to determine the duration between two external events. As for the example, keeping the traffic light green for a specific duration, etc.

Counter is a more general version of timer. For example, counter can be used to count the number of cars that pass over road sensor or the number of people passing through the turnstile.

  • UART (universal asynchronous receiver/transmitter)
It is used in serial communication. It is needed to communicate bytes of data between devices that are separated by long distances or when those devices have few available I/O pins. Internal construction of UART includes some registers and two independent operating processors one for receiving and other for transmitting.

  • Pulse width modulators
Pulse width modulation is used to generate clock like signals to another devices. This approach is beneficial for single purposes by simplicity and efficiency
For example, pulse width modulation can be used to blink a light at a specific rate.

  • DMA controller (direct memory access)
It is used for transferring data between memories and peripherals. We have IC 8257 for DMA controller. We can easily interface it with microprocessor. It can transfer a full block of data, hence is used in CD ROM or disk controllers.


  • LCD controllers (liquid crystal display)
It is the display or output device. It is a very low cost power device. It can display text and images. For example, watches, fax and copy machines, calculators.


  • Keypad controllers
It is the input device and is used to give the input to the embedded system.

  • Stepper motor controllers
It rotates a fixed number of degrees whenever step signal is applied. We can directly give DC signal to it. Stepper motors are common in embedded systems with moving parts like disk drivers, printers, photocopy and fax machines, robots, camcorders, etc.


  • ADC converters
It is most useful as embedded systems deal with digital signals but its surroundings consist of many analog signals, which are the input to the embedded system like temperature, speed.

  • Real time clocks (RTC)
It keeps the time and date in an embedded system.

Depending on the targeted application of the device the peripherals can include communication devices such as serial controllers, Ethernet controller or wireless communication controller and other application specific ICs.

Other blocks of ES:
                  
Major functional block decisions must be made under this, such as the selection of real time kernel, major algorithms and data structures in software, or the power source or networking protocol used in hardware.

                        For micro controller – based designs we require MCU resources such as GPIO ports, timers and ADCs.

Interfacing schemes
                        One factor that makes an ES different from a regular computer is the special I/O devices we interface to our ES. Interfacing includes both the physical connections of the hardware devices & software routines that affect information exchange. We can use many interfacing schemes like: parallel I/O interface, memory interface, high speed I/O interface, analog interface.




 
Embedded Software





Programming is the design and debugging of a sequence instruction. Basically software contains programming of processor of the embedded system. Two types of programming languages are mainly used:

  1. Assembly language
  2. C programming language

The selection of language affects the selection of processor, memory and development tools and is driven by portability, reliability and readability.

Assembly language
It is made up of a set of mnemonics each mnemonics corresponds directly to a processor machine instruction code. So for translating assembly language we need assembler and in embedded system we use cross assembler. Nearly every embedded system requires that at least some portion of the program be written in assembly language, which may deal with low-level I/O operations. But assembly language is not widely used.

C language
As it is the high level language it is shorter and easier to write. It is independent of the processor, but we need a compiler to translate high level language to machine code. Using C language has two important advantages, because of which it is much easier for programmer to write quality programs that are easier to read, revise, and port to a different system. This advantages are- 1.built in structure.
2.type checking & abstraction.
 If the embedded device is capable of communicating total eternal world, it has a software-communicating stack running on the top of the operating system. In order to connect the Internet the embedded device needs a TCP/IP stack. Hence it is used more frequently thanassembly language. In many application user used this language.

OPERATING SYSTEM

All intelligent devices that perform complex functions have an embedded OS inside it. This OS is typically real time in nature i.e., it is capable of responding to time critical external events.

The concept of real-time operating system (RTOS) is inseparable when we talk about embedded systems. RTOS is built for specific applications and guarantees response to an external event within a specified time constrain. It responds to inputs immediately. for example, when u suddenly apply breaks of yr car to avoid an accident, the “intelligent gadget” responds immediately. Vxworks is the most widely adopted RTOS in the embedded industry.

OS is larger software that provides low-level services to large applications. OS is responsible for deciding what program is to run next on the processor and for how long. This is called task scheduling. OS provides various software hardware interrupts. Device drivers are the lowest level software that acts as glue between the operating system and the peripheral device that is connected to the microcontroller. Best example of OS is Linux. It is used in many applications. In recent times, Linux has migrated from servers and workstations to be used in diverse embedded applications.


Real time ES


Ø  All Virtually embedded systems require real-time response while running more than one task.

Ø  A Real-time system is the system that must respond to signals within explicit and bounded time requirements.

Ø  To coordinate the process of sharing the CPU between multiple tasks, we use a program called a kernel. A kernel is the part of an operating system that schedules and dispatches tasks. For most ES we need a real time kernel because deterministic response time is required. In new ES real time kernels are used, e.g., Digital camera
ATM, Battery charger, Camcorders, Cell phones, etc.


Application:

  • Military and aerospace embedded software applications


From in-orbit embedded systems to jumbo jets to vital battlefield networks, designers of mission-critical aerospace and defense systems requiring real-time performance, scalability, and high-availabilityfacilities consistently turn to the LynxOS® RTOS and the LynxOS-178 RTOS for software certification to DO-178B.
Rich in system resources and networking services, LynxOS provides an off-the-shelf software platform with hard real-time response backed bypowerful distributed computing (CORBA), high reliability, software certification, and long-term support options.





Medical devices can now have the best of both worlds, with hard real-time applications running alongside commercial desktop operating systems on the same industry-standard Intel® processors.

·         Communications applications

Communication is essential to achieving a dependable distributed embedded system.An example of an event based communication system is the typical office network. Messages are generated by users whenever they send data to printers, access data on shared network drives, run applications that exist on other machines or send email to others in the network.



Various classes of embedded systems such as home media systems, portable players, smart phones, embedded medical devices and sensors, automotive embedded systems have surrounded us and with continued convergence of communications and computing functions within these devices, embedded systems are transforming themselves into really complex systems,  thus creating newer opportunities and challenges to develop and market more powerful, energy efficient processors, peripherals and other accessories.



Industrial automation (IA) is the vast area of embedded computing devoted to industrial applications. Apart from many tailored solutions (numerical controllers, hardware controllers, etc.) the scene is dominated by programmable logic controllers, widely known by the abbreviation PLC, which represent the most wide-spread class of embedded computing platforms.


Advantages:


Ø  Customization yields lower area means compact size
Ø  Lower power
Ø  Lower cost
Creating computer hardware requires precise engineering design & when it is an embedded system, it has to be more than reliable. Besides being low in cost & sufficiently high on performance.



Disadvantages:

Ø  Higher hardware/software
Ø  Need designer, compilers, debuggers
Ø  May result in delayed time.


Conclusion:
           


From what we saw above we conclude that embedded systems are very much advantageous. More & more developments are taking place in embedded systems. Even in INDIA software called mistral has developed text to speech and speech to text recognition technologies to give the car occupants the ultimate comfort. A   DSP based biomedical card developed by mistral allows remote   monitoring of up to 32 patients at a given time through central computer. This system is capable of acquiring ECG data from patient 7 analyzing it.

Tata InfoTech has done many remarkable projects in embedded application. Now a days readymade chip of micro controllers which are already programmed for specific functions, are available. It is very cheap also.

Finally we can say that embedded systems are electronic devices that incorporate a computer (usually a microprocessor) within their implementation.  A computer is used in such devices primarily as a means to simplify the system design and to provide flexibility.Often the user of the device is not even aware that a computer is present.

The day is not far when almost all automobiles would interact with computers on dashboards from ordering a pizza to booking tickets at nearest theater. Things would be as easy as giving orders to your servant.                                                                                                                                                                                     
Bibliography




1.     Embedded system  : by – Raj Kamal

2.     Embedded system : Wikipedia.com

3.  www.lynuxworks.com

4.  Embedded Systems Design

by Arnold S. Berger,

Proudly Powered by Blogger.