LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PID Control - analog input, digital outputs

I think I understand your goal, but I did take a look at the VIs you uploaded.  The first one needs some work to meet standard LabVIEW style.  There's no need for the property nodes (especially "Value (signaling)" since you don't have an event structure).  Wrap the code in a while loop and use shift registers to store values between calls.  Straighten out all the wires and simplify your logic.  For example, if the only thing that happens in a case structure is that you write to a DAQ output, and in the false case you write TRUE and the true case you write FALSE, get rid of the case structure, put a NOT in the boolean wire that previously went to the case selector and connect it directly to the DAQ Write.  All the extra complexity makes it hard to understand quickly what you're trying to do, and unfortunately I don't have the time to go into it in detail.

 

Your second VI is pretty much the example I wrote, except with an extra DAQ Write and at least one wire going to the wrong place which prevents the output from changing.  That's why I said you should put in some controls and indicators in place of the DAQ functions, so you can test it and out and really see what is happening.

 

Duty cycle is a percentage of the square wave cycle time (the inverse of the frequency input).  This is not necessarily related to your loop time, except that you need to run your loop much faster than you want to generate the square wave in order to get an accurate response.  When set up properly, the PID will take care of reducing the duty cycle as the process variable approaches the setpoint.

Message 11 of 54
(5,741 Views)

Thanks Nathan! I understand your concern regarding LabVIEW style and I will make the changes. This is not the final version.I usually clean up the program after I get the logic right. And also the redundant DAQ writes. I will make the change.

 

Regarding duty cycle, I still have doubts. Here is my understanding, correct me if I am wrong. If the loop iterates at 500ms, 20% duty cycle means that it is ON for 100ms and OFF for 400ms of the loop correct? So every iteration will have 100ms ON time. And this is how the square waveform is output on the wavechart I presume. Am I missing something here? I dont understand your statement "This is not necessarily related to your loop time, except that you need to run your loop much faster than you want to generate the square wave in order to get an accurate response. "

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 12 of 54
(5,736 Views)

Since a working demo is often worth 1000 words, play with this and see if it helps.  Note that it is a "snippet" - you can drag it directly into a block diagram (or you may need to first drag it to the desktop, and from there into a diagram, depending on your browser and operating system).

 

The square wave is generated at a fixed frequency, relative to the time input (in seconds).  The loop must run fast enough to get both the on and off parts of the square wave.  Put differently, if you try to run a 1hz square wave and your loop only runs at 1hz, the output will always be generated at the same point in the wave, and you'll never see a change in output.

Square Wave PtbyPt - PWM demo.png

Message 13 of 54
(5,731 Views)

Thanks Nathan! This really helps.

 

Quick question. The example PWN counter output looks a little helpful if I am able to turn a DO into a channel that can output a square wave which I think you taught me how to. But, I have a question regarding a calculation there .What is the significance of converting the error or output from Proportional vi to span (%). Essentially, a -100 to 100 is converted t0 a range 0 to 100%. What is the significance of this? I am having a really hard time understanding this concept.

 

A negative error will be in the range (0-50)% and a positive error will be in the range (0-100)%. If I were to use it in my application,I would think that a negative error ((PV-SP)*1) calls for action on the raise valve and a positive error call for action on the lower valve. I will change that vi and attach my understanding. Please guide me. Thanks!

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 14 of 54
(5,720 Views)

VeeJay wrote:

Quick question. The example PWN counter output looks a little helpful if I am able to turn a DO into a channel that can output a square wave which I think you taught me how to. But, I have a question regarding a calculation there .What is the significance of converting the error or output from Proportional vi to span (%). Essentially, a -100 to 100 is converted t0 a range 0 to 100%. What is the significance of this? I am having a really hard time understanding this concept.


