Electronic – Msp430 Launchpad Using Motor to Control Motor

msp430

I can blink the led but the time of it's very 1 second or 2 second.I try to increase but it did not.But my question I'm using L293D motor driver to control motors.I want to Dc motors turn when button switched 15 second.This my code but I can't find a solution.I m asking how to increase the time

#include "io430.h"
void delay(unsigned long int d)
{
  d*=9999999999999999;
  for(;d>0;d--);
}
void main(void)
{

  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer

P1DIR = BIT6 + BIT4  + BIT7 + BIT0;          // Toggle P1.0 using exclusive-OR
P1DIR &= ~BIT3;
if((P1IN&BIT3) == 0){ 
P1OUT |= BIT6 + BIT4  + BIT7;
}
else
{
 P1OUT |= BIT0;
delay(9000);
}
}

Best Answer

My suggestion would be get rid of the delay function and use the built in if you are using IAR or CCS."__delay_cycles (cycles);" using the built ins, will give you more predicable results and better timing. You could probably just replace your delay for the built in, to get closer to the results you are looking for.

personally I would go about the whole thing using interrupts and timers to pull the whole thing off and use the peripherals that the msp430 has. I would suggest using the WDT as an interval timer, doing this would leave the other timer for your motor control. p1.3 is used as the wake up pin and p1.0 is the led pin.

example code

volatile int counter;
void main(void) {
    WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
    P1DIR = 0x01;                             // P1.0 output, else input
    P1OUT =  BIT3;                            // P1.3 set, else reset
    P1REN |= BIT3;                            // P1.3 pullup
    P1IE |= BIT3;                             // P1.3 interrupt enabled
    P1IES |= BIT3;                            // P1.3 Hi/lo edge
    P1IFG &= ~BIT3;                           // P1.3 IFG cleared
    _BIS_SR(GIE);
}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
    WDTCTL = WDT_MDLY_64; //enables intervals of 64mS
    IE1 |= WDTIE;  // set WDT interrupt
}
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer (void)
{
    ++counter;
    P1OUT |= BIT0;
    if (counter == 245) {  //245 x 64mS = 15.6 seconds
        P1OUT &= ~BIT0;
        WDTCTL = WDTPW + WDTHOLD; 
    }
}

Not complete nor has this code been tested, but it should turn the led on for 15 seconds every time the P1.3 button is pushed.