LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loop event with a different time

Solved!
Go to solution

Hello,

I'm writing a VI that is a state machine that is running at 30ms timing but while the state machine is in the idle loop I need to send a keep alive toggle (Boolean) to a PLC every 500ms. With the requirements of the main state machine to run at 30ms how can I setup the other time or event inside the while loop. I used the remainder / quotient function with the iteration but cant seem to find the solution there.

 

So the requirements:

  • while loop must run at 30ms
  • every 500ms the boolean value must change states
  • the 500ms time should not slow down the main loop like a wait

 

Anyone have a suggestion?

Bill Lewis
0 Kudos
Message 1 of 5
(2,890 Views)

Hello Bill,

 

Just implement a timer counter which will count the time, and when it reaches 500ms, it will reset to start again the counting, and will toggle the boolean (like time elapse). Just note that it may not be exactly 500ms. Is the accuracy of the 500ms period is important?

 

Thanks,

Arev

 

CTO | RAFA Solutions

 

Certified-LabVIEW-Embedded-Systems-Developer_rgb.jpgCertified-LabVIEW-Architect_rgb.jpg

 

 

Message 2 of 5
(2,876 Views)
Solution
Accepted by topic author Bill_Lewis

Hello Bill_lewis,

 

As 500 isn't a multiple of 30, it seems difficult to perform it in one while loop.

You would use another loop in parallel or change one of the two timing in order to toggle your Boolean at a multiple of the while loop timing.

 

Regards.

Sabri JATLAOUI - Certified LabVIEW Architect - Certified LabVIEW Developer
0 Kudos
Message 3 of 5
(2,867 Views)

I would go with the the parallel loop and send the data every time your timer has elapsed. You will probably want to use a time of 350-400ms, if you are going to get an error after 500ms.

 

If you are sending it to the device that your state machine also accesses, then it may slow it down a teeny bit if both loops are trying to send data to the same device, but I don't see any way around that.

0 Kudos
Message 4 of 5
(2,849 Views)

Look at the Elapsed Timer express VI.  It is a simple VI that will tell you if some amount of time has elapsed from the last time it was reset and that time was reached.  It has an output that is true once that time has been reached so I'd put that into a case structure and when 500ms has gone by, send the keep alive.

 

Now as others have said this won't happen ever 500.00000000ms for several reasons, but most hardware doesn't need a keep alive to be that precise.  I'd try it at 500ms, then try it at 600, then 800, until it stops working and based on that I would decide what value to use.  If it some times has an issue at 500ms (because it will actually be at least 500 and might be too much) then I'd set it to 400ms.  Again generally hardware doesn't mind if it sees a keep alive too often.

0 Kudos
Message 5 of 5
(2,807 Views)