Thursday, September 23, 2010

Difference between DSP and FPGA

Life used to be easy. If you were working on a multiprocessor signal processing application, you would write down the requirements, check the specs of the devices on offer from the major DSP vendors, and just pick the chip that suited best.
Times have changed, and today's engineers are blessed with far more choice. The big FPGA vendors have stepped up their offerings for signal processing, and choosing the best solution can seem complex.
For distributed applications, the choice of interconnect technology can also obviously have a crucial effect on the overall solution. Crunching the data is all very well, but your system needs to have the right interfaces to move it around between the different processors, and off-load the results. What do the DSP and FPGA vendors have to offer in this area?
This article will look at what's available for multiprocessor systems (which inevitably tends to mean the high-performance end of the market), and how you can make the best choice between DSP, FPGA or a hybrid mixture of the two. We'll look fairly briefly at issues involved in the two types of chip, but concentrate more on system-level factors.
For high-performance signal processing applications, of course there are other options beyond DSPs and FPGAs. Massively parallel processors from vendors like picoChip are one alternative, but unfortunately often require the use of the vendor's proprietary toolset. ASICs and ASSPs are also well-suited to certain signal processing tasks, but their high up-front costs rule them out except in high volume applications.

DSPs evaluated

Pretty much since their invention in the 1980s, DSPs have provided excellent performance at reasonable power and cost levels. A large community of experienced DSP engineers has also grown alongside the technology, developing a substantial base of off-the-shelf field proven code to run on the DSP cores. There is also a well-established support from third party vendors for debug and optimization tools.
High performance DSPs continue to develop with faster clock speeds and multicore solutions. Very-long instruction word (VLIW) DSPs provide high clock rates and independent execution units to get the maximum speed.
DSP development cost is relatively low, and as a mature technology it can be argued that it has a lower risk and faster time-to-market than FPGAs and other signal processing technologies.
DSPs can be attractive for many applications, which are based on emerging standards, which often change frequently and rapidly. As DSP algorithms can be readily implemented in an accessible language such as C, it is easier to update the code to reflect changes in the standards as they occur. In addition, the complex nature of many of the signal processing algorithms in applications such as the latest wireless standards often make them more suitable to implement using a DSP: it is much easier for a DSP device to change the processing algorithm on-the-fly by calling a different software routine. While modern FPGAs can be reconfigured quickly, to achieve this dynamically while continuing to process data is a complex and challenging task.
DSPs are also improving their performance in the field of power. Led by the demands of the hand-held market, some next generation high-performance DSPs are incorporating power management techniques from their little brothers. This allows overall system power dissipation to be reduced during times of low traffic or to prevent over-temperature. A power and temperature-aware FPGA configuration could, of course, manage its clock domains in a similar way, but at the cost of greater development effort.
However, the DSP is not particularly well suited to parallel processing tasks: multiple devices can be required for tasks, which easily fit into a single FPGA. For example, in wireless baseband applications, for the processing of WiMAX OFDM Access (OFDMA) channels, a pure DSP solution cannot match an FPGA in the bandwidth and number of channels it can process. Consequently the DSP solution may have an unacceptable cost and power per channel.
To improve DSP performance in specific algorithms, vendors have introduced hardware cores to handle some processing traditionally off-loaded to FPGAs. For example TI's TCI6482 DSP includes Viterbi and turbo decoder co-processors for 3GPP and 3GPP2, while the multi-core TCI6487 DSP also includes a direct Common Public Radio Interface (CPRI) / Open Base Station Architecture Initiative (OBSAI) interface which can be chained between DSPs.
The FPGA alternative

