two functions calls in the same intervalTimer

Status
Not open for further replies.

Lorenzo

Well-known member
Hi forum,

Is it possible to call the same function two times in the same intervalTimer?

I am trying to compute the same function with different input in an interval timer that runs at 1 kHz.

Code:
void functionMotorControlTimer()
{
  Input1 = (float)(LC_1);
  Input2 = (float)(LC_2);
    
  Output1=PID_Compute(Input1,Setpoint1);  
  Output2=PID_Compute(Input2,Setpoint2);
  
  float pid_output1 = (float)(Output1); 
  float pid_output2 = (float)(Output2); 
}

PID_Compute is a home-made PID function.

Thank you :)
 
Is it possible to call the same function two times in the same intervalTimer?

Yes, should work fine.

However, this is going to be a problem:

Code:
  float pid_output1 = (float)(Output1); 
  float pid_output2 = (float)(Output2);

By declaring "float" in the function, these are local variables which only exist within functionMotorControlTimer(). You won't be able to access them from the rest of your program. Generally such variables need to be declared outside the function, and they usually need to be "volatile".
 
Thank you Paul. Actually there are some more rows of code that are needed to send the signal to the motors.

The problem is that the code works properly with only the first PID function (if I comment the second one) and also with only the second PID function (If I comment the first one).
 
There was a problem inside my PID_Compute function: I was uploading some global variables in a wrong way.
I have built a void function that computes both PID controls inside it and now it works! :D
 
Status
Not open for further replies.
Back
Top