Shared output variable for 2 PID loops


#1

Hi,

I am trying to control a heater with either constant power or constant temperature (I have a thermocouple to measure the temperature). So I created 2 PID loops; I set temperature in one and power in the other one. The problem is that both have the same control variable at the output, the heater current.

My initial idea was to enable the PID loop that I need to use with SetPidMode(PID_name,0) while having the other one as manual SetPidMode(PID_name,1) (~disable)

The problem I have is how to deal with the output variable. I think I cannot set the same output variable in both PIDs as they will write in the same variable. The PID in “auto” will write whatever it needs and the PID in “manual” will write something else, constant I guess. So that does not sound like a good idea.

Another option:
It seems that I can set the output of one PID as host. In this way I can tell to use the output of the other PID, the problem in this case is that I do not know how to configure that. The closest to do so will be to use SetPidOutput(PID_name,value), but this does not seem like the way to go, as with this function I can only set a value for the output of the PID, not a variable.

Any ideas on how to deal with this? Thank you.


#2

Correct, the brain will write both PID outputs to the physical output whether the PID is in auto or manual.

Yes, this would work - you will then set the other PID to manual and call SetPidOutput on that PID with the host value of the other. (You will never directly write to the physical output as the brain will write the PID output to it).

However, I think it would be easier to set them both to host and run some logic in your strategy to assign the value to your physical output.

You can also change the PID configuration on the fly, but will need to work with memory map commands for that.


#3

Thank you philip

SetPidOutput(PID_name,value)
This seems to be the only command I can use to set the PID output, but this set the output to an specific value.

Can I use the same function to output the PID output to a variable?
SetPidOutput(PID_name,variable)?


#4

If the PID is set to output to host, then you will need to get the PIDs output value using GetPidOutput(PID_name) and then assign it to your output, something like this:

if(nUsingConstantPower) then
  aoHeater = GetPidOutput(PID_Power);
else
  aoHeater = GetPidOutput(PID_Temperature); 
endif

#5

That’s what I was missing!!

Thank you again philip!