Counting only once when a case structure is true in a while loop
Hi. First time posting here so do pardon me. I have tried searching for answers in the forums along with attempting the solution myself but to no avail.
Here is the problem. I am trying to collect voltage signals via the DAQ assistant. When a certain threshold voltage is reached, the "true" case would run. I am currently using the shift register along with the while loop hence the output number "numerical 2" would increase as the while loop runs. However, I only want to register a single case as long the voltage is above is above the threshold.
Eg. When the voltage is above 3V for some time, it registers only a 1. Then the voltage might dip below 3V. The next time the voltage is above 3V again it would register a 2. So on and so forth. I have attached an image of my block diagram below. Thanks for the help!
Solved!
Go to Solution.
Keep the status of the threshold reached in a shift register. Perform an AND with the inverse of the value in the shift register and your new threshold detection. The result of the AND goes into your case structure.
EDIT: I just threw together this example. I used a Feedback Node since it would be cleaner.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
Threshold Count.png 12 KB
Similar Messages
-
Cluster value lost when leaving case structure
Hello all,
I am having an issue with a particular VI I am working on. (FYI this is in Labview 8.0)
The VI is set up to run a current source, voltmeter, and thermometer and then record and graph data in various ways that are selectable by the user.
Everything seems to be working fine except one particular graphing method. When I try to graph Current vs. Voltage, the current value is gettiing lost. Within a case structure the current and voltage are combined into a cluster and then exit the case structre to be later appended to a cluster array.
However, the value of the cluster is being lost when the graph is set for Current vs. Voltage. Any other method and it is working properly.
I can't seem to figure out why this is happening as it does not make much sense that the other methods of graphing work but this one doesn't when it is coded the exact same other than having different variables.
I have attached the VI with added indicators showing that the cluster value is being lost once it exits the case structure. Any help would be much appreciated.
Thank you very much and I apologize for my extremely messy VI.
- Nathan Cernetic
Solved!
Go to Solution.
Attachments:
IV-RT.vi 185 KBYou really need to boil this down to something we can run and reproduce the issue.
Have you tried to break a few relevant connections and rewire? Maybe something is corrupt.
Beside being a mess, your VI has quite a few glaring mistakes.
Let's have a look at the structures in the upper right:
90% of the code is the same in all three case structures, so all that needs to be inside the case structure is the small part where you built the 2D array. Everything else belongs outside the case.
The sequence structure has no useful function.
Why do you need to reverse the array with each iteration of the small FOR loop? Once before the loop would be enough. Right?
Why do you use built array inside the small FOR loop, but don't autoindex at the loop boundary? All you ever get is an array with exactly one element, no matter how much the loop runs. Seems useless! (see below image for an alternative).
You would not even need to reverse if you would use "built array" instead of "insert into array at position 0" in the central part.
Others: You constantly hammer all your property nodes. The only need to be called when things change. Again, you have way too many instances. For example in the case structure where you are having problems, the same property nodes exist in all cases. A single instance of the property node belong outside the case and only the string constants inside each case. Whenever code is the same in all cases of a case structure, that code belongs outside!
Message Edited by altenbach on 06-19-2009 03:39 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
RubeLoopII.png 10 KB -
Occur only once when it's true
Hi,
I know my title is quite similar to other one, but I've almost read all the post about this, tried the several methods suggested in the other post, but I don't succed to solve my problem, in each way, the same problem happens.
I've got a condition "In the fly in the area" which send "True or False".
What I would like, is each time it enters the area, so it goes to false from true (or opposite), it adds +1. (If it counts also +1 when it goes outside the area, it's not a problem, I can divide by 2 then round.
So here is what I did :
With this code, when the fly is on the area, nothing happens ==> good
When the fly join the area (condition is true), it adds +1, then again +1, again +1 all the time the fly is on the area so it goes to something like 10-100 while it should stay at 1. Then if it enters again, going to 2.
What I would like, is that it only add +1 ONCE it's true, and I really don't understand what I'm doing wrong.
Thank you very much.
Sébastien.
Solved!
Go to Solution.This is what I mean. If you right-click on the tunnel, there's a menu to link the tunnel to another. You need to keep your status through all of the cases. So they need to have the value wired through. If you link the tunnels, then when you create a new case the vlue will automagically be wired through.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
Link Tunnels.PNG 9 KB -
How can i set case structure always true on boolean impulse?
Hello everyone! I need a little help. All i want is to set a condition when to acquire data from my acquisition board. I have a sinusoidal pulse and when value its near zero (between 0.5 and -0.5) i want to start to write data and also stop condition. How can i make my case structure to remain set to true until next condition? Thanks in advance!
Attachments:
Untitled.png 104 KBsdadasdas wrote:
Thank you! I'm a beginner in labview and any advice is welcome!
I highly recommend tutorials if you are really new. Otherwise, just keep asking questions. You'll figure it out soon enough.
3 Hour Introduction
6 Hour Introduction
LabVEW Basics
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training
Learning NI
Getting Started with NI Products
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Executing code from a Bean only once when page loads
Hi all,
I have a method in a BackingBean which access UI Bindings from my fragment: xxx.jsff.
So that method has to be invoked from a inside that fragment since access Bindings from xxxPageDef.xml
I need to execute that code one and only one time when that fragment loads.
What is the best approach to my case????Thanks Pino for your reply.
Since the fragment does not have OnLoad event, I have no option than to find a work around.
That is exactly what I am doing.
I have a PageFlowScope variable which is set to true or false depending if I have input parameter value or not.
That variable is re-sated when the user pressed a button.
The problem was where to stick to code that will disable components if needed.
So I used one component and in its Rendered method I put the code that will disable components if needed (based on my PageFlowScope variable value).
Works perfectly fine, but it would be much nicer if there was more natural way of doing it (with OnLoad event on fragment).
Regards. -
Once I have sent an email I cant switch my case structure back to false
This may be a stupid question because nobody else seems to have had a problem with it, so sorry if this is the case.
Using the email Vi example provided with Labview, in a case structure, when the case structure goes true, it stays true as soon as the email vi is running, even after it has sent the email.
Is there any way to stop it or does it need a specific timeout period?
My very simple example is provided.
Thanks for any help
Alexi
Attachments:
mailtest[1].vi 28 KBalexi wrote:
> This may be a stupid question because nobody else seems to have had a
> problem with it, so sorry if this is the case.
>
> Using the email Vi example provided with Labview, in a case structure,
> when the case structure goes true, it stays true as soon as the email
> vi is running, even after it has sent the email.
>
> Is there any way to stop it or does it need a specific timeout period?
> My very simple example is provided.
Are you sure hotmail.com has an SMTP server running? I really doubt
that. Or even if it does you may not be able to contact it, as most ISP
block outgoing port 25 on their network to reduce problems with virus
hyjacked boxens spamming the internet. Don't blame him, it is a very
sensitive thing to do.
If one of these p
roblems occurs the Open TCP Connection function will
timeout after 60 seconds and return with an error 56, network timeout.
You will probably have to use the SMTP server of your ISP to send the
messages to and this server will further send it to the correct receiver
even if that one is on hotmail.
Rolf Kalbermatter
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
Execute case structure only once
Hi everybody.
I want to execute a case structure inside a while loop only once. The case strucutre is controlled by a counter, so that every time the counter has a value multiple of N, the program records an acoustic signal and calculate the main peaks of the FFT. The problem I have at the moment is that, every time the case is executed, it records and analyze the sound several times until the counter jumps to the next value. I want the case to execute only once every time the counter has a value multiple of N. I atttach the vi.
Thank you for your attention guys!!!
Attachments:
Pulsations2.vi 243 KBGERD is right. You should use a feedback node to store the previous count value. If the current count is Not Equal AND the remainder is Equal To Zero run your case.
Since your counts are all integers, I would also recommend changing the representation to an integer type. I32 would likely be the most appropriate.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Multiple booleans controlling one boolean input for a case structure
Hello,
I have four boolean buttons and a case structure with a boolean input. I would like to write the program so that whenever any one of the four boolean button changes value, the case structure reads true for one loop interation, and then returns to false.
I have tried all sorts of things and can't seem to figure it out.
Ultimately, the ideal function of the program is so that whenever you push any one of the four boolean voltage controllers, that voltage case is chosen in the case structure, the time in seconds is written to a file, and the elapsed time timer is reset.
I have attached my program. Let me know if you have suggestions. Thanks.
Attachments:
Volt_Control_And_Time_Counter.vi 71 KBZappow wrote:
However, with this setup, the time counter still doesn't work.
The event structure for all four buttons has a true boolean constant connected to my file-saving case structure. If I connect this to my elapsed time express VI reset button, the timer doesn't count.
The timer does not count because you have not wired a timeout to the lower event structure. The default timeout is -1, so the lower loop never spins via timeout
It is useless to have a wait in a loop that also has a timeout case. Just wire an approriate timeout value to the timeout terminal and remove all waits. It is also not necessary to have a 1ms ttimeout if your timeout values only displays to 100ms resolution. Can you explain why you think you need two loops and all that extra code?
Attached is a quick rewrite that solves some of the problem. Since I don't have any hardware, I replace the voltage out with a meter.
You have way too many FP controls and indicators. Use arrays!
Let me know if yo have any questions. Modify as needed.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
Volt_Control_And_Time_CounterMOD.vi 63 KB -
Hey everyone
I am currently a physics student and for my final year project I am building a mini CT scanner which involves the use of two stepper motors. I currently have a program working which controlls the motors but i am having difficulty in reversing the rotation. Unlike conventional CT scanners, I must rotate the sample. Would anyone be able to help me figure out how to automatically change the case structure form true to false in order to reverse the stepper motor and without stopping the program.
Many thanks
John
Attachments:
motor.vi 48 KBFrom this point, it is just a matter of figuring out what logic you want to be in place of that control.
You can go by the number of iterations and switch if you go beyond a certain count. You could go by your rotations completed. It is just a simple comparison.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Case structure run other case structure
HI all,
I have a big programme in LabVIEW, but what I want to do is very simple to describe with simple example on picture bellow.
I need to make that when 1. case structure will be true to start "second" case (but I also need to start second case manually with switch "START"). Is there any "property node" which will tell me when 1. case is on true?
If this exist I then only need to add "OR" boolean to second case.
I hope that is clear what I want to do.
Rookie; LV 2011 on WIN 7Switch when release will keep that switch set as True until you come back and switch it off yourself. Latch when release will keep that switch as true until the terminal is read by LabVIEW at which time LabVIEW will return the switch to false automatically.
Well I need button which goes automatically back to same position as it was after it was pressed, so I used "switch when released", it's also working with "latch when released". It's make no sense.
Case structure 1 will execute the true case as long as X=1. Are you saying that you don't want the True case of the 2nd case structure to continue to execute as long as X=1? Only execute on the first time that X becomes 1? If so, you will need a shift register or feedback node to keep track of that boolean wire and only execute the 2nd case when the boolean wire is True AND when the boolean wire in the previous iteration is NOT True.
Yes exactly that, I will try to use " shift register", so I can get previous iteration.
So I need gate which will do next:
wire | button | OUTPUT
1 0 1
0 1 0
1 1 0
0 0 0
Which gate must I combine to get what I want?
Rookie; LV 2011 on WIN 7 -
How to display field value only once in REUSE_ALV_GRID_DISPLAY
hi experts,
i am using REUSE_ALV_GRID_DISPLAY, for alv outpur display.but i want one of the field in output ,not to display the value which is of same, it have to be displayed only once, I mean i have a number which contains multiple line items corresponding, here i want to display the field value only once when it is repeating , for the same header number, how can i achieve itHi,
check the sample code,
REPORT Z_ALV.
Database table declaration
TABLES:
sflight.
Typepool declaration
TYPE-POOLS:
slis.
Selection screen elements
SELECTION-SCREEN BEGIN OF BLOCK blk_1 WITH FRAME TITLE text-000.
SELECT-OPTIONS:
s_carrid FOR sflight-carrid.
SELECTION-SCREEN END OF BLOCK blk_1.
Field string to hold sflight data
DATA:
BEGIN OF fs_sflight ,
carrid TYPE sflight-carrid, " Carrier Id
connid TYPE sflight-connid, " Connection No
fldate TYPE sflight-fldate, " Flight date
seatsmax TYPE sflight-seatsmax, " Maximum seats
seatsocc TYPE sflight-seatsocc, " Occupied seats
END OF fs_sflight.
Internal table to hold sflight data
DATA:
t_sflight LIKE
STANDARD TABLE
OF fs_sflight .
Work variables
DATA:
t_fieldcat TYPE slis_t_fieldcat_alv,
fs_fieldcat LIKE
LINE OF t_fieldcat.
*START-OF-SELECTION
START-OF-SELECTION.
PERFORM get_data_sflight. " Getting data for display
PERFORM create_field_cat. " Create field catalog
PERFORM alv_display.
*& Form create_field_cat
Subroutine to create field catalog
There is no interface paramete
FORM create_field_cat .
PERFORM fill_fieldcat USING 'Carrier Id' 'CARRID' '2'.
PERFORM fill_fieldcat USING 'Connection No' 'CONNID' '1'.
PERFORM fill_fieldcat USING 'Flight Date' 'FLDATE' '3'.
PERFORM fill_fieldcat USING 'Maxm.Seats' 'SEATSMAX' '4'.
PERFORM fill_fieldcat USING 'Seats Occ' 'SEATSOCC' '5'.
ENDFORM. "create_field_cat
*& Form fill_fieldcat
Subroutine to fill data to field column
-->p_seltext Column label
-->p_fieldname Fieldname of database table
-->p_col_pos Column position
FORM fill_fieldcat USING
p_seltext LIKE fs_fieldcat-seltext_m
p_fieldname LIKE fs_fieldcat-fieldname
p_col_pos LIKE fs_fieldcat-col_pos.
fs_fieldcat-seltext_m = p_seltext.
fs_fieldcat-fieldname = p_fieldname.
fs_fieldcat-col_pos = p_col_pos.
APPEND fs_fieldcat TO t_fieldcat.
CLEAR fs_fieldcat.
ENDFORM. " fill_fieldcat
*& Form get_data_sflight
Subroutine to fetch data from database table
There is no interface parameter
FORM get_data_sflight .
SELECT carrid
connid
fldate
seatsmax
seatsocc
FROM sflight
INTO TABLE t_sflight
WHERE carrid IN s_carrid.
ENDFORM. " get_data_sflight
*& Form alv_display
Subroutine for ALV display
There is no interface parameter
FORM alv_display .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = t_fieldcat
TABLES
t_outtab = t_sflight
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " alv_display
End of code -
Need help with case structures- please help :)
Hey all.
I'm currently trying to program a infrared furnace. I'm setting a temperature, subtracted my set temperature from the actual temperature (thermocouple hooked up to SCB-68), and voltage is being sent to the controller of the furnace accordingly. However, I need to hold the set temperature for a certain amount of time. I need help programming this: when the VI reads the set temperature from the thermocouple, it results in a timer running down. When the timer runs down to 0, the While Loop ends. I'm thinking case structures is most appropriate, but if you have a better suggestion, please let me know.
ThanksYou should probably implement a state machine.
The state machine would keep track of the temperature and making ajustments on a timely basis.
There is a template of a state machine is you select under the File menu > New > From Template.
You can also look under Help > Find Example > and do a search for state machine.
There are lots of state machine examples on this forum, some of which may be quite useful.
RayR -
Broken Arrow with Case Structure Input Selector
Generally We get a broken arrow when a case structure
is wired incorrectly to its case selector .
I found that even after this is fixed, the arrow remains broken.
however when you click on the broken arrow, the VI
starts to execute instead of highlighting the error.
Seems like a compiler Issue.
I want to know if anyone has faced this issue.
I am currently using LV 8.6
Regards,
Sundar.SUNDAR.N wrote:
Generally We get a broken arrow when a case structure
is wired incorrectly to its case selector .
I found that even after this is fixed, the arrow remains broken.
however when you click on the broken arrow, the VI
starts to execute instead of highlighting the error.
Seems like a compiler Issue.
I want to know if anyone has faced this issue.
I am currently using LV 8.6
Regards,
Sundar.
I can confirm that. I HAve seen it with type defs as well as LVOOP classes.
I have never been able to reproduce it on demand but it always seesm to be associated with situations where a type or class definition was changed. I think I have seen this issue on and off from LV 8.2 thru LV 8.6.
Ben
Message Edited by Ben on 07-31-2009 06:59 AM
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
AdfCustomEvent.queue() Fires Only Once
I have a server listener which has to be triggered on keyUp event.
function handlekeyUpOnUserInfoField(evt){
ownerInputcomponent = evt.getSource();
var enteredUserText = ownerInputcomponent.getSubmittedValue();
if(enteredUserText.length > 0){
alert(enteredUserText);
AdfCustomEvent.queue(ownerInputcomponent,"showUserPopup", {payload:enteredUserText},true);
evt.cancel();
The event AdfCustomEvent.queue is fired only once when I press the key, as I see the request being received at the server.
Any consecutive key up calls the java script as the alert shows the entered chars, but there is no event being received at the server.
Not sure why is this happening.Try to remove evt.cancel();
if it is not working
Try to use KeyUp instead of KeyPress? -
Enter and exit a case structure
I'm currently building a control. I have a condition for three booleans to become true to enter a case structure as true. One of the conditions is a temporary increase in temperature. I want to stay in the case structure after the temperature becomes false but both of the other booleans stay true. Is there a way to do this or should I be using some other technique?
Thanks,
ColtI think this guy is running into the same misconception I and many of my classmates ran into about LabVIEW back in the day. When your code enters the True Case, it will complete the True Case and immediately exit the True Case to complete whatever other tasks that may be outside of the Case Structure (assuming it didn't already do them). Then, the while loop (you must have a while loop) will move on to the next iteration, meaning it will do it all over again.
Now, if you know already know and understand how code works in general (about iterations) then do forgive me. I've edited a lot of student code and have seen this very mistake. A misunderstanding of the fact that code reiterates and will do it all over again if not told to do something else. Typically the mistake is made with Event Structures. I know it doesn't make much sense to not understand that...but trust me, it makes sense to those who don't understand. ha
Maybe you are looking for
-
My ipod shuffle 2nd generation is charging but not starting.
My Ipod shuffle 2nd generation 4 yrs old is charging when i connect it to the computer it blinks orange light then when i eject it, it shows green light. But afterwards when i start it nothing happens. It used to work very nicely before but now Its d
-
Macbook pro will not boot. I get the gray screen, an apple icon and spinning wheel. I tried to start in safe mode, but get this same screen. The only thing different is that I added the zedge update app to do a sync for adding ringtones to my apple c
-
IPhoto 09 (from iLife 09)
Up to my last upgrade to iPhoto 09 (offered online by Appple) iPhoto ran just fine on my G5, (PC chip - non intel). IMMEDIATELY after the upgrade, iPhoto will display all events and folder, BUT if I select PHOTOS. ie all pics), my G5 goes into a spin
-
Help please, I can only see outlines when I use the shape tool in CS5 ?
When I open action script 2 or 3 in CS5, and draw a rectangle or any shape, I can only see outlines? The problem IS NOT the outlines button that is in the layers palet as I have changed this many times and it has mad no difference and the problem IS
-
Master Contract configuration in Copying Control
Could u please give me a detailed process on defining the Master contact and what all the settings in the copy control - with their Usage (Like 303 is used for Header-Same Customer). However we can use Copy to Header-Different customer as well. So wh