Week 1: LED Challenge

This project is the first time any of us in the group have used the MSP430 micro controller and because of this it is a learning experience for all in using it, so starting off we just did a simple circuits to get a handle of the basics. The first circuit was just a simple LED that flashes on for 0.1s then off for 0.9s. The circuit we used is shown below. blink_circuit_schematic

After the circuit was set up we downloaded the sample code, compiled and transferred it over to the chip and straight away there was a problem, the computer couldn’t recognize the device but this was just because the RoboSlam folder wasn’t in the C folder, after it was moved the program was sent over and worked perfectly. From this code we learned some basic commands for the MSP430 and from this we had the base to start the LED Challenge.

The LED Challenge was to flash the letter R and our team number(54) on the LED using ASCII. This was a race so we tried to write the code as fast as possible, the circuit was kept the same. We had the code written in minutes and when we went to test the circuit using a sensor that tweeted the ASCII code if the circuit worked, which in our case it didn’t. This was because the timing of the micro controller was off and we need to adjust in the code. We first guessed at a few different delays which didn’t work and then we tried to time five cycles of the of the circuit and we timed twenty-seven seconds which should have been twenty so after a little maths we found a time which should’ve worked but didn’t. After a lot of trial and error we found out that the two second delay after each set of flashes shouldn’t have been changed proportionally to the rest and should be left at just two seconds. So by the time we figured this out the class was over for 30 minutes and we were the last to send the tweet but we did it because we were determined to finish. But from this we learned that we should always go the logical route first rather than guessing and hoping for the best. Below is the final code that worked for us.

//
// Blinking LED
// Written By Ronan Byrne - 23/01/2015
// 
#include <msp430.h>
 
int main( void )
{
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
     
    P1DIR = 0b00100001; // P1.0 is an output, P1.1-7 are inputs
    P2DIR = 0b00000000; // P2.0-7 are inputs
    
    
     
    // Main loop repeats forever
    while(1)
    {
        // This section flashes the letter R in ASCII
        
        // The "1" LED flashes on for one second
        P1OUT = 0b00000001;  
        // The "0" LED flashes on for one second
        __delay_cycles(76800); 
        P1OUT = 0b00100000;
        __delay_cycles(76800);
        P1OUT = 0b00000001;
        __delay_cycles(76800);
        P1OUT = 0b00010000;
        __delay_cycles(76800);
        P1OUT = 0b000100000;
        __delay_cycles(76800);
        P1OUT = 0b00000001;
        __delay_cycles(76800);
        P1OUT = 0b000100000;
        __delay_cycles(76800);
        P1OUT = 0b00000001;
        __delay_cycles(76800);
        P1OUT = 0b000100000;
        __delay_cycles(76800);
        P1OUT = 0b00100000;
        __delay_cycles(76800);
        
        //This section flashes 54 in ASCII
        P1OUT = 0b00000001;
        __delay_cycles(76800);
        P1OUT = 0b00100000;
        __delay_cycles(76800);
        P1OUT = 0b0000001;
        __delay_cycles(76800);
        P1OUT = 0b0000001;
        __delay_cycles(76800);
        P1OUT = 0b00100000;
        __delay_cycles(76800);
        P1OUT = 0b00000001;
        __delay_cycles(76800);
        P1OUT = 0b00000001;
        __delay_cycles(76800);
        P1OUT = 0b00100000;
        __delay_cycles(76800);
        P1OUT = 0b00100000;
        __delay_cycles(76800);
        P1OUT = 0b00100000;
        __delay_cycles(76800);
        P1OUT = 0b00100000;
        __delay_cycles(200000);
            
     }
    // The program never actually reaches this point
    return 0;
}

We did have the repeating delays added together, for example if there was a double 0 the delay would be 153600, as it would make the code shorter but another student told us theirs worked by doing this way so we tried it and it worked. And that was the end of that class.

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