FPGAs have one big advantage over DSPs: their efficiency in concurrent applications, achieved by using multiple parallel processing blocks. Coupled with their flexibility to allow the embedded systems designer to tailor the device to match their application's demands as closely as possible, FPGAs can achieve the highest possible throughput with low cost per channel.
The FPGAs' flexibility has traditionally come with an additional cost in power due to the increased gate count and silicon area of non-optimized solutions in comparison to hardwired architectures. However, 65nm technologies and the use of equivalent ASIC technology for volume manufacture mean that FPGAs can be low-power in the lab, and power-reduced further in volume.
The per-channel power of an FPGA may now be well be below that of DSPs, even though the chip-level power dissipation is higher. DSPs typically consume 3-4W and FPGAs 7-10W but FPGAs can handle 10x the channel density.
Acknowledging the advantages of DSPs has seen a shift in recent years to FPGAs incorporating DSP technology, for example Xilnx Virtex-5 SXT devices. This enables the FPGA to incorporate DSP algorithmic processing for tasks, which are not naturally parallel. Such "DSP-enabled" FPGAs have shown huge throughput advantages for certain types of signal processing, which has been reflected in their success in the high-end processing market. However, FPGAs are in general ill suited to processing sequential conditional data flow.

Programming FPGAs remains difficult, usually requiring a hardware-oriented language such as Verilog or VHDL. FPGA solutions can take an order of magnitude longer to code than DSP solutions which impacts development costs and increases time to market.
C-based synthesis tools have yet to deliver the ease of use and performance of C-coded processor solutions. High-level representations such as Simulink block diagram synthesis are not currently widely adopted and old FPGA synthesis methods still persist, especially where maximum performance is required.
Hybrid multi-processor systems

From a design engineer's point of view, this neck-and-neck technology development of FPGAs and DSPs is enabling them to find new and better solutions for signal processing applications. There is no simple answer as to whether FPGAs or DSPs are superior, and for many applications the best approach is a hybrid system, including both technologies to provide a solution that is superior to the sum of its parts.

Recent developments in FPGA technology redress many of the long-held preconceptions about their use, and have met many engineers' concerns about power, cost and complexity. Developing signal processing applications on FPGAs still requires significantly more effort than for DSPs, even with the high-level development tools and libraries available from FGPA vendors. Finding the right engineers with DSP and system-level experience to develop applications on FPGAs can also be tricky.
Independent benchmarks can be a valuable help of choosing the best device. For example, in 2007, BDTI published an analysis of FPGAs in DSP applications. The BDTI tests looked at cost/performance in a typical multi-channel communications application. The results are clear-cut, with the FPGA delivering a cost-per-channel figure of better than 20x compared to the DSP. This does not mean that FPGAs are necessarily best for high-performance signal processing applications, but certainly demonstrates they can have clear performance advantages over DSPs in some circumstances.
Another important factor is the IP cores and software libraries geared at particular target applications, which are often provided by vendors. These can alleviate some of the reliance on in-house development of complex algorithms using the vendor tools and further reduce time-to-market.
The key advantages of the DSP are reduced development time for new and complex algorithms, and flexibility to run many different algorithms. For the FPGA, its number one benefit is efficiency gains from parallel processing. In many applications, such as image processing and wireless baseband processing, there is a mixture of these repetitive, simple processing tasks that are best suited to an FPGA and more complex and less predictable tasks that are perhaps better handled with a DSP. Additionally, as parallel processing blocks implemented in FPGAs become mainstream, they are increasingly likely to be integrated into the DSP vendors' silicon.
Overall, this means that a hybrid system containing DSPs and FPGAs can often provide the best solution for high-performance multi-processing applications, allowing each device to play to its strengths. The key to this particular debate is to look at FPGAs and DSPs as complementary technologies, rather than competition for each other.

Wednesday, September 22, 2010

Cordic Algorithm

CORDIC ALGORITHM

COordinate Rotation DIgital Computer is an iterative algorithm for calculating trig functions including sine, cosine, magnitude and phase. It is particularly suited to hardware implementations because it does not require any multiplies.

What does it do

It calculates the trigonometric functions of sine, cosine, magnitude and phase (arctangent) to any desired precision. It can also calculate hyperbolic functions, but we don't cover that here.

Working

CORDIC revolves around the idea of "rotating" the phase of a complex number, by multiplying it by a succession of constant values. However, the multiplies can all be powers of 2, so in binary arithmetic they can be done using just shifts and adds; no actual multiplier is needed.

How does it compare to other approaches

Compared to other approaches, CORDIC is a clear winner when a hardware multiplier is unavailable, e.g. in a microcontroller, or when you want to save the gates required to implement one, e.g. in an FPGA. On the other hand, when a hardware multiplier is available, e.g. in a DSP microprocessor, table-lookup methods and good old-fashioned power series are generally faster than CORDIC.

