05-31-2016 01:21 PM
I am using a cRIO for the first time (cRIO-9063) with 4 modules: 9375, 9213, 9205, and 9208.
The module I am concerned with now is the 9208. I want to read its analog inputs periodically (say 100ms) and add it to a running average. So I have a VI running on the PC that gets the value at 10 of its analog inputs every 100ms, but I seem to be getting duplicate values, which makes me think that the scan engine has not updated yet.
My scan period is 10ms and network publishing period is 100ms, so I am unsure why I am getting any duplicate values. Can you explain how I should set this up so that a new value gets updated at least every 100ms? Are there other settings I should be looking at? Thanks!
Solved! Go to Solution.
05-31-2016 01:42 PM - edited 05-31-2016 01:44 PM
From the sounds of it there is no real synchronization going on. Although the timed loop on the PC is set to execute every 100ms, the timing may change slightly from iteration to iteration....depending on how you are doing it. You might be catching the very beginning and the very end of one network publish period. From my understanding, network publishing type events can differ in their execution times from iteration to iteration as well.
To get a value every 100ms I would use the sync-to-scan engine VI described in the link below. That way you can tell something to happen every 10 scan periods.
http://zone.ni.com/reference/en-XX/help/371361M-01/lvioscan/synctoscanengine/
That being said, I do not have much experience with NI Scan Engine; normally I use the FPGA module to write whatever is needed. Writing the code I think makes it easier to understand synchronization between FPGA DMA channels and consumer loops on the host side. If you own the FPGA module it might be worth a quick read.
Corey
05-31-2016 01:48 PM
Thank you Corey!
I should mention that it is often more than one duplicate value. I am most often getting 10 values all the same, so 1 second's worth of data with no change in it...
05-31-2016 01:51 PM
Oh wow...yea seems like something else going on than just being out of sync, huh? Any snippets or code you can post?
05-31-2016 02:03 PM - edited 05-31-2016 02:04 PM
Here is a picture of the code that I call every 100ms to keep my running average. (I know pictures are less preferable than code, but it will take me a while to save copies and disconnect the typedefs). The SubVI that says "Get PD Curren" just bundles the 10 inputs together from the cRIO into an array. Below, you can see what values I got during the last ~1 second of run time. Each row corresponds to a different AI, and each column is spaced apart by about 100ms in time.
05-31-2016 02:06 PM
@Gregory wrote:My scan period is 10ms and network publishing period is 100ms,
I have not used the Network Publishing part of the Scan Engine. I like to keep my communications very direct: either use Network Streams or TCP directly communicating between PC and RT.
My suspision is that you have something in your RT that is keeping your Scan Engine from running. Are you monitoring the CPU usage?
05-31-2016 02:21 PM - edited 05-31-2016 02:24 PM
Yea, I dont see anything wrong either in the small section of code. I guess I missed you were going from RT to a PC host via network published shared variables. I haven't used those in a constantly polling type of fashion before so I dont know much about what you are seeing from that end. However, if you are polling 10X a second, every second maybe a network stream as crossrulz mentioned might be worth a look. They are relatively painless to use once you get the connection points made. From there they behave a lot like an RT FIFO. Then you can execute your loop everytime there is new data available, and not until then.
05-31-2016 03:06 PM
Have you looked at this article?
http://digital.ni.com/public.nsf/allkb/6E37AC5435E44F9F862570D2005FEF25
05-31-2016 03:51 PM
All I did to read inputs from the cRIO is drag the variables from the c-series module in the project explorer onto a block diagram (picture below), I don't know if this constitutes a "network published shared variable".
I will check the CPU usage on the cRIO. I did not create any VIs to run on the cRIO yet, so I expect it to be pretty low.
05-31-2016 03:58 PM
@Gregory wrote:All I did to read inputs from the cRIO is drag the variables from the c-series module in the project explorer onto a block diagram (picture below), I don't know if this constitutes a "network published shared variable".
I will check the CPU usage on the cRIO. I did not create any VIs to run on the cRIO yet, so I expect it to be pretty low.
Yes, the Scan Engine's network published attributes use the Network Published Shared Variable Engine. NPSVs are horrible about latency for many many reasons. I never use them in a real application. In this case, I would use a Network Stream.