04-01-2015 08:54 AM
Hi.
First of all, I looked online for this solultion and no success.
What I am trying to do is have a counter with enable and reset.
1. Increment from 0 to 5 everytime true boolean is received. Q, the output should then be 1
2. If boolean false is received, Q should be 0
3. Once the count reaches 5, reset the counter to 0 and repeat.
4. Step 1-3 only happens when enable is true. Anytime enable is false, the process is stopped.
Please help!
Rose
04-01-2015 09:07 AM
Hi Rose,
some pseudocode may help:
IF enable THEN IF boolean THEN Q := 1 counter := (counter +1) MOD 5 ELSE Q := 0 ENDIF ENDIF
You need two case structures, a feedback node and a Quotient&Remainder function.
You didn't define your output Q when ENABLE is FALSE…
04-01-2015 09:27 AM
This is something called an Action Engine, closely related to "Functional Global Variables" (FGV) or "VI Globals" (VIG). Basically, you have a While Loop with one or more Shift Registers acting as "memory" and an "Action" input (typically a Boolean or an Enum) that says what the Action should be.
As you posed your problem, I'm unsure if you require one Boolean (Enable/Disable) or two (Enable/Disable and "Count"). This is a situation where having an Enum input and more "Actions" might be appropriate. For example:
Load Save the Max Count (5 in your example) in a Shift Register
Reset Set the internal Count to 0
Enable Allow Count Action to proceed
Disable Don't allow Count Action to proceed
Count Increment counter if "enabled", and output current count
Each time you call this VI (did I say that this should be written as a sub-VI, with inputs Action and Max Count, and output Current Count?), depending on the Action you wire in, you will either perform "setup" actions (Load, Reset, Enable, Disable) or "Counting" actions (Count). Note that it is easy to modify it so that if the Counter is disabled (ooh, that's a good name for this sub-VI, "Counter", has a mnemonic ring to it), the output is, say, -1, "Not a Count", instead of (as I described it above) the last Count while Enabled.
Action Engines (and similar constructs, where there's a While loop with "True" wired to the Stop terminal, useful as a "memory" unit) are pretty common in LabVIEW. More accomplished LabVIEW users might also accomplish this with a Feedback loop, but I find that the "Do Once" loop shown above is easier for me to recognize and understand.
Bob (hard to teach an old dog new tricks) Schor
04-01-2015 09:28 AM
I think this diagram would meet your requirements if I am reading them correctly.
Gerd,
I think this works with only one case structure, am I wrong?
04-01-2015 09:31 AM - edited 04-01-2015 09:32 AM
Hi griff,
you can replace your comparison and select functions by QR as suggested…
I just gave that simple pseudocode based on the OP's problem description. From that is was easiest to use two case structures as (atleast for me) the problem isn't defined very well for all possible input cases…
04-01-2015 09:38 AM - edited 04-01-2015 09:38 AM
griff32 wrote:
I think this works with only one case structure, am I wrong?
You can get away with just 1 case structure. But not exactly the way you did it.
The False case just passes the count straight through.
04-01-2015 09:44 AM
HI Gerd,
Thanks I put that replacement in and it worked.
04-01-2015 11:25 AM - edited 04-01-2015 11:34 AM
For fun, I decided to implement it using flip flop representations, since it's a common ring counter design:
There are 6 unique combinations of Q0, Q1, and Q2 that will show up, which can be correlated to 0, 1, 2, 3, 4, and 5.
Edit: "Counter Enabled" is the Q output mentioned in the original post.
04-06-2015 11:37 AM
04-06-2015 11:37 AM