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)
}