LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Elapsed Time latches LED ONCE

Hello,

 

I am a beginner and I've been trying to create a simple Timer+latch sequence but with no success. The sequence attached is part of a larger software that I'm building. Normally with a PLC this should be really easy, using timer and Set/Reset or Pulse coil(s), and I thought using the "Elapsed Time" vi should've been the same thing.

 

Context:

I have a BOOL control on the right (Digital Output to turn equipment on/off) and a BOOL feedback (Digital Input) confirming on/off status of external equipment. The DI is represented here as Front Panel control and the DO as indicator, for testing/simulation purposes, before I wire them to real channels.

 

What I want:

Basically, when the State is 0, then "68(Control)" led is OFF (hense the bigger False Case).
When the State is 1, then I want the same led to be ON for a number of seconds, then turn OFF until the State turns back 1 (when everything repeats).
The timer should start when the 68 feedback on the left (digital input) confirms the equipment is ON.

 

Problems:

1. I can't find a simple one-block way (or at least without using another WHILE or FOR) to latch a LED and the examples I found on the forum, most of them I rather complex and can't integrate them successfully, hence I went on with the wiring and scenarios around the attached file.
2. I reached a level where I feel I'm close but I cannot completely reset the 68(Control) LED after time has elapsed, even though my indicator say time has elapsed.

Download All
0 Kudos
Message 1 of 15
(3,937 Views)

Looks like I just found a way to retain the OFF state of the LED after Time elapsed, but as a downside it won't go ON again the next time State button switches ON again, unless I restart the program. Such a bummer. Any help?

Download All
0 Kudos
Message 2 of 15
(3,900 Views)

The solution is probably not to add even more code, but to simplify. I am sure there is a solution that fits on half a postcard.

 

(not that if state is currently false, your while loop spins millions of times per second. Not reasonable)

0 Kudos
Message 3 of 15
(3,850 Views)

