Thursday 30 June 2011

8085 uP Instruction Set - Arithmetic Instructions

8085-MICRO PROCESSOR INSTRUCTION SETS
    8085 Micro Processor is 8 bit micro processor which has some instruction sets to perform its operation. The 8085 Instruction Set comprises of five instruction sets in this micro processor.
They are,
  
       Arithmetic instructions, Logical instructions, Data transfer instructions, Branch instructions and I/O , stack, machine control group.


We also divide the Instruction Set into four parts namely
ARITHMETIC INSTRUCTIONS
      Arithmetic instructions include some mathematical operations such as addition subtraction increment and decrement. For addition and subtraction the quantity is always stored in accumulator. Accumulator is a register which can hold 8 bit data where the arithmetic and logic values can be stored in it.


CONVENTIONS
   A - represents the accumulator.
   B,C,D,E,F,H,L - represents the general purpose registers.
   [A] - represents the contents of the registers A.
  Similarly , [B] represents the contents of register B . i.e the square brackets represents the contents of the particular register.
   [M] - represents the contents of memory location specified by the address M = xxxx ( 16 bit address ).
 Double square brackets  :  e.g: [[B]]
             If [4200] = 12 , [B] = 4200 , then [[B]] = [4200] =12.


INSTRUCTIONS
        1.  ADD r:
          ADD r means that the register content is added to the accumulator.
       Example: [B] = [1 1] , [A] = [D D]
       [A] + [B] = [A]
             So, [A] = [E E]
          Ie. = represents that arithmetic quantity is stored in accumulator.
      
       2.  ADD m:
         It means that the memory content is added to the accumulator.
             Example: [A] = 32,   [H]= 42,  [L] =01, [4201]=3F
             [A] + [HL] = [A]
             [A] = [71 ]
         Ie. = represents that arithmetic quantity is stored in accumulator.

 3. ADI 8 BIT:
         It means that the 8 bit immediate data is added to the contents of accumulator.
            Example: [A] = [1]
            For ADI 8F:
                 [A] = 90
           Ie. = represents that arithmetic quantity is stored in accumulator.

 4.SUB R:
           It means that the contents of register are subtracted from the contents of accumulator.
              Example: Sub B , [B] = [11] , [A] = [CC]
              [A] - [B] = [A]
              [A] = [BB]
           Ie. = represents that arithmetic quantity is stored in accumulator.

  5. SUB M:
           It means that the contents of memory location are subtracted from the contents of accumulator.
              Example: [A] = [32], [H] = 42, [L]=01, [4201]  = 22
              4201 is the memory address
              22 is the data which is stored in memory
              [A] = [A] – [HL]
              [A] = [10]
          Ie. = represents that arithmetic quantity is stored in accumulator.

 6. SBI:
          It means that the 8 bit data is subtracted from the contents of accumulator.
            Example: [A] = [FF]
            For SBI 22
            [A] = [A] – [22]
            [A]=DD
         Ie. = represents that arithmetic quantity is stored in accumulator.

 7. INR R:
         It means that the content of register is increased by value 1.
           Example: [B] = 01
           [B] = [B] + 1
           [B] = 02
         Ie. = represents that arithmetic quantity is stored in accumulator.

 8. DCR M:
         It means that the content of register is decreased by value 1.
           Example: [B] = FF
           [B] = [B] – 1
           [B] = FE
         Ie. = represents that arithmetic quantity is stored in accumulator.

 9. INR M:
         It means that the data which is present in the memory is increased by a value 1.
           Example: [H] = 45, [L]= 01, [4501] = 32
           HL 4501 is the memory address.
           32 is the data which is stored in the memory.
           [H] = 45, [L] = 01, [4501] = 33

10. DCR M:
         It means that the data which is present in the memory is decreased by a value 1.
           Example: [H] = 45, [L]=01,  [4501] = 32
           HL 4501 is the memory address.
           32 is the data which is stored in the memory.
           [H] = 45 , [L] = 01  [4501] = 31

11. INX Rp:
         It means that the content of register pair is increased by 1.
           Example B 50/23 C
           B 50/24 C

12. DCX Rp:
        It means that the content of register pair is decreased by 1.
           Example B 32/FE C
           B 32/FD C
           
The next post will be shortly…

Wednesday 29 June 2011

Numerical Methods Using MATLAB - Newton-Raphson Method


In this post, we learn about solving Algebraic Equation using Newton's Method (or) Newton-Raphson Method.

Newton's Method:
Given an approximate root of an equation, a closer approximation to the root can be found using Newton's Method.

