Lambiek Posted March 22, 2005 Report Share Posted March 22, 2005 Hi, I'm rather new to LV, and while I'm experimenting and developing with a FP RT system, I'm stuck now. We're doing frequency measurements with a counter module (cFP-CTR-502), and in this context I need an algoritm that goes like this: A variable (I'll call it Divisor) has a value of 1 for starters and depending on the value of another variable (let's call it Count), the divisor should be multiplied, or divided by a value: count < 1000 => Divisor *3 count < 500 => Divisor *6 count < 250 => Divisor *9 Count >16000 => Divisor *9 Count >8000 => Divisor *6 Count >5300 => Divisor *3 Count between 1000 and 5300 => no alteration of Divisor. I tried to write code in a formula node(dlr==Divisor and Cnt==Count): float32 dlr=1; while (dlr<6250) { if(cnt<250) dlr=dlr*9; else if (cnt<500) dlr=dlr*6; else if (cnt<1000) dlr=dlr*3; else if (cnt>5300) dlr=dlr/3; else if (cnt>8000) dlr=dlr/6; else if (cnt>16000) dlr=dlr/9; } But this has two main problems: -All of my CPU time is taken (alltough it's in a while loop with a 'Wait untill next ms multiple') -'dlr' is allways reset to a value of 1, while it should be a more dynamic number Can Anyone give me a hint on how I should work this out ? thx Quote Link to comment
Louis Manfredi Posted March 22, 2005 Report Share Posted March 22, 2005 Hi lambiek: Here is a possible clue: I think that once the program enters the formula node, it will use the data which existed at the time it entered the node (unless it is changed within the node) until it exits. So your program will use the original value of cnt over and over-- depending upon what the initial value of count is, it might never exit the formula node. I suspect that isn't what you intended? (Also, will never exit the formula node to execute the wait till next ms operation.) Also, once you get past that point, double check to see that the else if (cnt = 16000) comparison gets made when you want it to-- I suspect the cnt>5300 case will always block it. Hope to have helped, Louis Quote Link to comment
jbrohan Posted March 22, 2005 Report Share Posted March 22, 2005 There is a simple way using the select function. It takes a minute or two to test that it's correct with values just below, equal and just above each of the steps. I'm including a jpg of the diagram! Yours Sincerely John Just thought about this for a minute... It's a) upside down and b) the 8000 one has the wrong comparator... a not uncommon event in my programming! Quote Link to comment
Lambiek Posted March 24, 2005 Author Report Share Posted March 24, 2005 There is a simple way using the select function. It takes a minute or two to test that it's correct with values just below, equal and just above each of the steps. I'm including a jpg of the diagram! Yours Sincerely John Just thought about this for a minute... It's a) upside down and b) the 8000 one has the wrong comparator... a not uncommon event in my programming! 4299[/snapback] Thank you already for your answer :thumbup: , But it's not really clear what your meaning, what are the possible cases in the case structure ? I'm not sure I understand what your trying to tell me.... Quote Link to comment
ahlers01 Posted March 24, 2005 Report Share Posted March 24, 2005 You may want totry the following Labview case structure (which is a more or less literal translatino of you pseudo code to LV graphical code: Sorry, there are two errors: a) some pictures are missing. But you can reconstruct from the visible frames what's in the missing frames.. b) it should read translation, not 'translatino' (whatever that is) Quote Link to comment
RandyR Posted April 6, 2005 Report Share Posted April 6, 2005 The trouble with hard coding a solution into a case statement is the tediousness as well as the lack of being able to easily modify the table. And of course, with the case statement, you can't change it at all in an exe. Here's how I'd do it... Simple and easily configurable. Randy 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.