LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I query analog output of FPGA 7831?

Solved!
Go to solution
 
0 Kudos
Message 1 of 11
(3,720 Views)

Siexto,

 

You could either simply wire the output signal into one of the available input channels and poll it there or keep track of what you write to the outputs.
Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
0 Kudos
Message 2 of 11
(3,704 Views)

Robb,

 

Thanks for your response.  I apologize for not elaborating on the problem when first posted.  Let me explain a bit more...

 

I am using a 7831 RIO to control four (4) analog controlled power supplies.  I do not have feedback from the power supplies to determine what voltage they are outputting so I have to approximate this by querying the output of the 7831.  I do this by opening a reference to my FPGA VI and then get the value of the particular channel with a FPGA read/write control node.  The problem is that this is not working in my main host vi. The function will return the correct value once if I manually run the vi to get the analog output after running my main host vi.  If I call it a second time it again returns a zero value even though I can check that the output voltage is set correctly and the device is outputting.  I am attaching my project.  The main vi is called SetStrofioVoltages.vi and the vi to get the analog output is called GetAnalogOutput.

 

Thanks for your help.

0 Kudos
Message 3 of 11
(3,694 Views)

Siexto,

 

The read/write control will poll controls or indicators on the front panel of the FPGA VI, so you must have this data published to the front panel first. Then, we have to make sure the VI is running. Does your open FPGA reference in your host vi have the 'Run VI' checkbox selected? What exactly is the indicator you are reading? If everything is built correctly, you should not have to manually run the FPGA VI.

 

I don't have any of your VIs, so I cannot comment on if you are doing it right or not.

Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
0 Kudos
Message 4 of 11
(3,689 Views)
I don't think the attchment worked.  Here are the files without the rest of the project.  I am not including the SetStrofioVoltages vi after all because it is the vi that sets the analog output on the 7831 and I don't think it has anything to do with getting the output of the 7831. 
0 Kudos
Message 5 of 11
(3,687 Views)

Yes, the Run Vi checkbox is selected in the open FPGA reference.  I am including the vi that reads the analog values and converts them to voltage values.

 

 

0 Kudos
Message 6 of 11
(3,682 Views)

Rob,

 

Also, note that I am able to read the correct value of the output channel after my SetAnalogOutput vi runs, but only once.  After it is read correctly (once) it returns values of zero on subsequent calls.  I want to query the analog output before I set the voltage in SetAnalogOutput because I cannot be guaranteed that the initial voltage is zero (ususally it is not).

 

Thanks again,

 

Stephen 

0 Kudos
Message 7 of 11
(3,677 Views)

Stephen,

 

I think we can improve your data flow here. Basically, when you poll the  'AO data' cluster on the FPGA...we have no guarantee that those values have been written to the boards yet since you have a boolean 'Output?' that enables them. You cannot write and read from a control value that we are not sure has been flagged to actually be written to the outputs.

 

My suggestion:

 

First off, initialize your outputs. It is true that you don't know what state they will be in when you initially run. This can be bad...try and set them all to zero in the first step of a case structure with some new IO nodes. Put your loop into the second frame of the sequence structure.

 

Next, create an indicator in each case for each channel...that way those indicators arent updated unless we put 'Output?' to true...then those values are passed and it should mimic your FPGA outputs. Do not pull the control since we dont know if it has written or not when we poll.

 

Finally, depending on what you want to do, you may want to make your FPGA 'output?' controls set to mechanical action 'latch'. This would allow them to write one value and then wait for the next command. Of course, you may want them always enabled as they are coded now if you plan on passing a lot of data in succession like a specific waveform. I didnt look too much in the host VI's so I cant comment on which is 'best' for your app.

Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
0 Kudos
Message 8 of 11
(3,642 Views)

I found a solution to my problem but it doesn't use the best programming practices.  My host vi does not run in a while loop.  It has to set 6 power supply voltages based upon an optimization routine that is calling it.  Four of the power supplies are analog controled by the analog outputs of PCI-7831.  The host code was opening the FPGA reference for an analog supply, polling the analog output using the read/write node and then changing the voltage to the new value.  It then closed the FPGA reference and repeated for the other analog supplies.  This seemed like it should work but the Analog output always returned zeros when the host vi ran.  If I ran my subvi manually to poll the analog outputs after the host vi finished executing, it would return the correct values.  But if I ran it again, it would then give me zeros again even though the 7831 Analog outputs were still set.  I did some testing and found that I could get the correct values only if the FPGA reference remained open so I decided to never close the reference.  This know works however I do not know why I have to do it this way and it does not seem correct to never close the reference. 

 

I also have a separate issue.  I would like to run the host vi without having to open the project so that it can be used as a subvi in someone else's code.  Is this possible?  

0 Kudos
Message 9 of 11
(3,618 Views)
Solution
Accepted by Siexto

Siexto wrote:

This know works however I do not know why I have to do it this way and it does not seem correct to never close the reference. 


When an FPGA VI reference is closed, if you right click there is a checkbox for 'Close and reset if last reference' or simply 'Close' Of course, this will reset all the values you have written. Try and not leave references open, that is just asking for memory leaks.

 

 


Siexto wrote:

I also have a separate issue.  I would like to run the host vi without having to open the project so that it can be used as a subvi in someone else's code.  Is this possible?  


You will have to hardwire the resource name in on the Open FPGA reference (ie RIO0) and also target a bitfile saved somewhere on your machine. Be careful if you have multiple RIO devices...since then you will need to know which RIO is which.

Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
0 Kudos
Message 10 of 11
(3,612 Views)