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.

pwm to controlled 5v dc motor using msp430g2553

Other Parts Discussed in Thread: MSP430G2553, L293D

guys help me to find the right solution from the code

#include<msp430g2553.h>

volatile unsigned long i;
void main(void)
{
    WDTCTL = WDTPW + WDTHOLD;

    P1OUT = 0X00;
    P1DIR |= BIT1;
    P1OUT |= BIT1;

    TACTL  |= TASSEL_2 + MC_1;
    TACCTL0 &= ~CAP;

    TACCR0 = 5000;
    TACCR1 = 50;


    while(1)
    {
    TACCTL0 |= OUTMOD_4;
    }
}

this is my pwm generation code. am getting CONSTANT  value on voltmeter on msp430g2553 port pin1.1(TA0.0) . I dont know where im doing wrong if my code is wrong.send me right code to generate pwm to drive 5v dc motor using l293D driver circuit

  • To output a module signal (like tiemr PWM) on a port pin, you'll have to select it by setting the proper PxSEL bits. E.g. "P1SEL|=BIT2;"

    In your code, you use CCR0 to set the PWM frequency. The TA0.0 output signal is either a short pulse or 50% DC, depending on TA0CCTL0 OUTMOD.
    The actual PWM signal with adjustable duty cycle is generated by CCR1 on TA0.1 output. (I think on P1.2, hence the P1SEL above).

    You can generate a PWM signal on CCR0 output, but then the timer needs to run in up mode and the PWM frequency is implicitely set by the timer overflow frequency. (15Hz on 1MHz timer clock, 0.5Hz on 32768Hz timer clock). Much too slow for a motor control, but it gives a whopping 16 bit DC resolution :)

    Depending on your multimeter, you might not be able to properly measure a PWM signal. The motor averages the signal by its inductance. For the multimeter you might need an R/C combination

  • Hi krishnan,

                          Whenever you are playing with PWM, there are 3 things which are to be considered.

    • Clock frequency-----This feeds TImer module.
    • Period of PWM that you need-------This decides the PWM frequency
    • Duty cycle

    so for the same application I may go like this....

    #include<msp430g2553.h>

    volatile unsigned long i;

    #define StartTimer()    TACTL |= MC_1; //START TIMER IN UP MODE
    #define StopTimer()        TACTL |= MC_0;

    void main(void)
    {
        // Turn offf WDT
        WDTCTL = WDTPW + WDTHOLD;
        // Select DCO@1MHz as clock sources
        DCOCTL = CALDCO_1MHZ;
        BCSCTL1 = CALBC1_1MHZ;

        // Initialise Timer_A for PWM output
          TACTL = TASSEL_2 ;                         // clock = SMCLK

          TACCTL1 = CM_0 | OUTMOD_7    ;               // CM_0: Compare mode (no capture mode)
                                                    // OUTMOD_7 set/rest mode PWm
          TACCR0 = 120;                             // 8-bit counter from 00h to FFh
        //sri Notes: Usually this goes as PWM period
        // Set P1.2 as output for PWM signals

          P1DIR |= BIT2;                            // Pin4-P1.2/TA0.1 is output
          P1SEL |= BIT2;                          // Pin4-P1.2/TA0.1 is TA1 output WITH PWM functionality
        //sri Notes: P1.1 cannot be used for PWM output

          TACCR1 = 60;

        //Sri Notes:This combination gives a PWM signal of 8.2 with 50% duty cycle.
          StartTimer();

        while(1)
        {

        }
    }
    Regards,

    Sri.

  • prabhakaran krishnan said:
    I dont know where im doing wrong if my code is wrong.send me right code to generate pwm to drive 5v dc motor using l293D driver circuit

    and krishnan, this is not polite. Hope you understand!

    Regards

    Sri.

    Please check Verify answer if this answers your question.

**Attention** This is a public forum