From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing multiple FPGA PID loops

Solved!
Go to solution

Hello,

 

I am designing a PID controller for each of the three axes (X, Y, and Z) of a piezoelectric stage using the FPGA module and a cRIO. I used the example project "Using Discrete PID - cRIO.lvproj" (labview\examples\control\pid\fpga.llb\CompactRIO) as a starting point, and I basically added two more PID loops on the FPGA VIs for the other two axes. I can get the controller to work  for one axis at a time (in simulation mode), but whenever I try to run all three controllers simultaneously, only one of them works. In order to synchronize between the host and FPGA VIs, I used three interrupts for each of the PID loops, but it seems like only one interrupt works when I run the code... Any idea how to synchronize the three PID loops with the host VI?

 

Regards,

 

Shin

0 Kudos
Message 1 of 15
(4,063 Views)
Solution
Accepted by topic author watashin

I think this is expected behavior, per the documentation: "The Interrupt VI is a shared resource, so multiple uses of it induce additional delay and jitter due to arbitration." If you're waiting for the interrupt to be acknowledged, then the other loops can't continue because the interrupt VI can't run. On the FPGA, if you want all the PIDs to run at the same loop rate, put them all in the same loop and use only one interrupt. Or, use some other synchronization mechanism (set a boolean from the host, wait until it's set and then clear it on the FPGA). The interrupt is only there for simulation purposes anyway, since the "plant" is running on the host. In a real system the plant runs continuously and the FPGA directly reads the sensors and drives the outputs, so the only value provided by the host is the setpoint and there's no need for synchronization.

Message 2 of 15
(4,056 Views)

Thank you for the reply! I somehow just assumed that having multiple PID controllers equals having mutiple loops... I put everything in one loop using only one interrupt and now all three controllers are working perfectly.

I also have a quick question regarding the PID FPGA VI; Is there any way to increase the precision of the PID gains? E.g. somehow change the terminal data type from 8 bit integer length to 5 bits? I am sorry if this question belongs to another disccussion forum...

0 Kudos
Message 3 of 15
(4,052 Views)

No, you can't change the datatype of the PID gains. Remember that the PID gains are not the same as the values you would use for the standard (non-FPGA) PID function; see the help for the conversion if you're not already familiar with it. You can always scale your values (input or outputs) to maximize resolution.

0 Kudos
Message 4 of 15
(4,041 Views)

The problem I am having is that the value of Kp is around 0.01, which is only twice as large as the maximum resolution of a <+/-16,8> fixed point data type. So even if the input has good resolution, the output can be very off...

0 Kudos
Message 5 of 15
(4,023 Views)

What if you add a little math so that the PID output is a percentage of full-scale output? Or you can scale up the inputs by a factor of 2 as necessary, then scale down the outputs by the same amount to maximize the available resolution, although you will need to recompute the gains.

0 Kudos
Message 6 of 15
(4,015 Views)

But scaling the input and output doesn't affect the values of the PID gains, right?

I actually added the small P gain just because the FPGA PID vi needs a non-zero value for Kp... My controller is basically just an integrator. Is there any built-in FPGA VI that acts as an intergrator, or would I need to make my own integrator?

0 Kudos
Message 7 of 15
(3,991 Views)

Sorry, yes. You could scale either the inputs or the outputs, then scale the PID gains to match - but don't scale both the inputs and outputs. For pure integration, there is the Discrete Normalized Integrator VI. I'm not sure how the FPGA PID is implemented, but I don't see anything in the documentation that suggests you can't use it with proportional gain set to 0 since the gains are specified independently, so long as you're specifying the gains on the block diagram and not in the Express VI configuration.

0 Kudos
Message 8 of 15
(3,987 Views)

For the PID (FPGA) Express VI, If I put a value of zero for Kp, then the Ki and Kd values also become zero no matter what my values for Ti and Td are, because Ki = (Kp * Ts) / (Ti * 60) and Kd = (Kp * Td * 60) / Ts. I will try scaling the input and then the PID gains, thank you for the help again!

0 Kudos
Message 9 of 15
(3,964 Views)

Those conversions are done when you enter PID gains into the Express VI configuration dialog. However, if you supply your own gains on the block diagram, the wired values are used directly, as explained in the help. So I would expect (sorry, can't test right now) that you could wire a proportional gain of 0 and a non-zero integral gain, and it will work. Is that not the case?

0 Kudos
Message 10 of 15
(3,958 Views)