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.

CCS/MSP430F5522: How do I find where variables declared as floats are stored in memory?

Part Number: MSP430F5522

Tool/software: Code Composer Studio

I'm not sure if I'm even asking this question correctly so please bear with me.

I'm having an issue with my stored data read from an A/D converter.  When I'm debugging and look at the variables that are set from an A/D converter pin, 11 out of 12 of my variables are stored as 0.  The last is the value expected.  When I connect my device to my computer via USB, I can see the values for each of the variables on the MSP430 USB HID application, the values for these variables are all reading as expected.  It is only when it is disconnected where all but one of the variables are lost.  I'm guessing it is because they being set to be stored in an improper register but how do I find where these variables are being stored?  

FYI, the variables  are all based on values read from up to 3 A/D pins.  The USB HID application allows the user to select which pin corresponds to each variable, and the same variables are always reading zero in the debugger regardless of what A/D they base their values off of.  

  • Hi Kyle,
    How are you storing your variables? Do you have code you can share?

    Are you using DMA? If so, you could check the memory location in the DMAxDA register.

    If you view the variables in the debugger while connected to USB, do they still read as 0?
  • Thank you for the reply!

    The missing variables are stored as floats but they are part of a static structure.  As far as how they are being stored in memory, that is what I am trying to find out.  I inherited this project and I'm pretty sure these variables are zeros because of a memory storage issue, but I can't find where they are stored.

    static struct testResults starResults = { 0,0,0,0,0,0,0,0,0,0,0,0};
    struct testResults 
    {
    	float ch1Amplitude;
    	float ch2Amplitude;
    	float ch3Amplitude;
    	int min1;
    	int max1;
    	int min2;
    	int max2;
    	int min3;
    	int max3;
    	float mean1;
    	float mean2;
    	float mean3;
    };

    The variables in multiple locations for comparing values but this is the function where they get set to the correct analog values read from the analog input pin:

    void testMethod_2( test_data_t *t, int chan,int  led)  // high sensitivity with boost board attached
    {
    
    
    	int i,j,c,k;
    	int numTests=1;//64;//8;
    
    
    	 long results[2];
    	 int sample[3];
    
    
    	for (i=0; i< 2; ++i )
    	{
    		 results[i]=0;
    	}
    
    	switch_adc_input( chan );
    	if ( AdcResolution == TWELVEBITS )
    	{
    		ADC_CONTROL2 |= BIT5; //ADC_RES;  // set to 12 bit resolution
    		ADC_CONTROL2 &= ~BIT4; //
    	}
    
    	c=222;
    
    	ADC12CTL0 |= ADC12MSC;
    	ADC12CTL1 |= ADC12CONSEQ_2;
    	ADC12IE=0x01;
    
    	//ADC_CONTROL0 |= ADC_ENABLE_CONV ;  // enable adc conversions
    
    
    	if ( c < 600 ) //  skip testing and report -1 result because of excessive noise.
    	{
    
    
    		PHOTODIODE1_OFF;PHOTODIODE2_OFF;
    		timer_us( 100 );//test
    		for ( k=0; k < 1; ++k)
    		{
    			if (chan==ADC_AMP1OUT)
    				PHOTODIODE1_ON;
    			else PHOTODIODE2_ON;
    
    
    			for ( i=0; i < numTests; ++i)
    			{
    				if ( k==0 && i==5)  // fake cycle to correct for slump in output on first cycle
    					break;
    
    
    				led_on( led, PD_OFF); //led_on( led, PD_ON);  use led '5'  to use no led or just set the led time too much less in next statement.
    				timer_us(2);
    				LED1_OFF;  LED2_OFF; LED3_OFF; // turn off led
    				timer_us(t->blanking_us );
    				if (chan==ADC_AMP1OUT)
    					PHOTODIODE1_ON;
    				else PHOTODIODE2_ON;
    				timer_us(t->meas_delay_us);
    				adcIndex=ADC_SAMPLES_FOR_TEST2_AMPLITUDE;
    				adcResults=0;
    				ADC_CONTROL0 |= ADC_START_CONV+ADC_ENABLE_CONV;                     // Start conversion
    				  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM4, Enable interrupts
    				  __no_operation();                         // For debugger
    
    				sample[0] = adcResults>>5;  //(long)ADC_MEMORY_LOC;
    				PHOTODIODE1_OFF;PHOTODIODE2_OFF;
    				timer_us(50);
    				led_on( led, PD_OFF); //led_on( led, PD_ON);
    				timer_us(t->ledOn_usec);
    				LED1_OFF;  LED2_OFF; LED3_OFF; // turn off led
    				timer_us(t->blanking_us );
    				if (chan==ADC_AMP1OUT)
    					PHOTODIODE1_ON;
    				else PHOTODIODE2_ON;
    				timer_us(t->meas_delay_us);
    
    				adcIndex=ADC_SAMPLES_FOR_TEST2_AMPLITUDE;
    				adcResults=0;
    				ADC_CONTROL0 |= ADC_START_CONV+ADC_ENABLE_CONV;                     // Start conversion
    				__bis_SR_register(LPM0_bits + GIE);       // Enter LPM4, Enable interrupts
    				__no_operation();                         // For debugger
    
    				sample[1] = adcResults>>5;//(long)ADC_MEMORY_LOC;
    
    				sample[0]=sample[1]-sample[0];
    				results[0]+=(long)sample[0];
    
    				timer_us(10);//350);//450); //1000);
    
    			}
    
    		}
    
    		ADC_CONTROL0 &= ~ADC_ENABLE_CONV ;  // disable adc conversions
    		ADC12CTL0 &= ~ADC12MSC;
    		ADC12CTL1 &= ~ADC12CONSEQ_2;
    		ADC12IE=0;
    		ADC_CONTROL2 |= BIT4; //ADC_RES;  // set to 10 bit resolution
    		ADC_CONTROL2 &= ~BIT5; //
    
    		results[0] = (results[0]/ numTests) ;
    
    
    		//timer_us(75); // 5ms x 10 = 50 ms
    	}
    	else
    		results[0] = -1;
    
    	PHOTODIODE1_ON;PHOTODIODE2_ON;
    	if (t==&stardata.AtestData[currentTestParmIndex] )
    		starResults.ch1Amplitude = results[0];//(float) results[2];
    	else if (t==&stardata.BtestData[currentTestParmIndex])
    		starResults.ch2Amplitude =(float) results[0];
    	else starResults.ch3Amplitude =(float) results[0];
    }

    The key part to notice is:

    starResults.ch2Amplitude =(float) results[0];
    	else starResults.ch3Amplitude =(float) results[0];

    ch2Amplitude and ch3Amplitude are the variables that are stuck at 0.


    ch1Amplitude is the variable that is the analog value that is expected.  I am reading these values while attached to the debugger.  

  • Hi Kyle,

    First off, Id like to point out that floats should be avoided if at all possible on MSP430. They are inefficient. Second, I'm assuming that the other 9 variables in the struct are dependent on ch2 and ch3 amplitude?

    If you add the struct to a watch expression, you can see memory location of it and its contents. (see pic below)

    Can you breakpoint on whats labelled above as line 115 and check that result[0] is populated? Alternatively you could swap line 113 and line 115 and see if you get a value in ch2amplitude; to rule out memory issues.

    It strikes me as odd that you are casting the second 2, but not the first (working) variable. I did a quick test of this which shows the same result though.

  • Thanks again for the help. I really appreciate it and I'll tackle variable declaration later once I get this figured out. Like I said, I inherited this project and a lot of this is kind of new to me. The other variables are relative the the first three amplitude variables. So it makes sense that the min/max/mean 2 and 3 and 0, but for 1 it should be populated.

    Thanks for the address tip. I actually was monitoring that struct but my window was small and the address column wasn't visible. That was a stupid mistake.

    Switching lines 113 and 115 made the channel 2 amplitude value on the debugger and with the GUI program that goes along with these device show what the channel 1 amplitude is expected to be. On the expressions tab, the value is shown on ch2Amplitude and ch1 is 0 and the addresses do not change for the values, so I guess my theory of a memory problem is invalid. I'm not sure what the problem could be at this point anymore
  • Do you ever make it into the else's on line 114 and 116?
    If so, can you break point line 115 and 116 and check the contents of results[0]?
  • It never hits those breakpoints. So that means t==&stardata.BtestData[currentTestParmIndex] and (t==&stardata.CtestData[currentTestParmIndex] are never true. But why is it true for A?
  • That means it's always true. So for some reason t isn't being modified. Try ctrl + clicking on t, or right click and click show references. That should help you track down why it isn't changing. THen you just need to find out how to enter that section of code and get the conditions to match.
  • I still haven't solved the problem but I'm now able to backtrack and I definitely will be able to solve it because of your suggestions, so thanks Cameron!

**Attention** This is a public forum