Blinking onboard LEDs randomly in TI Launchpad using linear feedback shift registers

Till now i blinked the onboards LEDs in a predefined order…like on for sometime and then off and so on….

But now tried to blink them randomly and it blinked…:)

For this all i had to do was to use the last two bits of a linear feedback shift register(LFSR) to control the LEDs…

And there are two LFSRs-Fibonacci LFSR and Galois LFSR…More details on these can be obtained from  http://en.wikipedia.org/wiki/Linear_feedback_shift_register

The program using Fibonacci LFSR is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<msp430.h>
unsigned int op,grn,red,lfsr = 0xACE1;
unsigned bit;
main()
{
        for(;;)
        {
                P1DIR=0x41;
                do{
                        bit=((lfsr>>0)^(lfsr>>2)^(lfsr>>3)^(lfsr>>5))&1;
                        lfsr=(lfsr>>1)|(bit<<15);
                        grn=lfsr&0x0001;
                        red=lfsr&0x0002;
                        red=red>>1;
                        grn=grn<<6;
                        op=grn|red;
                        P1OUT=op;
                        for(int i=100000;i!=0;i–);
                }while(lfsr!=0xACE1);
        }
}

I got the code implement the LFSR fom the page that i mensioned above….all i had to do is that to do the bit manipulations to get the desired output….

Also I wrote a program to do the same using Galois LFSR….

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<msp430.h>
unsigned red,grn,op,lfsr=0xACE1;
main()
{
        P1DIR=0x41;
        do{
                unsigned lsb=lfsr&1;
                lfsr>>=1;
                if(lsb==1)
                        lfsr^=0xB400;
                red=lfsr&0x0001;
                grn=lfsr&0x0002;
                op=red|(grn<<5);
                P1OUT=op;
                for(int i=100000;i!=0;i–);
        }while(lfsr!=0xAEC1);
}

This video includes the output of both the programs…:)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s