Elktro Posted June 27, 2008 Report Share Posted June 27, 2008 I have not been able to find a solution to how to initialize feedback node every time while loop executes so that the initialization is done inside the while loop. Global initialization will not work, of course. Basically I want to convert this C-code to LabVIEW code: do{ int num=0, num2;do { int abc = function(); if (num = 0) num2 = abc; num++; int num3 = num2 - abc; function2(num3); ...}while(stop()); ... }... function() has two restriction it can be called only once and it has to be in the inmost loop. Ilkka PS. What a crappy indentation feature! Quote Link to comment
ned Posted June 27, 2008 Report Share Posted June 27, 2008 It's often difficult to take C code and translate directly to LabVIEW because the two languages just don't work the same way. Also, I think your C code does not match what you wrote that it should do. In your comments you state that function() should only execute once, but you have written the code such that function() executes every time through the loop, and only copies the result to abc once. In LabVIEW you don't need the variable "num" since it's already provided within a while loop, at the "increment" terminal (the little i in a box). You can connect that to a case statement; in case 0 you run function() and in the default case you pass the value straight through. It would help if you post your LabVIEW code (or at least a screenshot) so we can see what you've tried to do, and comment on it more specifically. Quote Link to comment
Francois Normandin Posted June 27, 2008 Report Share Posted June 27, 2008 Well, from the part of your program you've shown, num2 doesn't change and will always be equal to abc. num3 = num2 - abc is therefore always 0... so function2(num3) is really while(stop()){do{function2(0)}}. But I see suspension marks which means num2 must change somehow as a result of function2. Here is the equivalent LabVIEW code for your program. It is not as you should do it, just a quick translation of your program as is. I suggest your get abc = function() out of the loop and initialize num2 with it. Then, remove the case structure as your variables will already be initialized. Quote Link to comment
Elktro Posted June 27, 2008 Author Report Share Posted June 27, 2008 QUOTE (ned @ Jun 26 2008, 03:19 PM) It's often difficult to take C code and translate directly to LabVIEW because the two languages just don't work the same way. Also, I think your C code does not match what you wrote that it should do. In your comments you state that function() should only execute once, but you have written the code such that function() executes every time through the loop, and only copies the result to abc once. Okey... The thing I meant is that function() should be called only once between do and while. So for example this is not allowed: do{ int num=0; int num2 = function(); do { num++; abc = function(); int num3 = num2 - abc; function2(num3); ... }while(stop()); ... }... QUOTE (ned @ Jun 26 2008, 03:19 PM) In LabVIEW you don't need the variable "num" since it's already provided within a while loop, at the "increment" terminal (the little i in a box). You can connect that to a case statement; in case 0 you run function() and in the default case you pass the value straight through. It would help if you post your LabVIEW code (or at least a screenshot) so we can see what you've tried to do, and comment on it more specifically. Here is a simplification of the problem: This program will initialize the feedbacknode only once (Global initialization). I want it to initialize every time as new number is directed every 500ms, but this must happen inside of the innermost while loop. I could initialize the feedback node before the while loop, which means that first I need to call the "function()" outside of the innermost. And that I do not want to do. Ilkka Quote Link to comment
LAVA 1.0 Content Posted June 27, 2008 Report Share Posted June 27, 2008 Here's a simple construct for this using a Comparison and Select function. Quote Link to comment
Elktro Posted June 27, 2008 Author Report Share Posted June 27, 2008 QUOTE (normandinf @ Jun 26 2008, 04:36 PM) Well, from the part of your program you've shown, num2 doesn't change and will always be equal to abc. num3 = num2 - abc is therefore always 0... Not necessarily. If function() gives different values, abc will change. So num3 = num - abc is surely 0 first but not necessarily after that. The LabVIEW program of yours doesn't exactly do waht does the C-program. function2(num3) is not called wjen num3=0 as it should. Ilkka Quote Link to comment
Francois Normandin Posted June 27, 2008 Report Share Posted June 27, 2008 QUOTE (Elktro @ Jun 26 2008, 11:41 AM) Not necessarily. If function() gives different values, abc will change. So num3 = num - abc is surely 0 first but not necessarily after that.The LabVIEW program of yours doesn't exactly do waht does the C-program. function2(num3) is not called wjen num3=0 as it should. Ilkka well we don't see that part in the code you supplied... from what I could tell, it would execute every loop except the first. Quote Link to comment
ned Posted June 27, 2008 Report Share Posted June 27, 2008 QUOTE (Elktro @ Jun 26 2008, 11:21 AM) This program will initialize the feedbacknode only once (Global initialization). I want it to initialize every time as new number is directed every 500ms, but this must happen inside of the innermost while loop. I could initialize the feedback node before the while loop, which means that first I need to call the "function()" outside of the innermost. And that I do not want to do. Is there some reason you can't use a shift register instead of a feedback node, and a structure that looks like this: http://lavag.org/old_files/monthly_06_2008/post-3989-1214500441.gif' target="_blank"> Quote Link to comment
Neville D Posted June 27, 2008 Report Share Posted June 27, 2008 Haven't looked too deeply at the code, but you can, on the feedback node, move the initializer terminal to the outermost loop if required. Right-click the feedback node, and select "Move initializer one loop out" Or just us the shift-reg with the i=0 case. Neville. Quote Link to comment
Elktro Posted June 28, 2008 Author Report Share Posted June 28, 2008 I have now found very satisfactory solution. The thing to realize is that the "result" must be zero for first loop execution. Thanks for quick answers! Ilkka Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.