Thursday, 30 May 2013

Embedded System - 01

Keyword: Embedded System, Microcontroller

Embedded System Tutorial - 01


Introduction to Embedded System
In the daily life we use lots of electronics devices like Calculators, Computers, Automatic Washing Machines and Mobile Phones etc. The common thing in all these devices is that they all contain Microprocessor (Brain in the Electronic Systems). So they all are Microprocessor Based System. Actually Microprocessor based systems are divided into two categories:

Reprogrammable Systems
These are the general-purpose systems. We can run programs of different type of language programs like C, C++, Java, Visual Basic etc. Even we can listen the music, watching the movies, surfing Internet, sending mails etc. That is, these systems can be reprogrammed from the user's end and they are general-purpose type. Examples of these systems are Personal Computer, Laptop, and Workstations etc.
Embedded Systems
These are not general-purpose systems but these systems are specially designed for specific applications. The examples of Embedded Systems are Robots, Calculators, Digital Weighing Machine, Xerox Machine, Metro Rails without Drives etc. In such a ways we can say that, Embedded Systems are the microprocessor or microcontroller based electronics systems which are designed for the specific task only.
What is a Microcontroller?
A Micro controller consists of a powerful CPU tightly coupled with memory RAM, ROM (or EPROM), various I/O features such as Serial ports, Parallel Ports, Timer/Counters, Interrupt Controller, Data Acquisition interfaces-Analog to Digital Converter (ADC), Digital to Analog Converter (ADC), everything integrated onto a single Silicon Chip.
It does not mean that any microcontroller should have all the above said features on chip, Depending on the need and area of application for which it is designed, The ON-CHIP features present in it may or may not include all the individual section said above.
Any microcomputer system requires memory to store a sequence of instructions making up a program, parallel port or serial port for communicating with an external system, timer/counter for control purposes like generating time delays, Baud rate for the serial port, apart from the controlling unit called the Central Processing Unit.
Difference between Microprocessor and Microcontroller
Microprocessor:
  • CPU is stand-alone, RAM, ROM, I/O, timer are separate
  • Designer can decide on the amount of ROM, RAM and I/O ports.
  • Expansive
  • Versatility
  • General-purpose
Microcontroller:
  • CPU, RAM, ROM, I/O and timer are all on a single chip 
  •  fix amount of on-chip ROM, RAM, I/O ports
  • for applications in which cost, power and space are critical
  • single-purpose
Conclusion:
Both microprocessors and microcontrollers have to run commands and therefore run a device on its own, however it’s the minute architectural design of the microcontroller that leaves a person interested in awe of the tasks it can perform when it is compared to a microprocessor. When a person requires running a word document or a video game on their computers they are essentially using the microprocessor, and when they have to work a microwave oven, they are working a microcontroller. Therefore, microcontrollers are more specific to the appliance they are configured for.

Features of 8051 Microcontroller’s:
  • 8-Bit CPU Optimized for Control Applications
  • Extensive Boolean Processing Capabilities (Single-Bit Logic)
  • On-Chip Flash Program Memory of 4kB (89X 51 families)
  • On-Chip Data RAM 128 Byte
  • Bi-directional and Individually Addressable, I/O Lines
  • Multiple 16-Bit Timer/Counters
  • Full Duplex UART for serial communication
  • Multiple Source/Vector/Priority Interrupt Structure
  • On-Chip Clock Oscillator
  • On-chip EEPROM (AT89S series)
  • SPI Serial Bus Interface (AT89S Series)     
  • Watchdog Timer (AT89S Series)
