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.

CCS/MSP430G2553: MSP430G2553

Part Number: MSP430G2553

Tool/software: Code Composer Studio

Dear All;

I am making red round object tracking project by using MSP430G2553 and Matlab. When red round object moves, a car will track red round object. Project is consist of from two parts as image processing and

motion part. In motion part I am using L298N motor driver card, MSP430G2553. and a car that consist of from 2 wheels with 2 dc motors and a swivel castor. Image processing part in matlab is working as smooth.

But when a red ball moves, car can not track red object. When I compiled code in Code Composer Studio, it doesn't give any error. Therefore I can not find problem in code. I added MSP430G2553 code and parts of

image processing code that provide commnication between MSP430 and MATLAB. I think remander part of matlab code is working correctly.

Send_Code.txt
#include <msp430.h> 
//P1.3 ENA
//P1.4 IN1
//P1.5 IN2
//P1.6 ENB
//P2.0 IN3
//P2.1 IN4
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    DCOCTL = 0; // 
    BCSCTL1 = CALBC1_1MHZ; 
    DCOCTL = CALDCO_1MHZ; 
    P1SEL = BIT1; // P1.1 = RXD
    P1SEL2 = BIT1; // P1.1 = RXD
    UCA0CTL1 |=UCSWRST;
    UCA0CTL1 |= UCSSEL_2;
    UCA0BR0 = 104; // 1MHz 9600 baudrate
    UCA0BR1 = 0; // 1MHz 9600 baud rate
    UCA0MCTL = UCBRS0; // UART Baud adjustment
    UCA0CTL1 &= ~UCSWRST;
    IE2 |= UCA0RXIE; // USCI_A0 RX interrupt enable
    __bis_SR_register(LPM0_bits + GIE); // General interrrupts and LPM0 mode are active
    }
    
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    {
    unsigned char received;
    received = UCA0RXBUF; 
    if(received=='C') {  //C=CENTER
    P1OUT &= ~(BIT3 + BIT6);
    }

    else  if(received=='R') { //R=RIGHT
    P1OUT |=(BIT3 + BIT4);
    P1OUT &= ~BIT5;
    }

    else  if(received=='L') { //L=LEFT
    P1OUT |=BIT6;
    P2OUT |=BIT0;
    P2OUT &= ~BIT1;
    }

    else if(received=='F') { //F=FORWARD
    P1OUT |=(BIT3 + BIT6);
    P1OUT |=BIT4;
    P1OUT &= ~BIT5;
    P2OUT |=BIT0;
    P2OUT &= ~BIT1;
    }

    else if(received=='B') { //B=BACK
    P1OUT |=(BIT3 + BIT6);
    P1OUT |=BIT5;
    P1OUT &= ~BIT4;
    P2OUT |= BIT1;
    P2OUT &= ~BIT0;
    }
    else if(received=='N') { //N=NO MOTION
    	P1OUT &= ~(BIT3 + BIT6);
    }
    }

priorPorts = instrfind % finds any existing Serial Ports in MATLAB
delete(priorPorts) % and deletes them
s = serial('COM3');
set(s,'BaudRate',4800);
fopen(s);

IMAGE PROCESSING CODES

case 1
fwrite(s,'C');
case 2
fwrite(s,'L');
case 3
fwrite(s,'R');
case 4
fwrite(s,'B');
case 5
fwrite(s,'F');
otherwise
fwrite(s,'N');
end

