From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case Structure/ While loop issues

Solved!
Go to solution

Hello,

I am trying to write a code that plots a random number everytime a button is pressed.  The graph should be the random number on the Y-axis and the number of times the button is pressed on the X-axis.  I want to plot the last twenty random numbers.  I am using a while loop and a case structure.  If the button is pressed, the case structure incruments the number of times the button is pressed and generates a random number.  I am using shift registers to keep track of the last twenty numbers generated.  When the button is not pressed, the shift registers update the values incorrectly.  My code is attached to this question.  

 

I know wiring the last value of the shift registers to the case structure will change the array to all of the last value when the button is not pressed.  I know what causes the issue but I am not sure how to fix it.  I would appreciate it if you have a look at it and give me some tips.

 

Thanks in advance. 

0 Kudos
Message 1 of 5
(3,036 Views)
Solution
Accepted by MoAgha

Your problem is that the loop is continuously running and your values in the shift register are being overwritten when you are doing nothing.

 

There are a few ways around this.  The simplest would be to use an Event Structure.  Another option is to just store your array in the shiftregister.  Use Rotate 1D Array and Replace Array Subset to update your array.  This is a little more robust and easier to use than using the history option of the shift register.

 

But the absolute simplest, based purely on what you have told us, is to just use a chart instead of a graph.  A chart keeps a history.  The default history length is 1024 samples, so you will want to reduce that to 20.  Then you just wire your random number straight into the chart and everything is done for you.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 5
(3,020 Views)
  • Since your x values increase linearly, you can use a plain chart. No need for an xy graph.
  • The terminal of the graph belongs after the case structure, eliminating the local variable.
  • same for the "appended array" indicator.
  • The OK button 3 belongs before the outer case structure, eliminating the local variable. now you can set it to latch action. (Switch until release is dangerous, because it might not register if you release it too early).
  • Instead of resizing for a gigantic shift register history, use a FIFO array in a plain shift reister.
  • The build xy graph express VI is not needed.
  • You have several output tunnels set to use the default if unwired. This will reset your shift register value. You probably want to wire most of them across unchanged.
  • Try to use an event structure instead. Much simpler!
0 Kudos
Message 3 of 5
(3,012 Views)

the same problems

 

IA 24 * 19 array populated by an array of fixed positions calculated CASE judge after then as a display case from the outside but I'm looking to fill up to 24 x 19 array of value there is only one value changes how design can make all the specified array value of the position of all the changes it

0 Kudos
Message 4 of 5
(2,767 Views)

Store your array in a shift register and use Replace Array Subset to update specific elements in your array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 5
(2,742 Views)