Principles

Symbols used

Given a complex value:

C = Ic + jQc

we will create a rotated value:

C' = Ic' + jQc'

by multiplying by a rotation value:

R = Ir + jQr

The basic principles

  1. Recall that when you multiply a pair of complex numbers, their phases (angles) add and their magnitudes multiply. Similarly, when you multiply one complex number by the conjugate of the other, the phase of the conjugated one is subtracted (though the magnitudes still multiply).


  1. Therefore:

To add R's
phase to C:

C' = C·R

Ic' = Ic·Ir - Qc·Qr
Qc
' = Qc·Ir + Ic·Qr

To subtract R's
phase from C:

C' = C·R*

Ic' = Ic·Ir + Qc·Qr
Qc
' = Qc·Ir - Ic·Qr

  1. To rotate by +90 degrees, multiply by R = 0 + j1. Similarly, to rotate by -90 degrees, multiply by R = 0 - j1. If you go through the Algebra above, the net effect is:

To add 90 degrees,
multiply by R = 0 + j1:

Ic' = -Qc
Qc
' = Ic

(negate Q, then swap)

To subtract 90 degrees,
multiply by R = 0 - j1:

Ic' = Qc
Qc
' = -Ic

(negate I, then swap)

  1. To rotate by phases of less than 90 degrees, we will be multiplying by numbers of the form "R = 1 +/- jK". K will be decreasing powers of two, starting with 2^0 = 1.0. Therefore, K = 1.0, 0.5, 0.25, etc. (We use they symbol "L" to designate the power of two itself: 0, -1, -2, etc.)

    Since the phase of a complex number "I + jQ" is atan(Q/I), the phase of "1 + jK" is atan(K). Likewise, the phase of "1 - jK" = atan(-K) = -atan(K).

    To add phases we use "R = 1 + jK"; to subtract phases we use "R = 1 - jK". Since the real part of this, Ir, is equal to 1, we can simplify our table of equations to add and subtract phases for the special case of CORDIC multiplications to:

To add a phase,
multiply by R = 1 + jK:

Ic' = Ic - K·Qc = Ic - (2^-L)·Qc = Ic - (Qc >> L)
Qc' = Qc + K·Ic = Qc + (2^-L)·Ic = Qc + (Ic >> L)

To subtract a phase,
multiply by R = 1 - jK:

Ic' = Ic + K·Qc = Ic + (2^-L)·Qc = Ic + (Qc >> L)
Qc' = Qc - K·Ic = Qc - (2^-L)·Ic = Qc - (Ic >> L)

  1. Let's look at the phases and magnitudes of each of these multiplier values to get more of a feel for it. The table below lists values of L, starting with 0, and shows the corresponding values of K, phase, magnitude, and CORDIC Gain (described below):

L

K = 2^-L

R = 1 + jK

Phase of R
in degrees
= atan(K)

Magnitude of R

CORDIC Gain

0

1.0

1 + j1.0

45.00000

1.41421356

1.414213562

1

0.5

1 + j0.5

26.56505

1.11803399

1.581138830

2

0.25

1 + j0.25

14.03624

1.03077641

1.629800601

3

0.125

1 + j0.125

7.12502

1.00778222

1.642484066

4

0.0625

1 + j0.0625

3.57633

1.00195122

1.645688916

5

0.03125

1 + j0.031250

1.78991

1.00048816

1.646492279

6

0.015625

1 + j0.015625

0.89517

1.00012206

1.646693254

7

0.007813

1 + j0.007813

0.44761

1.00003052

1.646743507

...

...

...

...

...

