Motor example from today’s lecture

Please note the colour-coded wiring on my breadboard:

  • Black is 0V. Never use black for any wire that isn’t always 0V! This is the conventional meaning of black wires throughout the electrical engineering world.
  • Red is 6V. Red is always the positive supply voltage (6V from the battery pack in this case). This is the conventional meaning of red wires throughout the electrical engineering world.
  • Orange is 3.3V. This is just my own personal convention. It’s similar to red which reminds me that it’s a positive supply voltage, but also different enough from red that I don’t get them mixed up which could result in damage to the MSP430.

Remember, neat wiring with consistent colour-coding is the secret to fast fault finding in your circuit. It’s probably the single most important element to successful breadboard prototyping of circuits.

20161005_145740

20161005_145744

20161005_145754

20161005_154735

20161005_154741

20161005_154754

20161005_154802

20161005_154818

20161005_154838

20161005_154912

//
// Motor Control example for MSP430G2553
// Written by Ted Burke - Last modified 5-10-2016
//
  
#include <msp430.h>
  
void main()
{
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
      
    P1DIR = 0b00000000; // All port 1 pins are unused (set as inputs)
    P2DIR = 0b00011001; // P2.0 is LED, P2.3 and P2.4 are motor
    
    // Main loop repeats forever
    while(1)
    {
        // Decide what to do with motor and LED based on
        // the voltage on pin P2.5 (the switch input)
        if (P2IN & BIT5)
        {
            // If the boolean condition is true do this
            P2OUT = 0b00010001; // LED on, motor forward
        }
        else
        {
            // If the boolean condition is false do this
            P2OUT = 0b00001000; // LED on, motor reverse
        }
    }
}
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

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