rigomm
Joined: 17 Mar 2010 Posts: 13
|
Function using array of float data does not work |
Posted: Sun Oct 17, 2010 11:09 pm |
|
|
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! |
|