A question to a function implementation & Pointer it dosent work

Hi there

I have a header file which contains :

#ifndef header_h
#define header_h_h


void Transformation( float u, float v, float w, float *I_alpha, float *I_beta)
{
  
  
  float w;  
              w=u-v;
             *I_alpha=u;// I_alpha= Strom_Phase_1
              *I_beta= 0.57735*(u+2.0000* v); //
       
  }
  #endif

In included it in my main code in that way

#include "C:\Users\transformation.h" 

float I_1 ;
float I_2 ;
float I_3 ;

float alpha ; 
float beta; 

Transformation(I_1,I_2,I_3,&alpha,&beta);

Serial.print(" alpha = "); 
Serial.println(alpha ,4);
Serial.print(" beta = "); 
Serial.println(beta,4);

My Serialprint shows the correct value for alpha but beta gets wrong values or the time ...

I have noe clue what is wrong... did I use the pointer and the &refrence in the rigt way ?

Thanks in davance

void Transformation( float u, float v, float w, float *I_alpha, float *I_beta)
{
  
  
  float w;  
              w=u-v;
             *I_alpha=u;// I_alpha= Strom_Phase_1
              *I_beta= 0.57735*(u+2.0000* v); //
       
  }

Why two variables called "w"? One in the function and one an argument.

Please show your debugging output.

in the code you posted the I1…3 are not initialized.

Please post the complete sketch otherwise it is undo-able to reproduce the error

It looks OK to me. Please make up a test sketch which actually compiles. Supply test values. Show that the answer is wrong.

My Serialprint shows the correct value for alpha but beta gets wrong values or the time ...

Well, how about showing this serial print? It's all completely hypothetical when you say "some numbers are entered and I get some other numbers out and they are wrong".

I have a header file which contains :

void Transformation( float u, float v, float w, float *I_alpha, float *I_beta)
{
  
  
  float w;  
              w=u-v;
             *I_alpha=u;// I_alpha= Strom_Phase_1
              *I_beta= 0.57735*(u+2.0000* v); //
       
  }

You don't normally put functions into a header file. You put prototypes. The code goes into .c or .cpp files.

I guess we should ignore w, since you don't use it in the function.

void Transformation( float u, float v, float w, float *I_alpha, float *I_beta)
{

  w=u-v;
  *I_alpha=u;// I_alpha= Strom_Phase_1
  *I_beta= 0.57735*(u+2.0000* v); //

}

I don’t understand what you are doing here. Assuming you remove “float w”, then all you do is replace the passed-in w by u-v. Then you don’t use w.

Then the function returns “*I_alpha=u” which means it simply returns whatever-it-is in u back to the caller. So that doesn’t achieve much either.

Finally you do a calculation, which when I tested it, returns the correct results.

So you really need to state what numbers you are passing in, what you expect to get, and what you actually get.

How To Ask Questions The Smart Way

Show the values you pass in, the values you actually got back, and what values you expected to get back.

It's no good saying things are "correct" or "wrong".

You have to be specific.

And post your complete sketch, or I'll have to send you off to http://snippets-r-us.com/

                    I_1_2=I_2-I_Phase_1;

Try better data names. And use some spaces. This is unreadable.

And there is no reason to use a header file for this. Just put the function in your C file and delete the header file. The IDE will even create the prototype for you (for better or worse).

There is also no reason to put in 2.0000, it will not affect the calculation in any way. One zero, or at least the decimal point, is important to signal the compiler that it is a float.

Where is PaulS when you need him?

See reply #9.

void loop() {
  // put your main code here, to run repeatedly:
  Sensor_1= analogRead(A0)*volt;
  Sensor_2= analogRead(A1)*volt;
  Sensor_3= analogRead(A2)*volt;

  void Transformation( float A, float B, float C, float &alpha, float &beta);

  Serial.print(" alpha = "); 
  Serial.println(alpha,4);
  Serial.print(" beta = "); 
  Serial.println(beta,4);

}

See: Gammon Forum : Electronics : Microprocessors : Arduino programming traps, tips and style guide

void loop() {
  // put your main code here, to run repeatedly:
  Sensor_1= analogRead(A0)*volt;
  Sensor_2= analogRead(A1)*volt;
  Sensor_3= analogRead(A2)*volt;

  void Transformation( float A, float B, float C, float &alpha, float &beta);

  Serial.print(" alpha = "); 
  Serial.println(alpha,4);
  Serial.print(" beta = "); 
  Serial.println(beta,4);

}

Where do you use Sensor_1, Sensor_2 and Sensor_3?

What is with the weird indentations?

ABC is not used, why bother to calculate it?

Tell us the values you input into the function and what you get back for alpha and beta. We can't see your screen.

He's not calling the function so the values don't matter.