Showing posts with label micro controllers. Show all posts
Showing posts with label micro controllers. 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

The intelligent wireless video camera

by Unknown  |  in wireless video camera at  03:38



The intelligent wireless video camera


The intelligent wireless video camera described in this paper is designed using wireless video monitoring system, for detecting the presence of a person who is inside the restricted zone.  This type of automatic wireless video monitors is quite suitable for the isolated restricted zones, where the tight security is required.

The principle of remote sensing is utilized in this, to detect the presence of any person who is very near to reference point with in the zone.

A video camera collects the images from the reference points and then converts into electronic signals.  The collected images are converted from visible light into invisible
electronic signals inside a solid-state imager.  These signals are transmitted to the monitor,

In this paper for the demonstration purpose three reference points are taken.  Each reference point is arranged with two infrared LED’s and one lamp.  This arrangement is made to detect the presence of a person who is near the reference point.   The reference point is nothing but restricted area, when any person comes near to any reference point, then immediately that particular reference point output will become high and this high signal is fed to the computer.   Now the computer energizes that particular reference point lamp and rotates the video camera towards that reference point for collecting the images at that particular reference point. To rotate the video camera towards interrupted reference point, stepper motor is used. 


 I MRUDULA, T.SIRISHA, IV/IV B.Tech, E.C.E.
N.I.E.T., KANTEPUDI (v), SATTENPALLI (m), GUNTUR (dt).


                    The present wireless video camera described in this is designed using wireless video monitoring system, for detecting the presence of a person who is inside the restricted zone.  This type of automatic wireless video monitors is quite suitable for the isolated restricted zones, where the tight security is required.
Once upon a time much importance is not given for the security system.   But as we see today lot of terrorism has grown up across the country and need has aroused to develop different types of security systems for various applications to safe guard the zones of various types like, military zones, railway yards, scrap yards, borders etc., this kind of automatic video monitoring systems can be installed at indo-pak borders, where the terrorists are crossing borders.   In fact our country is spending lot of its revenue to safe guard the borders.   By installing this type of security systems everywhere at critical points, lot of revenue can be saved by minimizing the manpower.
Basic operational principle:
          The video surveillance unit is designed for the widest possible viewing range and portability. The unit consists of a Stepper Motor, which drives the camera towards reference points automatically by the computer and a transmitter


transmits the images collected by the camera to a distant end. Thus a automatic controlled wireless camera is very useful for surveillance of places where the particular location makes it inconvenient or impractical for a wired operation of the unit. The robotic action made by the stepper motor is attached to the camera allows surveillance of maximum area with one single camera. Such setup can be very flexible to the user and can save valuable company resources. There are several types of security systems existed in the Market; one of the most common security systems is CCTV (Closed Circuit Television).   The CCTV consists Video Surveillance Camera used as security-monitoring device plays a major roll in security systems.  One reason for this is the fact that a picture is worth then a thousand words.   This is especially true in a court of law where an eyewitness is required who can place the criminal at the scene of a crime.

      CCTV systems are also helpful in the residential security Market.   They allow homeowners to see their callers, thus establishing their identity before they open an outside entrance door.   This is an important feature too, because other wise, they might open their door to a criminal.

The Infrared sensing circuit consists of two infrared LED’s for transmitting the signal as well as receiving the signal.  The signal transmitted by the transmitting LED omits the signal in a line like laser beam, the radiated signal from the transmitting LED is invisible and harmless.  Whenever the human body interrupts the transmitting signal, there the signal is reflected and this reflected signal is received by the infrared receiving LED. 

INFRARED TRANSMITTER / RECEIVER SECTION:

This section is designed for detecting the presence of a person who is inside the restricted zone within the range. It is basically an infrared proximity detection system. Here high efficiency IR-LED is driven by PNP Transistor SK100 with a modulating frequency of about 10KHz. This frequency is available from Pin 5 of LM 567 IC (versatile PLL tone decoder IC). The 47W resistor connected in series with the IR LED limits the IR-LED current.
The basic function of the detector circuit is by radiating energy into space through IR LED and detecting the echo signal reflected from an object. The reflected energy that is returned to the receiving LED indicates the presence of a person who is within the range. A portion of the transmitted energy is intercepted by the target and re-radiated in many directions. The radiation directed back towards the system is collected by the receiving LED causes to produce a high signal at Pin No.8 of LM567 IC. The output of the receiver is fed to the computer. Whenever the computer receives a high signal from the reference point, the computer drives the stepper motor through the driving transistors and rotates the motor towards that particular reference point. Three similar circuits are designed for the three different reference points.

          Diagram of the sensing circuit:
    
