This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F447: msp430f447

Part Number: MSP430F447

hi

i have used port pin to enable the motor and using through beam ir sensor i am stoping the motor 

problem is in the below code first time its working properly second time the motor stops its not coming out of the while 

the code is 

#include "io430.h" // Header for msp430f447 evaluation board
#include <stdio.h> // Header for C function

static int counter1=0;
static int counter2=0;
void Delay (int j); //Delay function
void Delay1 (int k); //Delay function
void Delay2 (int k); //Delay function
void Reset_all(); //Reset all
void Timer_on(); //Timer on function
int filling_done = 0;
int indexing_done = 0;
int rest_time=0;
static int nrv_operating = 0;
void main( ) //Main function
{



WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
Reset_all();
P1DIR |=0x7F ; // P1.0,P1.1 all output
P1OUT &=0x00 ; // Clear P1.0,P1.1
/*----------------Timer module---------------*/
CCR0 = 32768;
TACTL = TASSEL_1 + MC_2 +ID_0+TACLR; // ACLK, contmode,timerclear

P1OUT |= 0x08; //P1.3=1 NRV motor rotates
while(((P2IN & BIT0) == BIT0)||((P3IN & BIT7) != BIT7)); //wait P3.7==0;
P1OUT &= 0x00; // P1.0 = 0,P1.1=0,P1.2=0,P1.3=0
while(1)
{

if((P6IN & BIT6) != BIT6) //open/close button
{
while(1)
{
/* if(rest_time==1)
{ // rest initiated
Delay2(200);
}*/
// process starts
for( int operation_count=0;operation_count<200;++operation_count)
{
if(operation_count % 2 == 0 && operation_count != 0)
Delay2(100);
if(operation_count > 0)
Delay1(60);
// /*---------------------------------indexing--------------------------------*/
P1OUT |= 0x01; //P1.1=1 NRV motor rotates
Delay(7);
while((P2IN & BIT7) != BIT7);
P1OUT &= 0x00; // P1.0 = 0,P1.1=0,P1.2=0,P1.3=0


/*---------------------------nrv operation---------------------------------*/
nrv_operating = 1;
P1OUT = 0x08; //P1.3=1 NRV motor rotates
// while(((P2IN & BIT0) != BIT0)||((P3IN & BIT7) == BIT7)); //wait till P3.7==1;
Delay1(4);
while((P3IN & BIT7) == BIT7);

Delay(4);
P1OUT &= 0x00; // P1.0 = 0,P1.1=0,P1.2=0,P1.3=0
Timer_on();
while(filling_done == 0);
filling_done = 0;
TACTL = MC_0;
CCR0 = 32768;
TACTL = TASSEL_1 + MC_2 +ID_0+TACLR; // ACLK, contmode,timerclear */

} // set of cycles completed
/* filling_done = 0;
CCR0 = 32768;
TACTL = TASSEL_1 + MC_2 +ID_0+TACLR; // ACLK, contmode,timerclear*/
// reinitialize syztem
filling_done = 0;
indexing_done = 0;
P1DIR |=0x7F ; // P1.0,P1.1 all output
P1OUT &=0x00 ; // Clear P1.0,P1.1
CCR0 = 32768;
TACTL = TASSEL_1 + MC_2 +ID_0+TACLR; // ACLK, contmode,timerclear
// initiate resting variable and continue
rest_time=1;
}

}
}
}//End of Main

void Delay(int j)
{
int i;
for(j=0;j<1;j++)
for(i=0;i<0xFFFF;i++);
}
void Delay1(int j)
{
int i;
for(j=0;j<10;j++)
for(i=0;i<0xFFFF;i++);
}
// very long delay
void Delay2(int j)
{
int i,m;
for(m=0;m<j;m++)
for(i=0;i<0xFFFF;i++);
}
void Timer_on() //Timer on function
{
CCTL0 = CCIE;
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}

#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
//one second counter variable
CCR0 += 32768;
if(++counter1>=10) //10 sec for nrv
{
if (nrv_operating == 1)
{
P1OUT |= 0x08; //P1.3=1 NRV motor rotates
while(((P2IN & BIT0) == BIT0)||((P3IN & BIT7) != BIT7)); //wait P3.7==0;
P1OUT &= 0x00; // P1.0 = 0,P1.1=0,P1.2=0,P1.3=0
counter1=0;
filling_done = 1;
nrv_operating = 0;
}
}
/*if(++counter2>=5) //5 sec for indexing
{
P1OUT &= 0x00; // P1.0 = 0,P1.1=0,P1.2=0,P1.3=0
counter2=0;
indexing_done = 1;
}*/
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}

/*--------------------------------------Reset--------------------------------------------------*/

void Reset_all()
{
P1OUT=0x00;
P2OUT=0x00;
P3OUT=0x00;
P4OUT=0x00;
P5OUT=0x00;
P6OUT=0x00;
}

