Jump to content

How to initialize feedback node inside a while loop for every while


Recommended Posts

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!

Link to comment

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.

Link to comment

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.

post-10515-1214490929.jpg?width=400

post-10515-1214490934.jpg?width=400

Link to comment

QUOTE (ned @ Jun 26 2008, 03:19 PM)

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{

}...

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:

post-11857-1214492827.jpg?width=400

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

Link to comment

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

Link to comment

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.

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
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.