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.
//******************************************************************************
// MSP430G2x33/G2x53 Demo - ADC10, Sample A10 Temp, Set P1.0 if Temp ++ ~2C
//
// Description: se ADC10 and the integrated temperature sensor to detect
// temperature gradients. The temperature sensor output voltage is sampled
// ~ every 120ms and compared with the defined delta values using an ISR.
// (ADC10OSC/4)/64 determines sample time which needs to be greater than
// 30us for temperature sensor.
// ADC10 is operated in repeat-single channel mode with the sample and
// convert trigger sourced from Timer_A CCR1. The ADC10IFG at the end
// of each converstion will trigger an ISR.
// ACLK = n/a, MCLK = SMCLK = default DCO ~ 1.2MHz, ADC10CLK = ADC10OSC
//
// MSP430G2x33/G2x53
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// |A10 P1.0|-->LED
//
// D. Dang
// Texas Instruments Inc.
// December 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include "msp430g2553.h"
static unsigned int FirstADCVal; // holds 1st ADC result
#define ADCDeltaOn 3 // ~ 2 Deg C delta for LED on
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
ADC10CTL1 = ADC10DIV_3 + INCH_10 + SHS_1 + CONSEQ_2; // TA trig., rpt, A10
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REF2_5V + ADC10IE + REFON + ADC10ON;
__enable_interrupt(); // Enable interrupts.
TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode.
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
ADC10CTL0 |= ENC;
TACCTL1 = OUTMOD_4; // Toggle on EQU1 (TAR = 0)
TACTL = TASSEL_2 + MC_2; // SMCLK, cont-mode
while (!(ADC10IFG & ADC10CTL0)); // First conversion?
FirstADCVal = ADC10MEM; // Read out 1st ADC value
P1OUT = 0x00; // Clear P1
P1DIR = 0x01; // P1.0 as output
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
if (ADC10MEM >= FirstADCVal + ADCDeltaOn)
P1OUT |= 0x01; // LED on
else
P1OUT &= ~0x01; // LED off
ADC10MEM=0x00;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}
here i did not understand the role of TACCTL1, FirstADCVal, ADCDeltaOn. and also why ADCDeltaOn is set to 3?
please help.
Hi,
For TACCTL1, you should see the 2xx user guide www.ti.com/lit/pdf/slau144 particularly the section on the Timer A module.
GURU MOORTHY said:here i did not understand the role of TACCTL1, FirstADCVal, ADCDeltaOn. and also why ADCDeltaOn is set to 3?
Most of this information is somewhat touched on in the comments at the top of the code:
GURU MOORTHY said:// Description: se ADC10 and the integrated temperature sensor to detect
// temperature gradients. The temperature sensor output voltage is sampled
// ~ every 120ms and compared with the defined delta values using an ISR.
// (ADC10OSC/4)/64 determines sample time which needs to be greater than
// 30us for temperature sensor.
// ADC10 is operated in repeat-single channel mode with the sample and
// convert trigger sourced from Timer_A CCR1. The ADC10IFG at the end
// of each converstion will trigger an ISR.
as well as in the comments where FirstADCVal and ADCDeltaOn are defined:
GURU MOORTHY said:static unsigned int FirstADCVal; // holds 1st ADC result
#define ADCDeltaOn 3 // ~ 2 Deg C delta for LED on
So putting this all together, you'll see that TACCTL1 is the timer trigger being used to trigger the ADC conversions.
FirstADCVal is a variable where the first ADC reading at the beginning of code execution is stored. After we have stored the first ADC value, we want to turn the LED on whenever the temperature increases more than a certain preset amount to detect the temperature gradient (as mentioned in the comments at the top of the code) - this preset amount is whatever we have set for ADCDeltaOn. So in the ADC ISR, we compare the ADC value that was just measured to FirstADCVal+ADCDeltaOn - if the measured value is greater, the LED is turned on, else it is turned off. In this case ADCDeltaOn was set to 3 ADC counts, which is about 2 degrees C in this case (from the comment).
I hope this helps to clear this up.
Regards,
Katie
GURU MOORTHY said:i did not understand the role of TACCTL1, FirstADCVal, ADCDeltaOn. and also why ADCDeltaOn is set to 3
SHS_1 selects a timer's compare output signal for triggering conversion. On your MSP, it is TACCR1.OUT, so the TACCR1 PWM signal triggers the conversions. (you don't need to output it to a pin, the connection is internal)
FirstADCVal holds the very first conversion result. That is the temperature right after power-on. ADCDeltaOn is a trigger level. If a future conversion result is by ADCDeltaOn larger than the initial value (menaing the temperature has increased, where an increase of 3 counts is a temperature change of ~2°C), the LED is switched on. Once temperature is back to normal, the LED is switched off.
**Attention** This is a public forum