Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MSP430 16 bit ADC Operation

Status
Not open for further replies.

wuchy143

Member
Hi All,

I'm trying to use the 16 bit sigma delta ADC. I'm leveraging TI's example where I'm just trying to learn exactly how the example works so I can then apply it to my application.(Digital Amplifier).

I understand how the codes works below well but there is still one lingering issue at least in my head. The program starts by setting appropriate SFR's, enabling interrupts, and then finally turning on the ADC for continuous conversion. Problem I have is when the program finally turns on the continuous ADC conversion, then sets the micro in low power mode it goes right to ISR. Why doesn't the program run off into oblivion. There is no continuous loop in main so the micro doesn't go off and lose it's mind? I thought it should. It's as if it just uses the ISR as an infinite loop. But I don't understand why. I'm still a noob at programming so please be gentle if it's very obvious :)

Thanks

-mike

Code:
//*****************************************************************************
//   MSP430x42x0 Demo - SD16_A, Continuous Conversion on a Single Channel
//
//  Description: This program uses the SD16_A module to perform continuous
//  conversions on a single channel. A SD16_A interrupt occurs whenever a
//  conversion has completed. Test by applying a voltage to CH0
//  (A0+, A0-) and setting a breakpoint at the line indicated below.
//  Run program until it reaches the breakpoint, then use the debugger's
//  watch window to view the conversion results. Conversion results are
//  stored in the array, "results".
//  ACLK = LFXT1 = 32768 Hz, MCLK = SMCLK = DCO = 32 x ACLK = 1048576 Hz
//  //* An external watch crystal on XIN XOUT is required for ACLK     *//	
//  //* Minimum Vcc is required for SD16_A module - see datasheet        *//
//  //* 100nF cap btw Vref and AVss is recommended when using 1.2V ref *//
//
//                MSP430F4270
//             -----------------
//         /|\|              XIN|-
//          | |                 | 32kHz
//          --|RST          XOUT|-
//            |                 |
//    Vin+ -->|A0+              |
//    Vin- -->|A0-              |
//            |                 |
//            |            VREF |---+
//            |                 |   |
//            |                 |  -+- 100nF
//            |                 |  -+-
//            |                 |   |
//            |            AVss |---+
//            |                 |
//
//  L. Westlund / S. Karthikeyan
//  Texas Instruments Inc.
//  June 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.30A
//*****************************************************************************
#include  <msp430x42x0.h>


#define   Num_of_Results   8

/* Arrays to store SD16_A conversion results */
/* NOTE: arrays need to be global to       */
/*       prevent removal by compiler       */
static unsigned int results[Num_of_Results];

void main(void)
{
  volatile unsigned int i;                  // Use volatile to prevent removal
                                            // by compiler optimization

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  FLL_CTL0 |= XCAP14PF;                     // Configure load caps to 8pF FLL_CTL0 = 0X20
  for (i = 0; i < 10000; i++);              // Delay for 32 kHz crystal to
                                            // stabilize

  SD16CTL = SD16REFON + SD16SSEL0;          // 1.2V ref, SMCLK SD16CTL = 0X0014
  SD16INCTL0 |= SD16INTDLY_0;               // 4th sample will cause interrupt, SD16INCTL0 = 0X00
                                            // selects input pins(pins 13/14), PGA = X1
  SD16CCTL0 |= SD16IE ;                     // Enable interrupt SD16CCTL0 = 0X08
  for (i = 0; i < 0x3600; i++);             // Delay for 1.2V ref startup

  _EINT();                                  // Enable general interrupts

  SD16CCTL0 |= SD16SC;                      // Set bit to start continuous conversion
  _BIS_SR(LPM0_bits);                       // Enter low power mode

}

#pragma vector=SD16_VECTOR                  //puts interrupt funct in memory  
__interrupt void SD16ISR(void)              //defined by SD16_VECTOR in .h for chip            
{
  static unsigned int index = 0;

  switch (SD16IV)
  {
  case 2:                                   // SD16MEM Overflow
    break;
  case 4:                                   // SD16MEM0 IFG
    results[index] = SD16MEM0;              // Save CH0 results (clears interrupt flag automatically(SD16IFG)

    if (++index == Num_of_Results)
    {
      index = 0;                            // SET BREAKPOINT HERE
    }
    break;
  }
}
 
Last edited:
Interesting. Just so I understand this well. The micro is asleep no matter what until an interrupt occurs(ADC results complete in this case). It wakes up. Does it's job and then goes back to sleep? FYI you're right. Just read what you said on page 39 of the datasheet. :)
 
Last edited:
operating modes
The MSP430 has one active mode and five software selectable low-power modes of operation. A
event can wake up the device from any of the five low-power modes, service the request and resto
the low-power mode on return from the interrupt program.
The following six operating modes can be configured by software:
 Active mode AM;
−All clocks are active
 Low-power mode 0 (LPM0);
−CPU is disabled
ACLK and SMCLK remain active, MCLK is available to modules
FLL+ Loop control remains active
 Low-power mode 1 (LPM1);
−CPU is disabled
ACLK and SMCLK remain active, MCLK is available to modules
FLL+ Loop control is disabled
 Low-power mode 2 (LPM2);
−CPU is disabled
MCLK and FLL+ loop control and DCOCLK are disabled
DCO’s dc-generator remains enabled
ACLK remains active
 Low-power mode 3 (LPM3);
−CPU is disabled
MCLK, FLL+ loop control, and DCOCLK are disabled
DCO’s dc-generator is disabled
ACLK remains active
 Low-power mode 4 (LPM4);
−CPU is disabled
ACLK is disabled
MCLK, FLL+ loop control, and DCOCLK are disabled
DCO’s dc-generator is disabled
Crystal oscillator is stopped

Straight from the datasheet
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top