Week 3: More Motor Control

As we didn’t get the switch working for the motor last week we had to continue that on, when we open the bag with circuit in it we noticed that some of the components fell out and we had to put it back together which only took a few minutes. After putting back together we tested it and seen if it was still working but it wasn’t, the part that wasn’t working was the voltage regulator which caused us some trouble last week. We’re not sure what happened but the middle was outputting 5.6V when it should’ve been 3.3V. So like last week we needed to solder longer legs onto the regulator, which took a few attempts because like last time we burned out a few regulators but eventually we had one soldered that still worked.

So after that we tried testing the simple motor circuit we had working before, and it worked so then we moved back to the switch controlled motor circuit. We redone the code thinking it would work but it still didn’t and we weren’t sure why. We called over one of the lecturers to check out the circuit and the code, he said the code looked fine and at a first glance the circuit looked right, so then we starting troubleshooting the circuit with a multi-meter checking if all the voltages were correct. All the voltages were correct other than the voltage on the motor was 4.7V on both sides making the motor not move, but when testing the voltages we noticed that the resistor across Vcc and the and the test pin was instead connected from Vcc to the reset pin so every cycle of the micro controller was resting the chip and making the chip not work the way we wanted. But after we fixed this the the switch worked properly by having the motor going forward when the switch was on and reverse when the switch was not on. The final code we had is shown below:

//
// Motor Switching code 
// Written by Ronan Byrne - 13-02-2015
//
  
#include <msp430.h>
  
int main( void )
{
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
      
    P1DIR = 0b00000001; // P1.0 is an output, P1.1-7 are inputs
    P2DIR = 0b00110011; // P2.0,1,4,5 outputs, P2.2,3,6,7 inputs
     
    P1OUT = 0b00000001; // LED on - set P1.0 high
    
    int sw = 0;
    
    while(1)
    {
        // Main loop repeats forever
        if(P1IN & BIT1)
        {
            // Every time the switch was pressed the motor would go in opposite direction
            sw = !sw;
            //delay to stop the micro controller switch constantly when switch pressed
            __delay_cycles(1000000);
        }
        if(sw == 0)
        {
            P2OUT = 0b00010001;
        }
        else
        {
            P2OUT = 0b00100010;
        }
        __delay_cycles(10000);
    }
    // The program never actually reaches this point
    return 0;
}

After we were done on the switch we moved onto the next task which was the colour sensor which we quickly put together but didn’t get a chance to test as it was the end of the class, so after that class we were happy that we got the switch motor working.

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