CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Using 2D array float type as parameters in a function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rigomm



Joined: 17 Mar 2010
Posts: 13

View user's profile Send private message

Using 2D array float type as parameters in a function
PostPosted: Wed Oct 20, 2010 5:09 am     Reply with quote

Hi! I did a simple program using arrays This will be the base of a more complex one.

I’m using 2D arrays and passing them as parameters into a function.

If the variables (arrays) are declared as INTEGERS, the program works perfect!
If I declare the arrays as float, the function simply cannot load the variables. I mean, the variables in the function become zero.

Below the code of both versions

USING INTEGERS
Code:

#include  "30f3012.h"                                //DEVICE
#device adc=12
//*****************CHANGED INITAL dsPIC parameter to work at higher speed using the PLL
#FUSES HS2_PLL8//The xtal freq is divided by 2 and multiplied by 8 (maximum using 20MHz xtal)
#FUSES NOWDT // NO Watch Dog Timer
#FUSES PR_PLL //Primary Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#use delay(clock=80000000)// 20MHz/2*8=80MHz=80000000
#use rs232(baud=115200, xmit=PIN_B4, rcv=PIN_B5)    //To transmite result over Bluetooth module
//********************************
#define LED     PIN_D0
//=========================================================

int bandpass(int r[1][2],int r2[1][2]);
//**************************************************************************************
//////////////////
//*****MAIN*****//
//////////////////
void main()
{   
   printf ("start");   
  int step = 0;
  int x[1][2]={1,2};
  int y[1][2]={3,4};
  int a[1][2]={0,0};

   while(1)
   {
      step = bandpass(x,y);
      a[0][1]=step+y[0][1] ;
      printf("  Value  %d \n \r", a[0][1]); //display
      delay_ms(1000);
   }
}   
//=====================================================
int bandpass( int r[1][2] , int r2[1][2] )
{
    int z=1;                //
    z = r[0][0];              //
    printf("  Z  %d \n \r", z); //display
    return z;
}


Using integers: Z=2; Value=6 That is correct.

USING FLOATING TYPE
Code:

#include  "30f3012.h"                                //DEVICE
#device adc=12
//*****************CHANGED INITAL dsPIC parameter to work at higher speed using the PLL
#FUSES HS2_PLL8//The xtal freq is divided by 2 and multiplied by 8 (maximum using 20MHz xtal)
#FUSES NOWDT // NO Watch Dog Timer
#FUSES PR_PLL //Primary Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#use delay(clock=80000000)// 20MHz/2*8=80MHz=80000000
#use rs232(baud=115200, xmit=PIN_B4, rcv=PIN_B5)    //To transmite result over Bluetooth module
//********************************
#define LED     PIN_D0
//=========================================================

float bandpass(float r[1][2],float r2[1][2]);
//**************************************************************************************
//////////////////
//*****MAIN*****//
//////////////////
void main()
{   
   printf ("start");   
  float step = 0;
  float x[1][2]={1,2};
  float y[1][2]={3,4};
  float a[1][2]={0,0};

   while(1)
   {
      step = bandpass(x,y);
      a[0][1]=step+y[0][1] ;
      printf("  Value  %f \n \r", a[0][1]); //display
      delay_ms(1000);
   }
}   
//=====================================================
float bandpass( float r[1][2] , float r2[1][2] )
{
    float z=1;                //
    z = r[0][0];              //
    printf("  Z  %f \n \r", z); //display
    return z;
}


Using float type
Z=0, Value =4 That is incorrect.

Is not possible to use float type arrays as arguments in a function?
There is a way to make it work?
Please, any idea is welcome!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group