Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

Sine wave for FPGA PID control

I'm trying to use a sine wave as the FPGA setpoint in PID control.  I knew I could use the Sine wave generation express vi on FPGA but it seems to me that there's no interface of that vi with the Host and the parameters of the vi can't be changed through host.vi.  How can I generate a similar signal on Host.vi use the point by point generated by the function as the input of the setpoint?  I tried waveform generation and signal simulation but it seems neither works well within the while loop.  Could you recommend me some workable and optimum strategies?  Thank you very much!
0 Kudos
Message 1 of 10
(9,589 Views)

I'm somewhat confused by the sample time on PID vi in FPGA.  I set sample time on PID(FPGA) function on FPGA vi at 0.001s, which in essence is 1kHz sample rate.  The count for loop timer is 0.1  us. 

However, on Host vi, I used a signal simulation function and set the frequency of the sine wave at 1000Hz and the sample rate is 10000Hz.  

To my surprise, the PID control works apparently very good as shown on the attached picture.  I'm confused by the point that if the signal frequency is 1kHz, and the sample rate of PID function is also 1kHz, the sample rate should fall well short of the required sample rate in order to control the signal acquired.  I think there must be some misunderstanding on the definition of parameters here.  Could you please help me clear it up?   Thank you very much.

Download All
0 Kudos
Message 2 of 10
(9,585 Views)

Good Evening soljiang,

 

You are correct that there is no way to change the parameters of this Express VI other than its configuration window.

 

 

Please elaborate on what you mean by...

 

it seems neither works well within the while loop.

What behavior / output do you see?

 

 

Have you considered generating the sine wave on the RT host and sending the individual values to the FPGA for output?  This is not the most efficient method, but will work for many applications.

 

0 Kudos
Message 3 of 10
(9,551 Views)

an as Thanks for your reply. I sent the following as an email so it could either be dealt through email for here on the forum. 

 

1
I'm trying to use a sine wave as the FPGA setpoint in PID control.  I knew I could use the Sine wave generation express vi on FPGA but it seems to me that there's no interface of that vi with the Host and the parameters of the vi can't be changed through host.vi.  How can I generate a similar signal on Host.vi by using "point by point" generating function as the input of the setpoint?  I tried waveform generation and signal simulation but it seems neither works well within the while loop.  Could you recommend me some workable and optimum strategies?

2
Also I'm confused by the sample time on PID vi in FPGA.  I set sample time on PID(FPGA) function on FPGA vi at 0.001s, which in essence is 1kHz sample rate.  The count for loop timer is 10  us.
However, on Host vi (PID without simulation 2009051916(Host).vi), I used a signal simulation function and set the frequency of the sine wave at 1000Hz and the sample rate is 10000Hz. 
To my surprise, the PID control works apparently very good as shown on the attached picture.  I'm confused by the point that if the signal frequency is 1kHz, and the sample rate of PID function is also 1kHz, the sample rate should fall well short of the required sample rate in order to control the signal acquired.  However, after I used a oscilloscope to detect the signal of the PID output, the signal is a sine wave with a frequency on the order of magnitude of 100 Hz and the sine wave is not perfect with lots of struggle.

3
Now I changed to use Sine Wave Generation function PtByPt on Host vi(PID without simulation 2009052012(Host).vi).  Another NI engineer once gave me an example about how to use this vi but I don't know what the Time parameter it specifies means.  It's basically the loop number times a number that's related to the frequency.  But the final output of the PID control is a bad sine wave (not clearly shown in the picture PIC3 but if you use a oscilloscope it's clearly not a well-controlled sine wave) with frequency of 500+/-50 Hz when I set the wave setpoint input at 100 Hz and the sine wave struggles a lot shown in oscilloscope and sometimes deforms completely. 

4
I constructed my vi based on the Using Discrete PID control example coming with labview.  So I'm also somewhat confused by the scaling function there and the converting function given by https://www.ni.com/docs/en-US/bundle/lvfpga-api-ref/page/vi-lib/rvi/analysis/control/pid/subvis/nifp...  After using the PIDGainScaling function, the feedin for the gains are converted into 16 bit number shown in PIC4.  If I feed that into the Gain parameter to FPGA, does the PID module in FPGA further use the converting formulas repetitively applied on the scaled numbers again?

 

In the email with the reference#7243918, I attached all the pictures and files.  

 

I know there are several questions at a time in this email but I would really appreciate your help if you could help me clear up these confusions.  I attached all vi's and pictures in the ZIP file.  Thank you so much in advance for your help.

0 Kudos
Message 4 of 10
(9,548 Views)

To clear up a bit more on the last question, question 4, I want to know if I set Kc=256 on Host.vi and send it directly to PID Gain(x2^8) input on FPGA write function, is the Gain in PID module on FPGA, that is the gain of the system, 256, or 1, or 256*256?  What confuse me at the moment is that if I connect the input and the output directly with a BNC cable, the system seems stable when I set the gain at 255 but goes unstable when I set the gain at 256, so I think it must have something to do with the scaling, the magic number os 2^8. 

PIC0-PIC2 are the front panel for setup with Gain at 255, 256 and 257

Also you can see that I wanted to show PV separately and analyse its frequency content (as shown in the second while loop in PIC3) but seems it doesn't work; the signal in the middle graph below is by no sense the same as the blue line in the chart above, also I don't know how to use PSD analysis in this case, which is different from the left graph below, connected to the sine wave simulation dynamic signal directly.

0 Kudos
Message 5 of 10
(9,532 Views)

Hi soljiang,

 

I would start by looking at some basic PID documentation such as this knowledgebase article as well as this one. Hope this helps!

 

Ipshita C.

National Instruments
Applications Engineer
0 Kudos
Message 6 of 10
(9,518 Views)
I understand these things on the websites you recommended. What my confusion is when do the parameter sent into the module undergo data conversion.
0 Kudos
Message 7 of 10
(9,516 Views)

Hi soljiang,

 

I understand you already have an email service request open with National Instruments on this issue. At this point, I would suggest working closely with the applications engineer who is working on that service request.I have linked this forum to that service request. Thanks!

 

Ipshita C. 

National Instruments
Applications Engineer
0 Kudos
Message 8 of 10
(9,485 Views)

Hi all,

 

I have cRIO 9024, cRIO Chassis 9113, NI 9264 and NI 9203. I want to create an application which includes a sine wave generation with PID. My idea was to connect the sine output to setpoint, LVDT to process variable and PID's output to analog voltage output. But I think the idea is wrong because when I run vi, the cylinder goes to its initial point and does not even move a little, no matter what I do. I changed all the variables ( PID gains, output range, frequency of sine wave, amplitude of sine wave) but nothing happened. I can make a position control with PID and sine wave individually but I can't use them together.

 

Any idea will be appreciated.

 

Thanks.

0 Kudos
Message 9 of 10
(7,912 Views)

Can1985,

 

Can you expand on what you are trying to accomplish.  Are you trying to implement the PID in the real time code or are you attempting to use PID control on the FPGA.  Can you expand on what values you expect LVDT to return?  Also, what VI are you using for PID?  Finally, what are you overall trying to accomplish with this system and what do you mean by they worked individually but not together. After looking into the Service Request that was mentioned earlier in this forum, he was attempting to create a Sine wave from the FPGA and this document was able to help him.


Cheers,

0 Kudos
Message 10 of 10
(7,875 Views)