See if this can give you some general ideas. (It probably needs some tweaks because you don't describe the behavior for all possible scenarios. For example, what should happen if the feedback is turned on first? What should happen if feedback is turned back off quickly, etc.)

 

General advice:

Please do NOT maximize the diagram and front panel to the screen. You should be able to look at both as well as e.g. the help window or this web page.

Please save your VI using a reasonable name. "Untitled 1.vi" is NOT a reasonable name. In my case it opened as "untitled1 (18).vi" because so many others did what you did. If htis is a subVI, the caller would grab the wrong VI!

0 Kudos
Message 4 of 15
(3,844 Views)

Hi altenbach,

 

Thank you for your reply. I am sorry for any misunderstanding.

 

But the 68(Control aka LED) needs to be ON as soon as the State turns ON.

68(Control aka LED) means the physical equipment is ordered (via DO) to turn ON, then it will send a DI (68 Signal Feedback aka Button) to LabVIEW confirming it is ON.

 

(The file attached is just a draft where I tried to isolate and separately test this part of the code from a bigger software; so I simulated the DI with a control button and the DO with a LED because the DO is a result of a logic. I also had the State controlling a Case Selector because it simulates one of the states of a state machine).

 

So, when DI (68 Signal Feedback aka Button) turns ON, then Timer starts counting the seconds it is ON.

After seconds reach threshold, the DO (68 Control aka LED) should turn OFF. That means physically the DI 68 (signal feedback aka button) will turn OFF too.

 

After that, they will both need to stay off as long as the State is ON (and afterwards, but that will be controlled in the other states).

 

But if the State is back ON, the whole thing needs to happen again. Before your reply I think I managed to do this, but I cannot find a way to reset the Timer in a way that:

- it doesn't restart within the same "State=1"

- it restarts when the State is 0 and becomes 1 again.

If I were using a PLC, a pulse signal (_-_______) from the State turning on would've been enough to properly reset the timer.

 

 

As for other scenarios:

- when switching from previous state to this state, I'm planning to make sure to verify that 68 is OFF before it can switch to this state, so 68 cannot be on before this state starts.

- Eventually I will have an override option to keep 68 LED permanently ON or OFF but I thought it was too much to tell you guys because I'm not done with the auto sequence yet.

- I am not sure yet what should happen if feedback is turned off and on before the time is elapsed because it would mean something is wrong with the equipment or the signal. The timer could maybe pause or reset or the DO is just kept off and send a warning... Good question.

0 Kudos
Message 5 of 15
(3,837 Views)

@ASX24 wrote:

But the 68(Control aka LED) needs to be ON as soon as the State turns ON.


Well, earlier, you said:

 


@ASX24 wrote:

The timer should start when the 68 feedback on the left (digital input) confirms the equipment is ON.


I was under the assumption that the operator would need to see the state turn on and then manually confirm with the feedback control, and only then the timer will start. If the feedback control directly relies on the state control, why is it a control?

 

I still think you have way too much code. If you can describe it in a few sentences, it does not need a screenful of code! ...and the diagram and front pane are still maximized to the screen, which makes working difficult, as already mentioned.

0 Kudos
Message 6 of 15
(3,823 Views)

Because it is a simulation.
- The Control button is a simulation of a Digital Input that will turn on when the peripheral device turns on.
The peripheral device turns on after the software turns a Digital Output on.
- The LED is a simulation of the result bit (1/0) to be sent to the Digital Output.

But right now I don't have either the peripheral device or the PXI, so I'm simulating parts of a state machine code on a laptop.

 

So:
If State=0
  LED=0
If State=1
  LED (digital output)=1
    then button turns 1 (manual button simulating a DI will turn ON; user knows to press after LED=1)
      after the button turns ON, the timer starts
        after Timer=Target Time, LED=0
          then button simulating DI turns OFF as a confirmation
          LED remains 0

 

Eventually there will also be an override control in this state (so only in State=1) where LED can be forced on and off at operator's discretion for as long as he wants.

 

Yes, I also feel this should be insanely simple and intuitive to do this because I've been working with PLCs and there were very simple (a couple of lines).

But here I encountered several problems:
- I couldn't find latch option for LEDs or for any action except buttons or unless I have Real Time module or manually wire flip/flop gates
- I couldn't find any simple block to generate a one-time bit unless I work with shift registers (to the main while loop?), in order to reset the timer every time the State turns back 1

- I couldn't know why Elapsed Time is not reset if the State=0 (which would happen in a PLC)

- I couldn't find any MOV (move) instruction

-... etc

 

Anyway, this amount of code still hasn't help me to make this fully successful.

 

"the diagram and front pane are still maximized to the screen, which makes working difficult, as already mentioned."

I am not sure what you mean by this, if it is too large for your screen I will resize it for you; the VI is a draft for this state and, as soon as it works, it will be deleted and all code integrated into my main VI which is already sized for the target display resolution.

0 Kudos
Message 7 of 15
(3,794 Views)

Previous reply disappeared for some reason, so I'm repost some of it:

 

Because it is a simulation and I don't have the real channels or the peripheral device to my disposal yet.

The Control button is a simulation of a Digital Input that will turn on when the peripheral device turns on.
The peripheral device turns on after the software turns a Digital Output on.
The LED is a simulation of the action result (1/0) that will go to the Digital Output.

 

So:
If State=0
  LED=0
If State=1
  LED=1
    then button turns 1 (manual button simulating a DI will turn ON)
      after the button turns ON, the timer starts
        after Timer=Target Time, LED=0
          then button turns OFF as a confirmation
          LED remains 0

 

Eventually there will be an override option within "State=1" to manually keep LED On or Off.

 

Yes, I also feel this should be insanely simple and intuitive to implement, but the problems I encountered were mainly around the facts that:
- I couldn't find latch option for LEDs or for any action except buttons or unless I have Real Time module or manually wire flip/flop gates
- I couldn't find any simple block to generate a one-time bit (pulse) unless I work with shift registers (to the main while loop?), in order to reset the timer every time the State turns back 1.

- No one-time MOV instruction.

So i've been trying to work around these ideas but with no luck so far.

 

Sorry for the maximized windows but the VI is just a draft simulation of the State case of a state machine. After successful simulation I will move all code to the main VI which is sized for the target display.

0 Kudos
Message 8 of 15
(3,805 Views)

Not giving a solution here but a tip.

 

You can use an event structure in your code and a state machine. This will improve the readability of the code and you will have a more stable and standard piece of code.

 

Greetings

0 Kudos
Message 9 of 15
(3,797 Views)

I am not sure of your Labview coding level (looks to be at the beginning stages) but I'll also add that you can get the same performance (and without pooling) if you use a State Machine with an Event Structure. Look into that as well.

0 Kudos
Message 10 of 15
(3,786 Views)