Other Parts Discussed in Thread: MSP430G2553
I am using MSP430G2553 for temperature sensor application. i am pasting here 2 types od codes
code 1:
#include <msp430g2553.h>
unsigned int T_count;
unsigned int emflag =0;
unsigned int B_count;
long ActualTemp;
long IntDegC;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
T_count =0;
DCOCTL = 0;
BCSCTL1= CALBC1_8MHZ; // System Clock Settings
DCOCTL = CALDCO_8MHZ; // use calibrated 8MHz settings
P1DIR |= BIT0+BIT2+BIT3; // P1.2 and P1.3 output
P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
_bis_SR_register(GIE);
TA1CCR1 = 5000;
TA1CCTL0 = CCIE; // CCR0 interrupt enabled
TA1CTL = TASSEL_2 + MC_2 + ID_3 + TAIE; // SMCLK, contmode
}
#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer_B (void)
{
switch (__even_in_range(TA1IV, 10)) // Efficient switch-implementation
{
case 0:
break;
case 2:
TA1CCR1 += 50000; //50ms //6/10/2010
break;
case 10: //655.35ms
T_count++;
if(T_count >= 4)
{
T_count = 0;
ADC10CTL1 = INCH_10 + ADC10DIV_3;
ADC10CTL0 = SREF1 + ADC10SHT_3 + ADC10ON + REFON;
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
ActualTemp = ADC10MEM;
IntDegC = ((ActualTemp - 673) * 423) / 1024;
__no_operation(); // break point here
}
break;
}
}
When i put break point on _no_operation(); to read "IntDegC" @ room temp (25C) i am getting 144 decimal. I am debugging on computer with TI launchpad.
here is the code 2:
#include <msp430.h>
long temp;
long IntDegF;
long IntDegC;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL1 = INCH_10 + ADC10DIV_3; // Temp Sensor ADC10CLK/4
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
temp = ADC10MEM;
IntDegF = ((temp - 630) * 761) / 1024;
temp = ADC10MEM;
IntDegC = ((temp - 673) * 423) / 1024;
__no_operation(); // SET BREAKPOINT HERE
}
This code works fine and at breakpoint i am readin temp 22C which is very close to ambient temperature.
Since, in my application i want to read temperature every 1 min, i want to use timer in continuous mode with interrupt every minute. so code 1 should work.
tell me if anything is wrong with the code 1.
Thanks
Abhishek