Let a0 be the approximate root of the equation f(x)=0.
Let a be the exact root nearer to a0.

Then, a = a0 + h
where h is an integer with very small value.

Since a is the exact root of f(x)=0,

f(a) = f(a0+h) = 0

By Taylor's expression,
f(a) = f(a0+h) = f(a0) + hf'(a0) + (h^2/2!)f"(a0)+0000=0

Since, h is small, neglecting higher powers h^2, h^3,....etc, we get

f(a0) + hf'(a0) = 0

h = -(f(a0)/f'(a0))

a1 = a0 + h = a0 - (f(a0)/f'(a0))

a2 = a1 + h = a1 - (f(a1)/f'(a1))

Thus, we again get a sequence of approximate roots which converges to form the exact root on a few iterations depending on the required precision.

Source Code:

% this function that calculates solution of algebraic equation
% using Newton-Raphson method

function NewtonFunc(co,range)
  
% the variable prev stores the first approximate root of the eqn.
% here, we assume it to be the mean of the two points p1 and p2 (say)
% such that, f(p1)<0 and f(p2)>0

prev = (range(1) + range(2))/2;

% x is symbol var represented by 'x'
x=sym('x');

% the function 'f' is initialized
f=0;

% n gives the size of the coeff/: vector
[m,n]=size(co);

  % in the loop below, we create the function 'f' using symbol 'x'
% from the coeff/: vector
for i = 1 : n
     % the last element of co vector is the constant
         if i == n
          f = f + co(i);
                end
                % end of if i==n
 
        % adding the terms of the function step by step    
        if co(i) ~= 0  && i ~= n
                  f = f + co(i)*(x^(n-i));
               end
              % end of if
    end
%end of for

% infinite while loop
% where we find the sequence of approximate roots
while ( 1 )
 
% finding the approximate root 
% using Taylor's expansion (neglecting higher powers)
x0=prev-(subs(f,prev)/subs(diff(f),prev));
         
% when the required precision is obtained, break the loop    
if abs( abs(prev) - abs(x0) ) < 0.000001
       break;
end
% end of if
 
% assigning previous value    
prev=x0;
    end
% end of while
disp(x0);
end
% end of function

Numerical Methods Using MATLAB - Method of False Position

In this post, we solve Algebraic Equations using Regular Falsi Method, also known as Method of False Position. 


Regula Falsi Method:
         Consider the equation f(x)=0. Let a and b be two points such that f(a)<0 and f(b)>0. The function f(x) cuts x-axis at some point between (a,f(a)) and (b,f(b)).  The equation of chord joining the two points is given by,


(y-f(a))/(x-a))=(f(a)-f(b))/(a-b)


         The point where the chord cuts the x-axis gives an approximate value root of f(x)=0. Hence, we substitute y=0 in the above equation to get an expression for x, as follows:

x1=(af(b)-bf(a))/(f(b)-f(a))

          This value of x1 gives an approximate value of root of the equation f(x)=0. Substitute x1 in f(x) and find f(x1).

IF f(x1) > 0
x1=b
ELSE
x1=a


Now,
         x2=(af(x1)-x1f(a))/(f(x1)=f(a))
        Thus, we get a sequence of roots x1,x2,..... The sequence converge to required root with required accuracy.

Source Code :
% Function that calculates approximate solution using Regula Falsi (or) False Position Method
function    RegFalsiFunc(co,deg,rang)
     % x=a --> f(x)<0
     % x=b --> f(x)>0
     a = rang(1);
     b = rang(2);

     % initialize previous var to 0
     prev=0;

     % infinite loop
     while ( 1 )
            % find fa,fb,fx1 substituting a,b in f(x)
            fa = SubFunc(deg,co,a);
            fb = SubFunc(deg,co,b);
  
             % find x1 from fa,fb,a,b
             x1 = ((a*fb)-(b*fa))/(fb-fa);


            % find fx1 substituting x1 in f(x)
            fx1 = SubFunc(deg,co,x1);
   
            % if fx1 is negative replace a with x1
            if (fa*fx1)>0      a=x1;
            % else replace b with x1
            else    b=x1;
            end    
            % end of if....else
   
            % end the loop when required accuracy is achieved
            if abs(abs(x1)-abs(prev)) < 0.000001
                        break;
            end
            % end of if
            prev = x1;
      end
      % end of while
      disp(x1);
 end
% end of function

Monday 27 June 2011

Numerical Methods using MATLAB - Iterative Method



In this post, we solve Algebraic Equations by Iterative Method,  which is also famously known as Successive Approximation Technique.

What is an Iterative Method?


Iterative Method:


Consider the equation f(x)=0. We need to find the roots (approximate) of the equation.

Let x=g(x)-------------------------(1)

Firstly, assume an approximate root x0. The more accurate x0 is, the less the number of iterations for finding the exact root. We substitute x0 in (1) and get a new root x1. This process goes on and on, until we get a solution that matches the expected accuracy. We get a sequence of approximate roots. The convergence of the sequence  depends on the value of x0 chosen initially. There are some conditions for the convergence of the method, which are not discussed here.

Where do we get the Source Code?

    Right here!!!!!!!!!!!!!!

Source Code:

function iterateFunc(co,prev)

   %Now 'co' is the vector under scrutiny
   %'co' represents the coefficient vector

   [a,b]=size(co);
   % 'b' gives us the exact size of vector


   % we iterate backward here
   for i=b-1:-1:1

        %we find the position corresponding to minimum degree
        if co(i)~=0
            min=i;
            break;
       end  
  end

 % Beginning of truncation


  % We truncate the constant and the terms with zero coeff:/
  % near the constant

  tco=co(1:min);

  % Minimum degree to be taken as common is given by '(b-min)'
  % b1 gives the size of truncated vector 'tco'
  [a1,b1]=size(tco);

  % infinite while loop
  while 1
 
      % Function return the value of polynomial after sub. of  an user defined constant 'prev'
      ans1=SubFunc(b1-1,tco,prev);

      % Here find the entire right hand side
     % and rise it to the power (reciprocal of min degree)
      curr=((-co(b))/ans1)^(1/(b-min));

      % when required accuracy of solution is met 
      % loop breaks
      if abs(abs(prev)-abs(curr)) < 0.0000001
          break;
     end
 
      % transfer from current to prev
      prev=curr;

  end

  disp(curr);

end


Sunday 26 June 2011

Arduino - Beginner

     Arduino is a prototyping platform(AVR uC with some generic circuitry) with its own Software Development IDE(Arduino). Arduio-Hardware is nothing but a AVR uC with some sophisticated Bootloader program residing in it. This Bootloader  facilitates the communicaton between Arduino IDE and the Arduino Hardware.

      Arduino-Hardware
Arduino Duemilanove
           Arduino Hardware is very simple. It contains Atmega168/328 as its CPU. Atmega168/328 uC's cannot be interfaced with USB  directly. The  FT232 IC is used for emulating a COM port. This makes the USB communication easier.

           The figure on the right is the Schematic for Arduino Duemilanove.

     Arduino IDE
            Arduio IDE is based on Processing, a very high level language developed for interactive art. It has several libraries for SPI Communications, Motor control, EEPROM memory access, LCD Display ,etc. Unlike other programming language, programming in Arduino is little bit easier. The code has two compulsory function blocks namely setup() , loop().
        
     Through Up-Coming articles,we'll learn how to construct Arduino from scratch.

Numerical Methods using MATLAB - Bisection Method


Why do we need numerical methods?

          In Engineering, there are several different processes involved in a system under study. These processes are represented mathematically by their mathematical models. The models can be algebraic, trignometric, ordinary or partial differential equations. So, in order to study the static and dynamic behaviour of the system, we need to analyse the math models of the particular system. The analysis of these models is known as Numerical Analysis.

Basic Tools for Numerical Analysis:

1. System of Linear Algebraic Equations
2. Eigen value problems
3. Roots of Nonlinear Equations
4. Polynomial Approximation and Interpolation
5. Numerical differentiation and Interpolation

Above are few numerical techniques involved to solve several engineering problems. They are all based on certain assumptions and approximations.

Why do Engineers need to practise programming?

         Engineers are expected to solve problems in real time using the numerical techniques listed above. They just need to assemble existing pieces of code to form a solution to a practical problem. These existing pieces of code is usually a function that does a particular task.

What is MATLAB?


MATLAB  is a high-level language for scientific computing and data visualization built around an interactive programming environment. It is becoming the premiere platform for scientific computing at educational institutions and research establishments.










Why use MATLAB?

        MATLAB is an interactive system whereprograms can be tested and debugged quickly. There is no need for compiling, linking and execution each and every time of testing. Hence, programs can be developed in a shorter time in MATLAB. It contains a large number of basic functions and some numerical libraries like LINPACK etc,. There is no need of declaring variables as int or float since all the numerical entities are treated as arrays.

Where do we start?

        As Step1, we now learn to solve Algebraic Equations numerically. There are quite a few methods for solving them. Most are based on formula and approximation. We here use BISECTION Method to solve Algebraic Equations.

BISECTION METHOD:




Let us consider a polynomial f(x) of degree 'n', then,
f(x)=0 is an algebraic equation, whose solution is assumed to lie between the range (a,b) and is continuous within that range.

 If f(a) and f(b) are of opposite signs, then a real root should exist between points a and b. Let f(a)>0 and f(b)<0.

As a first approximation, we assume the root of the equation to x0=(a+b)/2. If f(x0)<0, the root lies between a and x0 and so we consider new limits as a and x0 and the process goes on.

If f(x0)>0, the root lies between x0 and b and hence we consider limits as x0 and b and the process goes on.

This way, we form a sequence of approximate roots x0, x1,...

Depending of precision required, the number of iterations can be set.

How to write a program for it?

Simple Algorithm: (Solving Algebraic Equation BISECTION method)

I INPUTS:
degree
coefficients
precision

II SETUP:
Range

III LOOP:

WHILE actualAccuracy > precision
Var1  ->  mean(range)
Var2 = FUNCTION value(degree,coefficients,Var1)

IF Var2>0
Range(2) = Var1;

ELSE
Range(1) = Var1;

IV END OF LOOP:

Where do I find the source code?

   SOURCE CODE:

           * BISECTION METHOD
           * SUBSTITUTION METHOD

Coming up next:

      Method of False Position

Tuesday 21 June 2011

SIRC Part I

BASICS
  
Wireless infrared communications refers to the use of free-space propagation of light waves in the near infrared band as a transmission medium for communication. Signals sent are encoded using a an encoding algorithm in the transmitter circuitry and is decoded and the essential information is obtained at the receiver part. IR communication is a basic form of wireless communication. It's frequency range is 32-60 KHz. There are several protocols for IR communication. Some are Sony's SIRC, Phillips RC5 protocols.

 SIRC (Sony Infra Red Communication Protocol), is an IR communication protocol for controlling SONY equipment. It consists of three versions based on bit length (12, 15, 20 bit). For convenience, we here discuss about 12 bit version of SIRC. Here Pulse Width Modulation (PWM) is made use of.

  The 13 bits are divided into 12 data bits and 1 start bit. The start bit indicates the start of the information and the following 12 bits indicate the information itself. The data bits are further classified into address and command. The seven bits followed by the start bit represent the command (from LSB to MSB) (ie) in reversed manner. The following 5 bits represent the address in reversed manner. 


What is a command and address?

Command:
    It is more of a self defining term. It consists of a digital word that will server as a command to the receiving system. The following table gives the commands and their digital values in a Sony IR remote.


Command
Function
0
Digit key 1
1
Digit key 2
2
Digit key 3
3
Digit key 4
4
Digit key 5
5
Digit key 6
6
Digit key 7
7
Digit key 8
8
Digit key 9
9
Digit key 0
16
Channel +
17
Channel -
18
Volume +
19
Volume -
20
Mute
21
Power
22
Reset
23
Audio Mode
24
Contrast +
25
Contrast -
26
Colour +
27
Colour -
30
Brightness +
31
Brightness -
38
Balance Left
39
Balance Right
47
Standby



Address:
   It is a digital word that represents the address of the receiving system. Sony has unique address for its products. The following table gives the digital address for various Sony equipment.


AddressDevice
1TV
2VCR 1
3VCR 2
6Laser Disc Unit
12Surround Sound
16Cassette deck / Tuner
17CD Player
18Equalizer


How does a signal to be transmitted look like?

   The following figure gives a rough idea about how the signal looks like:


  The data bits to be transmitted consist of marks and spaces. The marks are the high regions in terms of voltage while spaces are the low regions. Digital high (1) is represented by a mark of 1.2 ms (milli seconds) and digital low (0) is represented by a mark of 0.6 ms ( PWM). The time period of a start bit is 2.4 ms. A space is always represented by 0.6 ms low with respect to voltage.


What is PWM?

       PWM (pulse width modulation) is an encoding process where variation of width of each pulse is used to show the variation in the actual data.


Basic materials for transmission:
      We use an IR LED to transmit PWM signal and an IR receiver to receive the transmitted signal. The receiver always inverts the signal after which the decoding process is done.


 Coming Up :

    * More parameters

    * A platform to move on

    * Encoding and Decoding codes

    * Practical model

    * Building a project ( An Universal Remote)

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More