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 support@ccsinfo.com

Function using array of float data does not work

 
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

Function using array of float data does not work
PostPosted: Sun Oct 17, 2010 11:09 pm     Reply with quote

Hi everybody!

I´m trying to do a very simple program using floating data.
The program only has to save the data of one array into another variable and return.
Obviously, this is just a test program.

The problem is that when I call the function, the value in the array is always zero.

Below the code:
Code:

//////////////////////////////////////////////////////
//               main.c
//////////////////////////////////////////////////////
#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
//********************************
//DEFINE===================================================
#define LED     PIN_D0
//=========================================================
//●For test-----------------------------------------------------------------
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= x[0][1];
//      printf("  step  %f \n \r", step); //display
     
      step = bandpass(x,y);
      a[0][1]=step+y[0][1] ;
        printf("  Value  %f \n \r", a[0][1]); //display
      delay_ms(1000);
   }//*1
}   

//=====================================================
float bandpass(float x1[1][2],float y1[1][2])
{
   float z =0;  //初期化
   z = x1[0][1];//2を代入
        printf("  Z  %f \n \r", z); //display
        printf("  x  %d \n \r", x1[0][1]); //display
   return(z);
}


In this example, the program should display 2 for the value of Z or X(0,1) but instead of that, it appear a zero. and actually, the function returns zeros as value of z.
What is wrong.
I did exactly the same program but using integers and it works smoothly.

It seem as when I call the function it does not take the value of the parameters.

Can anybody give a clue? please!
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