8051 Architecture and Pin diagram:
8051 Pin Description:

  • P0-Port 0 ( Pin 32-39)
  • P1-Port 1 (pin 1-8) 
  • P2-Port 2 (Pin 21-28)
  • P3-Port3(Pin10-17)      
  • AD0 - AD7 -          Multiplexed Address/data lines
  • A8-A15 -                High Order Address Lines
  • RST -                     Reset (pin 9)
  •  T0, T1  -                Timer Clock Input
  • INT0, INT1 -        External Interrupt Lines
  • XTAL1, XTAL2 - Crystal Oscillator Pins (Pin 18-19)
  • WR,  RD  -            Write, Read Lines
  • RxD, TxD  -           Serial Receive / Transmit Lines
  • ALE/PROG -        Address Latch Enable / Program   Logic In burning the Flash ROM)
  • EA/VPP -               External Enable / VCC (burning the Flash ROM) VCC / GND = +5 volt
  • PSEN -                   Program Store Enable (Pin 29)
  •  GND                    Ground (Pin 20).
  • VCC-                     +5V Power Supply.
Port 0 (Pin 32-39):
Port 0 is an 8-bit open drain bidirectional I/O port. If external memory is not used, these pins can be used as general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0).

Port 1 (pin 1-8):
Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. Port 1 also receives the low-order address bytes during Flash programming and verification.

Port 2 (Pin 21-28):
Port 2 is an 8-bit bidirectional I/O port with internal pull-ups.  If there is no intention to use external memory then these port pins are configured as general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which means that not all eight port bits are used for its addressing, the rest of them are not available as inputs/outputs.

Port 3 (Pin10-17):
Port 3 is similar to Port 1. Each of these pins can serve as general input or output. Besides, all of them have alternative functions:
  • P3.0       RXD (serial input port)
  • P3.1       TXD (serial output port)
  • P3.2       INTO (external interrupt 0)
  • P3.3       INT1 (external interrupt 1)
  • P3.4       T0   (timer 0 external input)
  • P3.5       T1 (timer 1 external input)
  • P3.6       WR (external data memory write strobe)
  • P3.7       RD (external data memory read strobe)
Port 3 also receives some control signals for Flash programming and verification.
RST (pin 9):
Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device.
ALE/PROG (pin 30):
Address Latch Enable output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming.  In normal operation ALE is emitted at a constant rate of 1/6 the oscillator frequency, and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is skipped during each access to external Data Memory.  If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode.
PSEN (pin2 9):
Program Store Enable is the read strobe to external program memory.  When the AT89C51 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory.
EA/VPP (pin 31):
EA (External Access) must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH.  Note, however, that if lock bit 1 is programmed, EA will be internally latched on reset.  EA should be strapped to VCC for internal program executions.  This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming, for parts that require 12-volt VPP.

Keyword: Embedded System, Microcontroller

Wednesday, 29 May 2013

First program using VHDL


Keyword: VHDL

First Program using VHDL

VHDL code of 2-input AND gate using Data Flow

Library IEEE;                                         library part

Entity abc is
          Port (a: in bit;                             Entity part
                  b: in bit;
                         c: out bit);
end abc;                        -- Comment (only single line comment is possible)

architecture xyz of abc is
begin                                                                          
c<= a and b;                                Architecture part
end xyz;


Note: Here "abc" is the entity name and "xyz" is the architecture name. (entity name and architecture name may or may not be the same)

VHDL Tutorial-01


Keyword: HDL, VHDL

VHDL Tutorial-01