I hope you will be able to provide information. 

  • It looks like on the MATLAB side you are initializing the UART baud rate at 4800 whereas the MSP430 code is set for 9600, and there could be miscommunication between the two as such. You should also make sure that no parity bits and only one stop bit is sent, and that MATLAB is connected to the proper MSP430 Application UART COM port.

    Regards,
    Ryan
  • Dear Ryan;

    I changed baud rate as 9600 and I am sure I send no parity bits and one stop bit. Also, I checked Matlab is connected to proper MSP430 Application UART COM port. But I can not find what is the problem in my code? Could you help me please?

    Regards.

  • Make sure that the RXD/TXD jumpers on J3 of your MSP-EXP430G2 are aligned properly. Start with a simple UART echo code example and terminal program to verify communication between your PC and MSP430 target device. Use logic analyzer and oscilloscope screenshots to further establish that the data is correctly being sent to the MSP430G2553.

    Regards,
    Ryan
  • Hi RYAN;

    I made RXD/TXD pin adjustments as correctly. Then I made an echo example by using UART module and hyperterminal program. This program is working correctly. I think my problem is in pwm part. I can not turn two motors with pwm simultaneously. I am using L298 motor driver card in this project. The motor that I connected to OUT3 and OUT4 connectors of card can not turn. For example I write below code to turn only one motor with pwm

    In this code I adjusted frequency of motor as 20 khz. If frequency is equal to 20 khz, period of motor is equal to T=1/f=1/20000 50us. I used clock source  as SMCLK. SMCLK is supplied from DC0 and DCO is adjusted to 1MHZ.
    Therefore I write TA0CCRO=50 and I adjusted TA0CCR1=30.
    Then I made pin connections.
    P1.2>>ENA
    P1.1>>IN1
    P1.3>>IN2
       
        This code can turn motor(motor that connected to OUT1 and OUT2) as fastly. But if I try to turn other motor with this code, motor can not turn.I connected to pwm output P1.2 to ENB and P1.1 to IN3 and P1.3 to IN4.
       
    #include <msp430.h> 
    
    int main(void) {
        WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
        DCOCTL=CALDCO_1MHZ;
            BCSCTL1=CALBC1_1MHZ;
    
        P1DIR |=BIT2; //PWM output
        P1SEL |=BIT2;
    
        TA0CCR0 = 50; 
        TA0CCTL1 = OUTMOD_7;
        TA0CCR1 = 30; 
        TA0CTL = TASSEL_2 + MC_1;
    
        P1DIR |=(BIT1+BIT3);
        while(1) {
        P1OUT &=~(BIT1);
        P1OUT|=(BIT3);
        }
    }

         Then I tried below code and it can not turn right motor like above code. When I give energy to right motor can move. So, problem is not in motor. But, when I tried to move both motors only one motor can move (the motor that is driven by IN1 and IN2).

    #include <msp430.h> 
    
    int main(void) {
        WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
        DCOCTL=CALDCO_1MHZ;
        BCSCTL1=CALBC1_1MHZ;
        P1DIR |= BIT6; //Set pin 1.6 to the output direction.
            P1SEL |= BIT6; //Select pin 1.6 as our PWM output.
            TA0CCR0 = 255; //Set the period in the Timer A0 Capture/Compare 0
    register to 255
            TA0CCTL1 = OUTMOD_7;
            TA0CCR1 = 255;
            TA0CTL = TASSEL_2 + MC_1; //TASSEL_2 selects SMCLK as the clock
    source, and MC_1 tells it to count up to the value in TA0CCR0.
    
            P1DIR|=BIT1+BIT2+BIT3+BIT4;
            while(1) {
            P1OUT|=BIT1+BIT3;
            P1OUT&=~(BIT2+BIT4);
    }
    
    }

          I made pin conenctions description to below.

    P1.1>>IN1
    P1.2>>IN2
    P1.3>>IN3
    P1.4>>IN4
    P1.6>>ENA&ENB(I connected pwm output to both ENA and ENB pins of L298 motor driver card. Also Motor outputs are connected to OUT1,OUT2,OUT3 and OUT4 connectors as respectively.Then, GND of MSP430 and gnd of 9V battery are connected to GND connector
    of L298.
        By using this code or another code I can not turn both motor simultaneously.Only one motor can turn.

          Why I can not turn 2 motors simultaneously with PWM? Where is my fault? Could you help me please? Regards.

  • Use an oscilloscope or screenshot analyzer to view the ENA & ENB lines and L298 outputs, if possible then don't multiplex ENA & ENB but drive the enable pins from separate pins (TA0.1 on P1.2/1.6 or use TA0.2/TA1.1/TA1.2). You should make sure that your power supply is sufficient for the current draw of both motors.

    Regards,
    Ryan

**Attention** This is a public forum