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.

Why can I only save 256 ADC samples?

Other Parts Discussed in Thread: MSP430F5529, MSP-EXP430F5529LP

Hi everyone,


I'm starting with TI example code for repeated conversions on a single channel using "repeat-single-channel" mode.  The only change that I've made is changing the #define Num_of_Results from 8 to 500.  Anything greater than 500 causes issues, but that is a secondary problem right now.  

When i debug the code I connect a function generator to my MSP430 and look at the values in the results array.  I have values from 0 to 255 but every value after that is just 0.  What can I do to fill up the whole array?  I want this code to record 30-60 seconds of audio and I'm going to need more than 256 samples (and more than 500 samples for that matter).  I have pasted the code below, does anybody see what I am doing wrong?


Thank you.

#include <msp430.h>

#define   Num_of_Results   500
 
volatile unsigned int results[Num_of_Results];
                                            // Needs to be global in this
                                            // example. Otherwise, the
                                            // compiler removes it because it
                                            // is not used for anything.

int main(void)
{
  WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
  P6SEL |= 0x01;                            // Enable A/D channel A0
  ADC12CTL0 = ADC12ON+ADC12SHT0_8+ADC12MSC; // Turn on ADC12, set sampling time
                                            // set multiple sample conversion
  ADC12CTL1 = ADC12SHP+ADC12CONSEQ_2;       // Use sampling timer, set mode
  ADC12IE = 0x01;                           // Enable ADC12IFG.0
  ADC12CTL0 |= ADC12ENC;                    // Enable conversions
  ADC12CTL0 |= ADC12SC;                     // Start conversion
 
  __bis_SR_register(LPM4_bits + GIE);       // Enter LPM4, Enable interrupts
  __no_operation();                         // For debugger
 
}


#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
  static unsigned char index = 0;

  switch(__even_in_range(ADC12IV,34))
  {
  case  0: break;                           // Vector  0:  No interrupt
  case  2: break;                           // Vector  2:  ADC overflow
  case  4: break;                           // Vector  4:  ADC timing overflow
  case  6:                                  // Vector  6:  ADC12IFG0
    results[index] = ADC12MEM0;             // Move results
    index++;                                // Increment results index, modulo; Set Breakpoint1 here
   
    if (index == Num_of_Results)
    {
      index = 0;
    }
  case  8: break;                           // Vector  8:  ADC12IFG1
  case 10: break;                           // Vector 10:  ADC12IFG2
  case 12: break;                           // Vector 12:  ADC12IFG3
  case 14: break;                           // Vector 14:  ADC12IFG4
  case 16: break;                           // Vector 16:  ADC12IFG5
  case 18: break;                           // Vector 18:  ADC12IFG6
  case 20: break;                           // Vector 20:  ADC12IFG7
  case 22: break;                           // Vector 22:  ADC12IFG8
  case 24: break;                           // Vector 24:  ADC12IFG9
  case 26: break;                           // Vector 26:  ADC12IFG10
  case 28: break;                           // Vector 28:  ADC12IFG11
  case 30: break;                           // Vector 30:  ADC12IFG12
  case 32: break;                           // Vector 32:  ADC12IFG13
  case 34: break;                           // Vector 34:  ADC12IFG14
  default: break;
  }
}

  • unsigned char index is only 8 bits.

  • When you try to "save" data, you need to "write" the data into some physical thing that can be "read" back later. When you used up all that kind of physical thing, you cannot "save" any more.

    Your code shows that the physical thing you are using is the SRAM in a MSP430 chip. There are many kinds of MSP430. Some have only 128 bytes of SRAM. Others have more. Which one are you using?

  • Joseph is correct. That puts another limit even if you have enough SRAM.

  • Hi Kevin,

    Both of the answers suggested by Joseph and old_cow_yellow are correct. Your index is unsigned char, so it can only count from 0 to 255; try changing it to unsigned short. 

    I don't know which MSP430 you are using, but check the maximum RAM. Or please provide more details on the type of error you are getting when Num_of_Results > 500.

     

    Regards,

    Luis R

  • old_cow_yellow said:
    Joseph is correct. That puts another limit even if you have enough SRAM.

    Next problem will be the watchdog firing when initializing the large memory array before main()...

  • Hi Luis,

    Thank you (as well as Joseph and old_crow_yellow) for pointing out that the index is a char.  I changed that to an int for now and that is working.  I'll increase that size as I need to.


    I am using an MSP430F5529 on an MSP-EXP430F5529LP LaunchPad.  This development board has 8KB of Ram and 128KB of flash.

    When my Num_of_Results is changed to any number greater than 503 I build and debug the program and once the debugger starts it is automatically running, I do not click on Resume.  Then when I click on pause a new tab opens in CCS which says:

    Can't find a source file at "/tmp/TI_MKLIB28qeec/SRC/copy_zero_init.c"
    Locate the file or edit the source lookup path to include its location.

    I've tried to find that file but I don't even know where to look.  When I look at the ADC results after pausing the debugger I get all 0's before value 503 and everything after it is a very large random value.

    Do you have any idea what might be causing this issue?

    Thank you,

    Kevin

  • You are probably having the problem mentioned by Brian in his previous post. 

    Check this FAQ: http://processors.wiki.ti.com/index.php/MSP430_FAQ#WDT_fires_during_C_startup_code

    Regards,

    Luis R

**Attention** This is a public forum