04-06-2015 11:49 AM
sorry forgot the attachement
04-06-2015 12:03 PM
Hi All,
I’m trying to implement a counter with enable and reset.
04-06-2015 01:36 PM
I think the problem you are having is that you have not clearly defined the problem. I'm not sure what I'm about to say describes the task you are undertaking, but it at least should be unambiguous enough to determine if it does or not ...
Something like this, where you need to maintain an internal "State" (or "Count"), is something that many LabVIEW users call an Action Engine (if you Google "LabVIEW Action Engine", you can probably find very useful material). You might consider building this VI as an Action Engine, possibly with the following Actions:
Note that I haven't mentioned the output Q. Did you also want to output the current Count? What happens (or what do you want to happen) if you Count before you Enable, or Enable before you Initialize?
Note that all of this can be handled by a single VI, consisting of a "Do Once" While Loop (a While Loop with the constant True wired to the Stop indicator), some Shift Registers, and a Case Statement. An Enum that takes on the values Initialize, Enable, Disable, and Count, is also useful, especially for wiring to the Case Selector and making your code somewhat self-documenting.
Bob Schor
04-06-2015 03:41 PM - edited 04-06-2015 03:50 PM
@roseh33 wrote:
Hi All,
I’m trying to implement a counter with enable and reset.
- Increment from 0 to “number of pulses” when “enable” is true and output Q is 1.
- If enable is false, Q is 0.
- Once the counter reaches “number of pulses”, the counter has to reset to 0.
- Step 1-2 only happens when enable is true.
All you need is a shift register containing the count. Divide by the number of pulses using Quotient&remaider and only keep the remainder in the shift register. Increment if the switch is true, else don't increment. Code would take 10% of what you currenty have. Keep it simple!
Here's a draft. Modify as needed.
04-06-2015 05:08 PM
Sorry I am new to labview community. Here's my vi.
04-06-2015 05:39 PM - edited 04-06-2015 05:57 PM
@roseh33 wrote:
Here's my vi.
Have a look at my code above, much simpler! You can easily add a reset function.