problem with SW_I2C output data

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

problem with SW_I2C output data

1,005 Views
admin
Specialist II

I run the below loop in main().

I use a subroutine called Get_ADC_Raw() that utilizes the SW_I2C bean to gets data from a outside IC.
The below code will work for me – the data from Get_ADC_Raw() is put into a variable OutX Then this data is pushed out to my screen by the subroutine OutputRawtoScreen()

What I would like to do is take that data which is in variable OutX and do a couple of calculations, the last calculation is a log10().

The below code works - (only because set the OutX variable to a fixed value) I get the correct data from the Get_ADC_Raw() - it outputs correctly to the screen for me and the other calculation including the log10() work fine for me. Now if I eliminate the line “OutX = 4000” and just try to use the raw data that should be in that variable it seems to mess up the data that comes out of the Get_ADC_Raw() routine.

This is probably something simple I’m doing wrong and have worked the last couple of days to try and solve the problem without success.

My original project and code was developed around the MC9S08QE128 processor and it worked fine and was pretty much complete - I only started to have issues when I switched to the MC9S08JM60 processor (I needed USB capabillity). I'm sure it is probably something simple like an initialization that I need to take care of but I just can't find the solution.

 

Below is a basic run down of the code which has subroutines that are placed in other .c files that I link using .h files.

I am new to this forum and this is my first post so I apolgize if my explanation of my issue is not clear.

 

Any help would be be much appreicated - thanks!

 

  unsigned int OutX;
  float logVal;
  float logOut;

 

        for(;:smileywink:{
           OutX = Get_ADC_Raw();   //get data from SW_I2C bean
           OutputRawtoScreen(OutX); //output that data to my display

           OutX = 4000;   //set the variable to 4000

           logVal = OutX/32.767;  //divide the var value by 32.767 and out into logVal
           logVal = logVal/1000;   //divide the logVal by 1000 and place back in logVal
           logOut = 10*log10(logVal);   // do a log10 conversion on the logVal and place in logOut
      }

Labels (1)
0 Kudos
Reply
3 Replies

842 Views
admin
Specialist II

Now it would appear that my issue is related to the log10() function - I exited out of codewarrior and went back in and restarted the BDM. Now if I take the log10() function out the result from the Get_ADC_Raw() which uses the SW_I2C bean is correct but if I leave it in the code the result from Get_ADC_Raw() is not correct.

Am I having some type of pointer or initialization issue related to using the log10() that is effecting the SW_I2C bean result? 

Puzzled and frustrated!

0 Kudos
Reply

842 Views
bigmac
Specialist III

Hello, and welcome to the forum.

 

With the use of floats, and functions such as log10(), this will require a significantly larger stack than the case where floats are not used.  I suspect that you are experiencing stack overflow.  If so, the solution is to increase the stack size.

 

Regards,

Mac

 

 

0 Kudos
Reply

842 Views
admin
Specialist II

MAC - Your the man!!

Thanks a million!

0 Kudos
Reply