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.

MSP430G2553: Temperature based motor speed controller help

Part Number: MSP430G2553


I've written a code to change the motor speed based on the temperature using internal temperature sensor. 

This is the code. But when I upload it and connect the circuit, The motor won't start. Can you please help me to find me if there are any errors with the code. 

Immediate support is highly appreciated. Thank you.

#include <msp430g2553.h>

long adcValue, tempC;

int main(void) {

WDTCTL = WDTPW + WDTHOLD; //Disable the Watchdog timer for our convenience.

P1DIR |= BIT6; //Set pin 1.6 to the output direction.
P1SEL |= BIT6; //Select pin 1.6 as our PWM output.

TA0CCR0 = 1000; //Set the period in the Timer A0 Capture/Compare 0 register to 1000 us.
TA0CCTL1 = OUTMOD_7;
TA0CCR1 = 500; //The period in microseconds that the power is ON. It's half the time, which translates to a 50% duty cycle.
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.

__bis_SR_register(LPM0_bits); //Switch to low power mode 0.

ADC10CTL1 = INCH_10 + ADC10DIV_3; // ADC Channel -> 10 (Temp Sensor), CLK/4
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE; // Ref -> 1.5V, 64 CLK S&H, Interrupt Enabled

__delay_cycles(100); // Wait for reference to settle

while(1)

{

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled

adcValue = ADC10MEM; // Fetch ADC conversion result

tempC = ((adcValue - 673) * 423) / 1024; // C = ( (adcValue/1024)*1500mV)-986mV)*1/3.55mV

if(tempC > tempC + 2)
{
TA0CCR1 = tempC*20;
}
if(tempC < tempC + 2)
{
TA0CCR1 = tempC*20;
}
_delay_cycles(1000);

}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}

  • Please check this code too. Neither are working. Thank you.
    #include<msp430g2553.h>
    long tempInDeg;
    long prevTemp = 0;
    long currTemp = 0;
     
    //MAIN PROGRAM
    void main(void)
    {
        // Stop Watch Dog Timer
              WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
     
        // select the P1.6 as the PWM output
              P1DIR |= BIT6 ;
              P1SEL |= BIT6 ;
              P1OUT = 0x00;
     
     
        // ADC initialization
     
              ADC10CTL0 = ADC10SHT_3 + SREF_1  + REFON + ADC10ON;
     
              ADC10CTL1 = INCH_10 + ADC10DIV_3;
     
              _delay_cycles(30);
     
        // PWM initialization
              TACTL = TASSEL_1 + MC_1 ;
              TACCR0 = 1000-1;
              TACCTL1 = OUTMOD_7;
              TACCR1 = 500-1;
     
                while(1)
                {
                    ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
                    while (ADC10CTL1 & ADC10BUSY);          // check for ADC conversion is completed
     
                    tempInDeg = (((ADC10MEM - 673) * 423) / 1024) - 10;
                    currTemp = tempInDeg;
                    if(currTemp > prevTemp + 2)
                    {
                        TACCR1 = tempInDeg*20 -1;
                        prevTemp = currTemp;
                    }
                    if(currTemp < prevTemp + 2)
                    {
                        TACCR1 = tempInDeg*20 -1;
                        prevTemp = currTemp;
     
                    }
     
                    _delay_cycles(1000);
     
              }
     
    }
     
    </msp430g2553.h>
  • Last time I worked with a DC motor (it's been a while) I recall I needed a fairly long PWM period (on-time) to overcome the startup inertia -- 1ms didn't seem to be enough. Try setting the period to maybe 50ms (50000).

    Are you using an H-bridge, or connecting the motor directly? If directly, the motor startup may be drawing too much current and (repeatedly) resetting your MCU.

    [Edit: You may want to go back to your first version until you get the motor to run, and only then work with your temperature arithmetic.]

**Attention** This is a public forum