COMPUTER:



            The computer is playing a major role in this .The main function of the computer is to identify the interruption made by the person, where exactly the signal is interrupted, at which reference point identifying the point and displays the information on the screen.  The other major function of the computer is to drive the stepper motor.  This block is also responsible for identifying the reference point.  Here any normal configuration computer can be employed.   The software program defining the operations for the computer is written in ‘C’ language.
                     
    The output of the obstacle sensor is fed to the computer through the parallel port. The original purpose of Parallel port was to enable communication between a PC and a peripheral. Another use that has become very popular is transferring information or receiving the information. In this project work the received information from the detector circuit is used to drive the motor. Which is useful for the system for identifying the interrupted reference point. With the help of associated software written in ‘C’ language the received information can be displayed on computer screen.
           
 A computer is an electronic device, which processes information under the control of a set of instructions called program. It has the ability to accept the data, execute the program, and perform mathematical and logical operations on data. The result of the operations can be reported through output. Infact, a computer is a complete system in itself. The computer as a system is a combination of Hardware and Software components that jointly offer the necessary services to the user.

              The computer reads the data received through parallel port and can store the data; the same data will be displayed on computer screen. The program contains instruction about what has to be done with the data. The CPU executes the programs stored in the main memory by performing fetch instruction from memory and right data either to a memory location or on an output device. The main components of the CPU are, ALU (Arithmetic and Logic Unit), CU (Control Unit), and a set of registers. The control unit is responsible for the moment of data and instructions in and out of the memory and CPU. It is also responsible for the decoding of an instruction and determining as to what is desired by the same.   The complete electronic Hardware is interfaced with parallel port.

Stepper Motor Drive Circuit:

The stepper motor used in this is having four windings and these windings are energized one after another in a sequence according to the code produced by the computer through motor drive circuit.   This motor rotates in step wise and the step angle is 1.80.   Varying the pulse rate can vary the speed of the motor.   The pulses are produced by the computer can be controlled through the program by which motor speed can be varied. The stepper motor used in this project work is capable to drive up to 3kg load.
Each reference point is arranged with two infrared sensors and both the sensors are arranged side by side within the distance of one inch approximately and both are directed towards the space with the zone. The energization sequence for the forward and backward movements of the stepper motor is fed from computer with the help of software written in ‘C’ language.  The ratings of the motor employed are 12V dc 4-coil.   The driving circuit of the motor is designed using BC 547 (low power Transistor) and 2N5296 (Medium power Transistor).  These two transistors are configured in emitter following mode for amplifying the current rating.  The motor winding when it is energized, it consumes 350 mA approximately.
       

  The following is the diagram of the stepper motor drive circuit



TRANSMITTER:



                 The output of the video camera is fed to this transmitter, for transmitting the video signals in amplitude modulation. The video signal coming out of video camera is nothing but pure composite video signal and this signal is fed to this AM transmitter. The transmitter circuit generates a continuous frequency of 100MHz approximately, which is used to form a permanent link between the transmitter and receiver, and this is known as carrier frequency.  The output of video camera is fed to this carrier input as a modulating wave. This is a frequency modulated radio transmitter.   The radiating power of the transmitter is less than 20mw, so that the range between transmitter and receiver can be less than 25 feet.
The AM transmitter consists three sections namely
(1) VHF Oscillator
(2) Driver Stage or Modulator
(3) Final Amplifier Stage.
The output of the VHF oscillator is treated as carrier and the same is fed to the modulator section. The output of the VHF oscillator is fed to collector and the final output taken from the emitter of the PNP transistor of the modulator section. Since it is a PNP transistor there won’t be any phase reversal (180phase shift), because this transistor is configured in common base mode. Therefore finally at the output of this stage, a perfect AM wave can be obtained. In the amplifier section 2 N 3866-NPN Transistor is used to amplify the input signal.

The Complete Circuit Diagram of transmitter including three stages is as follows

 


The carrier is designed for transmitting the picture details.   At the receiving end, a small television set of 4” screen is used to display the picture caught. In this way using this wireless video camera we can detect the entry of unauthorized persons especially in case of military to detect our enemies crossing the border.






                            COMPLETE   CIRCUIT   DIAGRAM

Friday 16 May 2014

Programming of micro controllers 8051

by Unknown  |  in micro controllers at  00:42
Programming of micro controllers 8051
In this programing u can control four device by using only two input.circuit diagram is shown below.

#include <reg51.h>                           
 sbit izero=P0^0;
 sbit ione=P0^1;
 sbit itwo=P0^2;
 sbit ozero=P1^0;
 sbit oone=P1^1;
 sbit otwo=P1^2;
 sbit othree=P1^3;


 void main(void)
 {
      unsigned char a=0,b=0,c=0,d=0,e,f,g,h,sum;
    ozero=0;
    oone=0;
    otwo=0;
    othree=0;
    izero=0;
    ione=0;
    itwo=0;
    for( ; ; )
    {
       
        do
        {
            g=itwo;
        }while(g==0);
        e=izero;       
         f=ione;
        if(e==1)
        {
            sum=1;
        }
        else
        {
            sum=0;
        }
        if(f==1)
        {
            sum=sum+2;
        }
        else
        {
            sum=sum;
        }
        switch(sum)
        {
            case(0):
            {
                if(a%2==0)
                {
                    ozero=1;
                }
                else
                {
                    ozero=0;
                }
                a++;
                break;
            }
            case(1):
            {
                 if(b%2==0)
                {
                    oone=1;
                }
                else
                {
                    oone=0;
                }
                b++;
                break;
            }
            case(2):
            {
                if(c%2==0)
                {
                    otwo=1;
                }
                else
                {
                    otwo=0;
                }
                c++;
                break;
            }
            case(3):
            {
                 if(d%2==0)
                {
                    othree=1;
                }
                else
                {
                    othree=0;
                }
                d++;
                break;
            }
           
        }
        for(h=0;h<240;h++);
    }
}

Proudly Powered by Blogger.