LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean Cycle

Hello,
 
I like to create an boolean cycle where for example every second a boolean true for 1-5ms does appear. I tried something in this way but it does not work in the favoured way.
In the appended example there are two ideas.
First, the "time count" runs and there should be a match every 1000ms, but I think in connection with the runtime of the programm, not every match is detected. It is possible, to see the LED flashing sometimes for a short time. 
Second, the LED changes the boolean value every second, but the high value does also appear 1s.
The background is, that I like to write values in a file every second and the cycle should not have a great effect of the runtime from the VI.
Can somebody help? I work with LV6.i.
 
 
Regards
ThomasD  

Message Edited by ThomasD on 10-19-2005 02:43 AM

0 Kudos
Message 1 of 6
(3,608 Views)

Hi Thomas

Your first described way works, but I think it's a bit "dangerous" to compare the remainder to 1 (in addition you compare floating-point numbers).

I made a vi, which measures the time elapsed end sets an indicator. The duration of the time the indicator is set true, depends on the loop timing. So I places a "Wait until next ms multiple" with 5ms. Because of this very short time, you won't see the indicator flash (you could see it if you increase the time from 5ms to 100ms).

In the false case I just wire the boolean value through to the output tunnel and I do the same with the time from the shift-register.

Just have a look a the picture.

Hope this helps.

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 2 of 6
(3,597 Views)
Hello Thomas,

in addition to Beck's comments:
- You don't need to ask two times for the actual time. Doing some math will help (and probably speed) up your vi.
- Running a loop like yours as fast as possible is no good programming, it will just hog the cpu time.
- Writing to a file every second: do you really need this? If you want to save just a line of text, you can probably wait at least 10-20 seconds. If you collect a huge amount of data, the filesaving will need more than 1 second and surely affect the loop time.

Have a look at my picture. If you change your vi like this, you see that the LED flashes, even if you cannot see it (# Hi gives you the number of times the LED is on...).

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 6
(3,594 Views)


@ThomasD wrote:
The background is, that I like to write values in a file every second and the cycle should not have a great effect of the runtime from the VI.
Can somebody help? I work with LV6.i.

Just place your file operation inside a while loop and also place a "wait next ms multiple" with an input of 1000ms. That's all you need! 🙂

Unlike the plain wait (ms) node, the wait next ms multiple will ensure that the loop occurs at regular intervals, independent of the execution time of the nodes inside the loop.

0 Kudos
Message 4 of 6
(3,571 Views)

Hello you 3,

@ Thomas, I built the VI how you said, but in the logfile, where I save the datas, the time for each measurement/save cycle is a few seconds and the cycletime isn´t constant too.

@ Gerd, the programm in the first message of the thread should only show the ideas I had. When the code you told is integrated in my VI, I get two different results. First, when the "x < Y?" is connected, the cycletime is not constant. Same problem seen by the solution of Thomas or the first VI I have posted. I think, this are runtime-problems, where the exact match isn´t always found. Second, when the "x != 0? 2" is connected, the cycletime is <200ms.

@ Altenbach, I also tested it with the "wait next ms multiple", but these doesn´t also work over time. I read datas from the serial port with 9600 baud and than, the "Number of Bytes at serial port" does increase by using the "wait next ms multiple" function and after a few seconds there is a buffer overflow.

 

Legend to the pictures:

becktho_01.jpg: VI with Thomas´solution

gerdw_01.jpg: VI with Gerds solution

logfile_01.jpg: logfile with "x != 0? 2"

 

Regrads ThomasD

Download All
0 Kudos
Message 5 of 6
(3,542 Views)

Hi

As it can be seen in your attachments, you have more logik in the vi than just generating a pulse - this may slow down your loop. If you want to keep the pulse generation time constant, just pass the impuls to an other loop or vi, where you log the data. If you have to log data with each pulse, try to use a buffer.

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 6 of 6
(3,522 Views)