Jump to content

Holding results from a Case Structure


Recommended Posts

HI all,

 

This is my first post ,so take it easy.

I need to hold results from an array that is being indexed from a For loop into a Case structure. I am very much a beginner in LabVIEW. Below is a screenshot of my project. Any advice is greatly appreciated!


Also, anything other than the numbers 0-7 are defaulted to 8 which I am using as an error feature.

post-54541-0-64780300-1458075293.png

Link to comment

Listen noob...

 

 

This is my first post ,so take it easy.

 

Oh...let me start again...

 

What is your problem?  Because reading your post it doesn't seem like you have any question.  You state you have an array of numbers, and you are indexing each one, one at at time.  Each element goes into a case statement, and then one of N things happen, based on the value of the that indexed value.  So what isn't working?  Your title doesn't reflect your post.  You are asking about holding a value in the title but not in the code.

 

One thing you might be asking is why is your output only one value?  What I mean by that, is you give it 8, 5, and 4, but your output only shows a value for 4.  The reason for this is because your loop runs 3 times as it should (by the way you don't need the array size and wiring to the N terminal, that is only needed if no arrays are indexed)  But even if your loop runs 100 times, the output of the loop is always going to be the values returned from the last run, and that is because your outputs (the booleans) are scalars, not arrays, and the output tunnel is not being indexed.  If you want every boolean value returned, right click the output tunnel and enable indexing.  But now you have N booleans being returned but you can only display one (since your boolean on the front panel is just a single boolean) so what you might want is to add an Or Array Elements, which takes an array of booleans, and if one or more are true, then it returns a scalar true.

 

There are of course easier ways of producing this same output.  Like the attached code which does the same thing, but in a more scaleible way.

 

post-6627-0-61243000-1458079214.png

 

You probably have seen these links before but here is some free LabVIEW training links if you have some fee time you should check them out, especially the introduction videos.

 

NI Learning Center

NI Getting Started

-Hardware Basics

-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)

-LabVEW Basics

-DAQ Application Tutorials

-cRIO Developer's Guide

 

Learn NI Training Resource Videos

3 Hour LabVIEW Introduction

6 Hour LabVIEW Introduction
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training

Link to comment

Sorry about that I thought the title of the post was the question. The question is how to keep the previous result of the case structure to carry over to the next iteration through out the whole array. Overall I need to accumulate the array into the led results. I am making a k-map.

Edited by COkids
Link to comment

How are you creating a K-map from an array of numbers?  I assume each bit represents the state of a variable.  Are they being OR'd, AND'ed, XOR'd? How do you know how to build your map from the array?  What statement are you trying to map?



ETA:
Also, did you know you can make a 2-D array of LEDs on your front panel by dropping an Array control (ctrl-space "Array"), then placing an LED control inside that control?  This way your K-map will be a nice grid, but you will have to address the array through the array tools (build array, replace array subset, etc...).

if you make a 4x2 2D array of booleans on your block diagram (place an array constant and boolean constant inside that, or use "Create array" with a boolean input, then drag the "size" section down by 1 and wire a constant of 4 into the first size input and 2 into the second), you can address individual cells of that array, and set new cells each run through the FOR loop.  Use Shift registers to hold data from loop to loop, and 0-indexing to address the correct LED (e.g. ABC' would be 2,0; A'B'C would be 0,1).  Now all you need to do is change from numbers to indices and you have your built map.

Edited by Chris_Collier
Link to comment

Currently I am simplifying from by the equations by hand. All that is needed is to display the k-map based upon the hand simplified equation, as a sum of products. Also, the numbers in the array are the bianary value of the corresponding inputs.

Edited by COkids
Link to comment

The question is how to keep the previous result of the case structure to carry over to the next iteration through out the whole array. 

Well think of running your VI, similar to running a program for the first time, then closing it after the VI is done.  So when you open up a new copy of Word, how does it know what your recent documents were?  Well it can't just keep it in memory, because it is a new execution, unless it writes some data to a place on disk that will be maintained between runs.

 

But a more simple way to accomplish this, is instead of using the Run button to do a new calculation, which again will run once, then stop, similar to running a program and exiting it, you can instead wrap the whole VI in a while loop, so the program keeps running until you tell it to exit.  This is basic application design in LabVIEW, and while there are some work arounds, like reading and writing to local variables between runs, this design is not the appropriate method.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.