second time its not working 

  • Once you pass if((P6IN & BIT6) != BIT6) then you never leave due to the embedded while(1) loop. This while(1) should be removed such that you just loop through main. If this is not your issue then you will need to provide a lot more information and debugging efforts to help isolate the issue.

    Regards,
    Ryan
  • hi brown thanks for the reply

    #include "io430.h" // Header for msp430f447 evaluation board
    #include <stdio.h> // Header for C function

    static int counter1=0;
    static int counter2=0;
    void Delay (int j); //Delay function
    void Delay1 (int k); //Delay function
    void Delay2 (int k); //Delay function
    void Reset_all(); //Reset all
    void Timer_on(); //Timer on function
    int filling_done = 0;
    int indexing_done = 0;
    int rest_time=0;
    static int nrv_operating = 0;
    void main( ) //Main function
    {



    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    Reset_all();
    P1DIR |=0x7F ; // P1.0,P1.1 all output
    P1OUT &=0x00 ; // Clear P1.0,P1.1
    /*----------------Timer module---------------*/
    CCR0 = 32768;
    TACTL = TASSEL_1 + MC_2 +ID_0+TACLR; // ACLK, contmode,timerclear

    P1OUT |= 0x08; //P1.3=1 NRV motor rotates
    while(((P2IN & BIT0) == BIT0)||((P3IN & BIT7) != BIT7)); //wait P3.7==0;
    P1OUT &= 0x00; // P1.0 = 0,P1.1=0,P1.2=0,P1.3=0





    // infinite loop is required but the problem is first time its getting executed and for second time its stop // at this line "while((P3IN & BIT7) == BIT7);"


    while(1)
    {
    if((P6IN & BIT6) != BIT6) //open/close button
    {
    while(1)
    {

    // process starts
    for( int operation_count=0;operation_count<200;++operation_count)
    {
    if(operation_count % 2 == 0 && operation_count != 0)
    Delay2(100);
    if(operation_count > 0)
    Delay1(60);
    // /*---------------------------------indexing--------------------------------*/
    P1OUT |= 0x01; //P1.1=1 NRV motor rotates
    Delay(7);
    while((P2IN & BIT7) != BIT7);
    P1OUT &= 0x00; // P1.0 = 0,P1.1=0,P1.2=0,P1.3=0


    /*---------------------------nrv operation---------------------------------*/
    nrv_operating = 1;
    P1OUT = 0x08; //P1.3=1 NRV motor rotates


    while((P3IN & BIT7) == BIT7);

    Delay(4);
    P1OUT &= 0x00; // P1.0 = 0,P1.1=0,P1.2=0,P1.3=0
    Timer_on();
    while(filling_done == 0);
    filling_done = 0;
    TACTL = MC_0;
    CCR0 = 32768;
    TACTL = TASSEL_1 + MC_2 +ID_0+TACLR; // ACLK, contmode,timerclear */

    } // set of cycles completed

    // reinitialize syztem
    filling_done = 0;
    indexing_done = 0;
    P1DIR |=0x7F ; // P1.0,P1.1 all output
    P1OUT &=0x00 ; // Clear P1.0,P1.1
    CCR0 = 32768;
    TACTL = TASSEL_1 + MC_2 +ID_0+TACLR; // ACLK, contmode,timerclear
    // initiate resting variable and continue
    rest_time=1;
    }

    }
    }
    }//End of Main

    /*-----------------delay---------------------------------------------------------*/
    void Delay(int j)
    {
    int i;
    for(j=0;j<1;j++)
    for(i=0;i<0xFFFF;i++);
    }
    void Delay1(int j)
    {
    int i;
    for(j=0;j<10;j++)
    for(i=0;i<0xFFFF;i++);
    }
    // very long delay
    void Delay2(int j)
    {
    int i,m;
    for(m=0;m<j;m++)
    for(i=0;i<0xFFFF;i++);
    }
    void Timer_on() //Timer on function
    {
    CCTL0 = CCIE;
    __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
    }

    #pragma vector=TIMERA0_VECTOR
    __interrupt void Timer_A (void)
    {
    //one second counter variable
    CCR0 += 32768;
    if(++counter1>=10) //10 sec for nrv
    {
    if (nrv_operating == 1)
    {
    P1OUT |= 0x08; //P1.3=1 NRV motor rotates
    while(((P2IN & BIT0) == BIT0)||((P3IN & BIT7) != BIT7)); //wait P3.7==0;
    P1OUT &= 0x00; // P1.0 = 0,P1.1=0,P1.2=0,P1.3=0
    counter1=0;
    filling_done = 1;
    nrv_operating = 0;
    }
    }
    __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
    }

    /*--------------------------------------Reset--------------------------------------------------*/

    void Reset_all()
    {
    P1OUT=0x00;
    P2OUT=0x00;
    P3OUT=0x00;
    P4OUT=0x00;
    P5OUT=0x00;
    P6OUT=0x00;
    }

  • If P3.7 continues at a high level (no hardware pulls it low and the internal pull-down resistor is not enabled) then this statement will remain true and never exit the while loop.

    Regards,
    Ryan

**Attention** This is a public forum