...


  1. A few observations:
    • Since we're using powers of two for the K values, we can just shift and add our binary numbers. That's why the CORDIC algorithm doesn't need any multiplies!
    • You can see that starting with a phase of 45 degrees, the phase of each successive R multiplier is a little over half of the phase of the previous R. That's the key to understanding CORDIC: we will be doing a "binary search" on phase by adding or subtracting successively smaller phases to reach some target phase.
    • The sum of the phases in the table up to L = 3 exceeds 92 degrees, so we can rotate a complex number by +/- 90 degrees as long as we do four or more "R = 1 +/- jK" rotations. Put that together with the ability to rotate +/-90 degrees using "R = 0 +/- j1", and you can rotate a full +/-180 degrees.
    • Each rotation has a magnitude greater than 1.0. That isn't desirable, but it's the price we pay for using rotations of the form 1 + jK. The "CORDIC Gain" column in the table is simply a cumulative magnitude calculated by multiplying the current magnitude by the previous magnitude. Notice that it converges to about 1.647; however, the actual CORDIC Gain depends on how many iterations we do. (It doesn't depend on whether we add or subtract phases, because the magnitudes multiply either way.)

Applications

CORDIC used to calculate magnitude

We can calculate the magnitude of a complex number C = Ic + jQc if you can rotate it to have a phase of zero; then its new Qc value would be zero, so the magnitude would be given entirely by the new Ic value.

So to rotate it to zero:

We can determine whether or not the complex number "C" has a positive phase just by looking at the sign of the Qc value: positive Qc means positive phase. As the very first step, if the phase is positive, rotate it by -90 degrees; if it's negative, rotate it by +90 degrees. To rotate by +90 degrees, just negate Qc, then swap Ic and Qc; to rotate by -90 degrees, just negate Ic, then swap. The phase of C is now less than +/- 90 degrees, so the "1 +/- jK" rotations to follow can rotate it to zero.

1. Next, do a series of iterations with successively smaller values of K, starting with K=1 (45 degrees). For each iteration, simply look at the sign of Qc to decide whether to add or subtract phase; if Qc is negative, add a phase (by multiplying by "1 + jK"); if Qc is positive, subtract a phase (by multiplying by "1 - jK"). The accuracy of the result converges with each iteration: the more iterations you do, the more accurate it becomes.

[Editorial Aside: Since each phase is a little more than half the previous phase, this algorithm is slightly underdamped. It could be made slightly more accurate, on average, for a given number of iterations, by using "ideal" K values which would add/subtract phases of 45.0, 22.5, 11.25 degrees, etc. However, then the K values wouldn't be of the form 2^-L, they'd be 1.0, 0.414, 0.199, etc., and you couldn't multiply using just shift/add's (which would eliminate the major benefit of the algorithm). In practice, the difference in accuracy between the ideal K's and these binary K's is generally negligible; therefore, for a multiplier-less CORDIC, go ahead and use the binary Ks, and if you need more accuracy, just do more iterations.]

Now, having rotated our complex number to have a phase of zero, we end up with "C = Ic + j0". The magnitude of this complex value is just Ic, since Qc is zero. However, in the rotation process, C has been multiplied by a CORDIC Gain (cumulative magnitude) of about 1.647. Therefore, to get the true value of magnitude we must multiply by the reciprocal of 1.647, which is 0.607. (Remember, the exact CORDIC Gain is a function of the how many iterations you do.) Unfortunately, we can't do this gain-adjustment multiply using a simple shift/add; however, in many applications this factor can be compensated for in some other part of the system. Or, when relative magnitude is all that counts (e.g. AM demodulation), it can simply be neglected.

CORDIC used to calculate phase

To calculate phase, just rotate the complex number to have zero phase, as we did to calculate magnitude. Just a couple of details are different.

1. For each phase-addition/subtraction step, accumulate the actual number of degrees (or radians) you have rotated. The actuals will come from a table of "atan(K)" values like the "Phase of R" column in the table above. The phase of the complex input value is the negative of the accumulated rotation required to bring it to a phase of zero.

2. And we can skip compensating for the CORDIC Gain if we are interested only in phase.

Since magnitude and phase are both calculated by rotating to a phase of zero, can I calculate both simultaneously?

CORDIC used to calculate sine and cosine

Basically do the inverse of calculating magnitude/phase by adding/subtracting phases so as to "accumulate" a rotation equal to the given phase. Specifically:

1. Start with a unity-magnitude value of C = Ic + jQc. The exact value depends on the given phase. For angles greater than +90, start with C = 0 + j1 (that is, +90 degrees); for angles less than -90, start with C = 0 - j1 (that is, -90 degrees); for other angles, start with C = 1 + j0 (that is, zero degrees). Initialize an "accumulated rotation" variable to +90, -90, or 0 accordingly. (Of course, you also could do all this in terms of radians.)

2. Do a series of iterations. If the desired phase minus the accumulated rotation is less than zero, add the next angle in the table; otherwise, subtract the next angle. Do this using each value in the table.

3. The "cosine" output is in "Ic"; the "sine" output is in "Qc".

A couple of notes:

1. Again, the accuracy improves by about a factor of two with each iteration; use as many iterations as your application's accuracy requires.

2. This algorithm gives both cosine (Ic) and sine (Qc). Since CORDIC uses complex values to do its magic, it's not possible to calculate sine and cosine separately.

References

1. A survey of CORDIC algorithms for FPGAs by Ray Andraka of Andraka Consulting Group This very readable paper's review of CORDIC's principles is more comprehensive and rigorous than this FAQ, so it's a good place to go from here.

2. Wikipedia's CORDIC Page

3. Fixed-Point Trigonometry With CORDIC Iterations by Ken Turkowski

4. New Virtually Scaling-Free Adaptive CORDIC Rotator

Book references for CORDIC

1. M. E. Frerking , Digital Signal Processing in Communication Systems

2. Henry Briggs, Arithmetica Logarithmica, 1624.

Thursday, July 1, 2010

Using Arduino Interrupt

This is small information about Interrupts in Arduino.

The Arduino board has two interrupts.


Syntax:

attachInterrupt(interrupt, function, mode);

interrupt 0- Arduino digital pin 2

interrupt 1- Arduino digital pin3

in function give which function to call
in mode give HIGH or LOW on which the interrupt need to be activated


Cheers,
Balaji

 

Tuesday, June 29, 2010

How to create a custom page in Prestashop?

Log in your Prestashop and click tools at the top right.

 
 

In the next line click CMS there you can edit the static pages in your site.

How to create an user in MediaWiki?

Log in your MediaWiki and click Special Pages at the bottom left of the screen.

 
 

Then click Log in / create an account and create a new MediaWiki account.

Using Functions as Arrays

This is a C code for using functions as arrays.

We use array of function pointers. Here is sample code



  // array of functions
  #include

  // -- FUNCTION PROTOTYPES --
  void func1();
  void func2();
  void func3();
  void func4();
  void func5();
  // -- ENDS --

  void main()
  {
   // notice the prototype
   void (*ptr[5])();

   // arrays are made to point
   // at the respective functions
   ptr[0]=func1;
   ptr[1]=func2;
   ptr[2]=func3;
   ptr[3]=func4;
   ptr[4]=func5;

   // now the array elements
   // point to different functions
   // which are called just like
   // we access the elements of
   // an array
   for(int i=0;i<5;i++)
     (*ptr[i])();
  }

  // -- FUNCTIONS DEFINITION --
  void func1()
  {
   cout<<"Called Func1!\n";
  }

  void func2()
  {
   cout<<"Called Func2!\n";
  }

  void func3()
  {
   cout<<"Called Func3!\n";
  }

  void func4()
  {
   cout<<"Called Func4!\n";
  }

  void func5()
  {
   cout<<"Called Func5!\n";
  }
  // -- ENDS --

Monday, June 28, 2010

74HC595







IC PACKAGING :

FOOTPRINT:

Footprint refers to the physical layout that is required on the printed circuit board in order to mount a component or physical attachment.


SOCKET:

Socket is nothing but attachment the printed circuit board 


PACKAGING:


Final stage in semiconductor device fabrication or simply device assembly.


 

TYPES OF PACKAGES:

  • Surface mount package.
  • Through hole package.
  • Contactless Packages.        

                            

Surface Mount Package:

Surface mount package is the IC packaging technique, in which the compounds are mounted on the Printed Circuit Board(PCB).Devices mounted on this technique are called Surface Mounted Devices(SMD).Technique is called Surface Mount Technique(SMT).


TYPES OF SMT:

There are different types SMD packagings, but in this we are seeing only few. Based on the materials

  • Ceramic
  • Plastic
  • Metal


 


 


 

QFP (Quad Flat Package) is a type of SMT having leads on the four sides.


 


Many versions of QFP are there, in this LQFP and TQFP are very special.LQFP stands for low profile QFP with leads on four sides ,numbering can done from anti clockwise from the point on the IC with pin spacing range from 0.4mm to 0.8mm.TQFP stands for Thin Quad Flat Package same as that of the QFP,with thin body(1.0mm)and have a standard lead footprint(2.0mm).


 

                LQFP                            TQFP            

SOIC(Small-Outline Integrated Circuit) is type of surface mount package with space requirement and thickness less than DIP(Dual In-line Package).                                                                        


 



 

THROUGH HOLE PACKAGE:

Through Hole is mounting scheme for electronic component that involves the use leads in the component.It provide a stronge mechanical bond when compared to surface mount.


 


 



 

There are different kinds of through hole package. DIP(Dual In-line Package) is a through hole package in which circuits can be packed densely compared to round packages.

Amplifier circuit for microphone


This is the circuit diagram for mic amplifier










Saturday, June 26, 2010

INTREFACING SHIFT REGISTER WITH ARDUINO

This document gives some detail about how to interface shift register with Arduino, and connecting 7 segment display with it.

SCHEMATIC:


The schematic above shows shift register IC74HC595.It has 16pins. Vcc=5V.1 Micro Farad Capacitor is used. In this one shift register is used, we have to use at least two shift register and two 7 segment display.

                            
 


PINS 1-7, 15

Q0 " Q7

Output Pins

PIN 8

GND

Ground, Vss

PIN 9

Q7"

Serial Out

PIN 10

MR

Master Reclear, active low

PIN 11

SH_CP

Shift register clock pin

PIN 12

ST_CP

Storage register clock pin (latch pin)

PIN 13

OE

Output enable, active low

PIN 14

DS

Serial data input

PIN 16

Vcc

Positive supply voltage


 


 


 


 


 


 


 


 


 


 


The schematic above shows 7 segment display either common Anode or common Cathode (here it is common Anode).

Program:


 

//Pin connected to ST_CP of 74HC595


 

int latchPin = 8;


 

//Pin connected to SH_CP of 74HC595


 

int clockPin = 12;


 

////Pin connected to DS of 74HC595


 

int dataPin = 11;


 

//Initializing the output pins


 

int k=B11111111;


 

int a;


 


 

void setup()

{


 

//set pins to output so you can control the shift register


 

pinMode(latchPin, OUTPUT);


 


 

pinMode(clockPin, OUTPUT);


 


 

pinMode(dataPin, OUTPUT);


 


 

Serial.begin(9600);


 


 

}


 


 

void loop()


 

{


 

// setting the output pins to show 1


 

k=B11111010;

\

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 

// print the value


 

Serial.print(k);


 

// setting the output pins to show 2


 

k=B10100100;


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 

// shift out the bits: 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 

delay(1000);


 

// print the value


 

Serial.print(k);


 

// setting the output pins to show 3


 


 

k=B10110000;


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 

digitalWrite(latchPin, HIGH);


 

delay(1000);


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 4


 


 


 

k=B10011010;


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 


 

// print the value


 


 

Serial.print(k);


 


 


 

// setting the output pins to show 5


 


 

k=B10010001;


 


 

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 6


 

k=B10000001;


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 7


 

k=B11111000;


 

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 8


 

k=B10000000;


 

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 9


 

k=B10010000;


 

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 


 

// print the value


 


 

Serial.print(k);


 


 

// setting the output pins to show 0


 


 

k=B11000000;


 


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 


 

// shift out the bits:


 


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 


 

// print the value


 


 

Serial.print(k);


 


 


 


 


 

}


 


 


 


 


 

CONNECTING SHIFT REGISTER WITH ARDUINO:




 


 


 


 


 

If we want to use more than one shift register, we have to connect the Q7" (PIN 9) of the first shift register to the serial input pin (PIN 14) of the next shift register. If we want to connect more shift register the same (i.e. connecting the PIN 14 of the shift register with the PIN 9 of the previous shift register) procedure must be followed. connecting two shift register is shown below