Jump to content

Algorithm


Recommended Posts

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

Link to comment

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

Link to comment

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

post-230-1111530954.jpg?width=400

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!

Link to comment
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

post-230-1111530954.jpg?width=400

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

Link to comment

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:

post-833-1111670659.png?width=400

post-833-1111670660.png?width=400

post-833-1111670585.png?width=400

post-833-1111670587.png?width=400

post-833-1111670588.png?width=400

post-833-1111670589.png?width=400

post-833-1111670590.png?width=400

post-833-1111670591.png?width=400

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)

Link to comment
  • 2 weeks later...

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

post-767-1112747992.jpg?width=400

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.