VHDL stands for VHSIC Hardware Description Language, and VHSIC in turn stands for Very High Speed Integrated Circuits. VHDL is an acronym for Very High Speed Integrated Circuit Hardware Description Language which is a programming language used to describe a logic circuit by function, data flow behavior, or structure.
VHDL is a programming language: although VHDL was not designed for writing general purpose programs, you can write any algorithm with the VHDL language. If you are able to write programs, you will find in VHDL features similar to those found in procedural languages such as C, Pascal or Ada. VHDL derives most of its syntax and semantics from Ada. Knowing Ada is an advantage for learning VHDL (it is an advantage in general as well).
However, VHDL was not designed as a general purpose language but as an HDL (hardware description language). As the name implies, VHDL aims at modeling or documenting electronics systems. Due to the nature of hardware components which are always running, VHDL is a highly concurrent language, built upon an event-based timing model.
Like a program written in any other language, a VHDL program can be executed. Since VHDL is used to model designs, the term simulation is often used instead of execution, with the same meaning. Like a program written in another hardware description language, a VHDL program can be transformed with a synthesis tool into a netlist, that is, a detailed gate-level implementation.
VHDL is one of the HDL languages available in the industry for designing the Hardware. VHDL allows us to design a Digital design at Behavior Level, Register Transfer Level (RTL), Gate level and at switch level. VHDL allows hardware designers to express their designs with behavioral constructs, deferring the details of implementation to a later stage of design in the final design.
Design Styles:
VHDL like other hardware description language (HDL) permits the designers to design a design in either Bottom-up or Top-down methodology.
Bottom-Up Design:
The traditional method of electronic design is bottom-up. Each design is performed at the gate-level using the standard gates ( Refer to the Digital Section for more details) With increasing complexity of new designs this approach is nearly impossible to maintain. New systems consist of ASIC or microprocessors with a complexity of thousands of transistors. These traditional bottom-up designs have to give way to new structural, hierarchical design methods. Without these new design practices it would be impossible to handle the new complexity.
Top-Down Design:
The desired design-style of all designers is the top-down design. A real top-down design allows early testing, easy change of different technologies, a structured system design and offers many other advantages. But it is very difficult to follow a pure top-down design. Due to this fact most designs are mix of both the methods, implementing some key elements of both design styles.
VHDL TERMS:
The terms, which are of reference and common usage in VHDL programming, are as follows:
Entity: a hardware abstraction of digital system is called an entity. All designs are expressed in entities.
Architecture: All entities that can be simulated have architecture description. The architecture describes the behavior of entity.
Configuration: a configuration is used to bind a component instance to an entity –architecture pair. A configuration is like parts list for a design.
Package: A package is a collection of commonly used data types and subprograms used in a design. Package is just like a tool box that contains tools used to build designs. 
Bus: The term bus usually to mind a group of signals.
Attribute: An attribute is data attached to VHDL objects or predefined data above VHDL objects. For example: - Maximum operating temperature.
Process: A process is a basic unit of execution in VHDL source code. All operations that are performed in a simulation of a VHDL description are broken into single or multiple processes.

Basic Structure of a VHDL file

A digital system in VHDL consists of a design entity that can contain other entities that are then considered components of the top-level entity. Each entity is modeled by an entity declaration and an architecture body. One can consider the entity declaration as the interface to the outside world that defines the input and output signals, while the architecture body contains the description of the entity and is composed of interconnected entities, processes and components, all operating concurrently, as schematically shown in Figure 2.1 below. In a typical design there will be many such entities connected together to perform the desired function.
VHDL uses reserved keywords that cannot be used as signal names or identifiers. Keywords and user-defined identifiers are case insensitive. Lines with comments start with two adjacent hyphens (--) and will be ignored by the compiler. VHDL also ignores line breaks and extra spaces. VHDL is a strongly typed language which implies that one has always to declare the type of every object that can have a value, such as signals, constants and variables.
Levels of abstraction
A digital system can be represented at different levels of abstraction. This keeps the description and design of complex systems manageable.
VHDL supports a design at many different levels of abstraction.
Three of them are very important
  • Behavioral level
  • Register – Transfer level
  • Gate level
Behavioral level:
This level describes a system by concurrent algorithms (Behavioral). Each algorithm itself is sequential, that means it consists of a set of instructions that are executed one after the other. Functions, Tasks and Always blocks are the main elements. There is no regard to the structural realization of the design.
Register-Transfer Level:
Designs using the Register-Transfer Level specify the characteristics of a circuit by operations and the transfer of data between the registers. An explicit clock is used. RTL design contains exact timing possibility; operations are scheduled to occur at certain times. Modern definition of a RTL code is "Any code that is synthesizable is called RTL code".
Gate Level:
Within the logic level the characteristics of a system are described by logical links and their timing properties. All signals are discrete signals. They can only have definite logical values (`0', `1', `X', `Z`). The usable operations are predefined logic primitives (AND, OR, NOT etc gates). Using gate level modeling might not be a good idea for any level of logic design. Gate level code is generated by tools like synthesis tools and this netlist is used for gate level simulation and for backend.

Keyword: HDL, VHDL