I don't understand your question.  This is how proportional control works - the output is proportional to the error, and the ratio between them is the proportional gain.  Another way to say this is that you can think of the proportional gain as the slope of a line that relates the error to the output.  Since you are controlling a digital output which cannot vary continuously (it's either on or off), you instead use the controller output to modulate the amount of time the output is turned on, by changing the duty cycle.  Once you have the system almost working, you will need to tune it to find appropriate values for the controller gains.


VeeJay wrote:

A negative error will be in the range (0-50)% and a positive error will be in the range (0-100)%. If I were to use it in my application,I would think that a negative error ((PV-SP)*1) calls for action on the raise valve and a positive error call for action on the lower valve. I will change that vi and attach my understanding. Please guide me. Thanks!


This is about right.  The absolute value of the output will be the duty cycle input to the square wave generator.  The sign of the output will determine which valve to pulse (and make sure that you turn the other one off).

Message 15 of 54
(5,714 Views)

Thanks nathan! Please let me know if I am heading in the right direction.

 

The demo by NI on PID on youtube is what is confusing. Logically, I get the point. But, LabVIEW syntax is what I am not sure about.

http://www.youtube.com/watch?v=qMydcfZ_ZSs

 

The output is wired directly to the analog output, but the fan decreases speed. Is that because the error from the control algorithm is neagtive?One last question. Is the output from a control PID or any other PID effectively error? What form is this error? percentage, difference, some other form?

 

Turning to my application, even for the valves, What I want is higher duty cycle when the error is larger and lower duty cycle when error is lower. That is what I think I have accomplished in the attached program hopefully. Please review. Thanks! I didnt make any subvis to reduce amount of attachments. Also, vi is not organized completely. Thanks!

I may not be perfect, but I'm all I got!
0 Kudos
Message 16 of 54
(5,707 Views)

I think I am used to calculating error as error = (PV-SP)/SP * 100. I think that is where I am making a mistake. Would you think so too?

I may not be perfect, but I'm all I got!
0 Kudos
Message 17 of 54
(5,704 Views)

The best way to know if you are headed in the right direction is to TEST YOUR CODE.  I will suggest yet again that you replace the DAQ Read/Write with controls and indicators, and see if the output matches what you expect.

 

The logic doesn't make sense - why are you dividing by the setpoint?  Assuming that for some reason you do need to divide by the setpoint, don't use a property node, wire it directly to the terminal.

 

You can simplify the time input to the Square Wave function - just use the output from "Wait until next ms multiple."  However, you will need to divide it by 1000, as the output from that function is in milliseconds, and the square wave function expects the time input to be in seconds.

 


VeeJay wrote:

The output is wired directly to the analog output, but the fan decreases speed. Is that because the error from the control algorithm is neagtive?One last question. Is the output from a control PID or any other PID effectively error? What form is this error? percentage, difference, some other form?


I haven't watched the video, so no idea what you're asking there.  Also, if you cannot answer your second question, you need to spend some time looking at a textbook on PID.  The math is simple, which is one of the advantages to PID control.

Message 18 of 54
(5,700 Views)

Dividing by setpoint is calculation of relative error. If error is high in percent I use that value as duty cycle to bring my PV toward tolerance band. I am trying to use indicators instead of DAQ writes, but the waveforms are not what I want to them to be. Or maybe, there is something in the loop time and frequency of square wave that I am making a mistake in.

 

All I want it is to modify the duty cycle on the square waveform based on the error. 😞 My mind is not functioning. I will send you an update soon. You are the only person helping me here. And there are not many of these kind of examples/tutorials out there. 😞

I may not be perfect, but I'm all I got!
0 Kudos
Message 19 of 54
(5,697 Views)

Attached is with indicators and controls. This is exactly what I want, but I am sure with the dynamics of my system, I would need to incorporate PID instead of just Relative error calculation. But, this is a start. Please review and thanks a bunch. The square wave thing is pretty cool. 🙂

I may not be perfect, but I'm all I got!
0 Kudos
Message 20 of 54
(5,693 Views)