05-08-2019 08:27 AM
Hi,
I am trying to create a program a simple reaction time program that displays a boolean on screen for the user after an X amount of time. The user performs an action (button press) when the LED appears. The features of the program are:
1) Has 3 AI channels - biosignal, button device, and input from the AO channel
2) Has 1 AO channel - this will trigger an external stimulator device and also trigger a change in the third AI channel (0 to 5V)
3) Once the third AI channel has changed to 5V, the boolean appears and the program stops after a few seconds.
I can't seem to get the boolean to appear and am not sure I am monitoring (or even programmed this correctly) and I am looking for some help. The specific MH state is "SRT Predictable" and "SRT Unpredictable". I have looked around but haven't found a solution that fits exactly what I am looking to do on the forums. This program is a subVI within a much larger program so I have only attached the subVI.
Any help would be greatly appreciate. Thanks in advance.
Anton
Solved! Go to Solution.
05-08-2019 10:48 AM - edited 05-08-2019 10:53 AM
Ok, so I'm not sure this will solve your problem but let's start with some simpler points - maybe from there we can work this out.
Moving to less certain things:
As an additional point, if you have the same code for the predictable and unpredictable cases except for the number of samples of 0 to generate for the AO, consider generating that value then moving the rest of the code into a separate state that actually runs the experiment. This will reduce a lot of duplicate (and possibly complicated) code, and simplify both maintenance and reading (for example, you in 3 months or me right now 😉 )
05-10-2019 11:44 AM
Hey cbutcher,
Thanks a ton for the feedback. I am working through your suggestions and need a few clarifications.
When you trigger the Exit case in the caller, the While loop also finishes. As a result, it never calls the Exit state in the "Count Samples.." VI.
In the Count Samples VI, it looks like you're checking if the sum of a bunch of values is greater than 5. Are you sure that
How many samples are you expecting in the While loop (from the AI tasks)? I can see you're writing 1 value at the bottom of the While loop, and that the sampling on that channel is driven by the AI task, but you didn't wire a number of samples to acquire to the top task, and probably you'll hit an error at some point with the non-regenerated AO if you're acquiring lots of samples (which you might be, since your loop might be slower than your sample rate and you could be acquiring multiple samples at AI when you don't specify size.
Thanks again for all the help.
Anton
05-10-2019 07:45 PM
Here's a picture that might describe what I mean a little better.
If you create a simple system with two VIs, one as a "FGV" and the other calling that function, you should be able to see that if you pass the "data" (not enum controlling action) into the FGV, it loses its ability to have memory. This is described more here: Building Single-Execution Uninitialized Shift Registers. Figure 2 and 3 in the basic concepts for SRs (http://www.ni.com/getting-started/labview-basics/shift-registers) also demonstrate this functionality/issue.
@atrinh wrote:How many samples are you expecting in the While loop (from the AI tasks)? I can see you're writing 1 value at the bottom of the While loop, and that the sampling on that channel is driven by the AI task, but you didn't wire a number of samples to acquire to the top task, and probably you'll hit an error at some point with the non-regenerated AO if you're acquiring lots of samples (which you might be, since your loop might be slower than your sample rate and you could be acquiring multiple samples at AI when you don't specify size.
- This is one concept I have always seem to have difficulty with. In the example vi, I would imagine it is a multiple of 2048 x 3 (SampleRate x duration). This number could change depending on the what the user inputs for SampleRate or duration. Do you have any suggestions for making the input for samples to acquire dynamic and appropriate to the user input?
I usually find that the simplest thing for me to do is decide on a loop rate (in your description quoted here, it sounds like you want this to be one second, which probably isn't true because you're also modifying the Visible property in the same loop.
Your task configuration VI, "3Ch Config DAQmx Logging RT v1.0.vi", has a sample rate output. You can use that (along with an appropriate divider, maybe 100 or 50?) to work out how many samples you want per loop. Wire that to the blue "number of samples per channel" input to your Read to specify how large the output array should be (you'll need an integer, so consider rounding up/down).
If you want to have (random*2*sample rate) zeros, followed by a 5V output on your DO, consider just appending 5 to the array you write before starting, and removing the Write inside the loop. I *think* that would have the same functionality. The sample clocking is controlled by the AI.
05-14-2019 10:30 AM
Thanks for the feedback and clarification. I redid my FGV and I think it is operating correctly now. Also, I rechecked what the FGV was comparing the threshold value to and it turns out I didn't have that right either. That has been corrected now as well.