LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State change time count

Solved!
Go to solution

I am developing a program that by changing the state shows me the time in seconds in the state "1" and the time in the state "0", ie the sum of the times of the two states is the value of the period. I know the time but I still have a problem with the sum of the two times, because it does not make me the correct sum. The idea is to save the last time value of each state in two variables and then add them, but when I do that the sum is incorrect. Some resolution help will be helpful.

 

 

0 Kudos
Message 1 of 9
(3,437 Views)

Hi hao,

 

where do you try to add some time values?

Which values are you adding and what is the result?

 

Why is there so much duplicated code in your VI? Why don't you use (reentrant) subVIs?

What is this piece of code:

check.png

How is the output defined for state=0? (Why do you need a formula node here?)

 

Why do you need to convert your boolean wires to 0/1 so often just to call some case structure with them? That is pure Rube-Goldberg!

(Btw. "light" is spelled l-i-g-h-t.)

Best regards,
GerdW


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

hi  

i appreciate your response and the questions.

 

answer to the first and second question

The values to add will be time1 and time2 only when the time of time2 ("0") starts running the time of team1 should be at zero and when the state changes to time1 the idea was to save the time value of "0" in a variable and when another variable receives the value of team1 then yes I made the sum of the two times. The parameter Active (don´t look for the (min)) should be 0 when run the vi file it shouldn't be the result that's there. The ideal would be to implement a reset button for the entire vi so that when it started it could do a full reset to the program. The result when i making the sum is in the file of image1

 

answer to the third question

I'm not quite familiar with the use of subvi yet, but it's an aspect to be improved in the presentation of my code and I appreciate the suggestion.

 

answer to the fourth question

this code in the node formula detects the state of the boolean switch, if it is "1" the on will be equal to the time1 which means that the led is active, if it is "0" the off will be equal to the time2 which means that the led is inactive, it was a simple way to observe the time count but in time it is to implement the case structure of the labview.

 

yes just to later call the case structure with them because it is easier for me, since I am not yet so familiar with the graphic programming and still need more training I prefer not to complicate.

0 Kudos
Message 3 of 9
(3,406 Views)

Hi hao,

 


@smalhao wrote:

answer to the fourth question

this code in the node formula detects the state of the boolean switch, if it is "1" the on will be equal to the time1 which means that the led is active, if it is "0" the off will be equal to the time2 which means that the led is inactive, it was a simple way to observe the time count but in time it is to implement the case structure of the labview.

But what is the output when state==0? Which value is given as "on" then? What is "off" for state!=0?

That code part is ill-defined!

 


@smalhao wrote:

yes just to later call the case structure with them because it is easier for me, since I am not yet so familiar with the graphic programming and still need more training I prefer not to complicate.


But you are currently creating more complicate code then should be - because you don't take the training resource first before starting to code…

 

What is shown in this image? Did you try to debug your code?

Which values do you add for "add of time1 and time2"? Did you use probes?

Best regards,
GerdW


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

The image of tower signalling show the equipment to control. The objective is obtain the time when light red is on and light red is off and i need adding that two values for obtain the period of working of light and then we know the malfuction indicate the tower. I don´t have the tower and  i'm working with in a simulation of red light through a switch button.

For example, if the red light is on 5 seconds and is of 3 seconds for the flashing situation, then i need adding 5 and 3 to obtain the period of 8 seconds and the operator who is working in that machine, know the malfunction in that moment showing a message in display of the computer control.

 

 

When the output is state==0 the led should be OFF.
When the output is state!=0 the led should be ON.

 

In the formula node will be receive the value of variable "state" it is the state of switch , if the value of "state" is "1" then the state will be "state!=0" and pass the value of variable time1 to variable "on" who will inciate the counting of the time in seconds of led when is on, if the "state" is "0" the state will be "state==0" and pass the value of variable time1 to variable "off", who will iniciate the counting of time in seconds of led off and then i need to sum that values of the variables of "on" and "off" to obtain the complete period of state (like the period of a sinusoidal wave for example), this is necessary to obtain the malfunction of a machine through the signalling tower of lights in a enterprise.

 

The image shows when i start the VI the values should be iniciate in table control with value 0 but in th parameter Activate not iniciate in that value and need to programming a reset button to iniciate the VI correctly when i run the vi. The value of parameter Time 0 volts not appears in the indicator add time1 and time2

 

 

 

0 Kudos
Message 5 of 9
(3,350 Views)
Solution
Accepted by topic author smalhao

Hi hao,

 


@smalhao wrote:

The objective is obtain the time when light red is on and light red is off and i need adding that two values for obtain the period of working of light and then we know the malfuction indicate the tower.

For example, if the red light is on 5 seconds and is of 3 seconds for the flashing situation, then i need adding 5 and 3 to obtain the period of 8 second

You only need to count the time for one of those states, either ON or OFF. The total time can be measured easily from how long your VI is running, so the other state is the difference between total time and measured time…

 

Use plain LabVIEW G functions instead of ill-defined code in formula nodes:

check.png

No need to convert booleans into integer values!

Best regards,
GerdW


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

That's what I wanted, much simpler, just one question, if I want to save the last time value, ie the switch was 30 seconds on and then off how can I save that 30 seconds value?

0 Kudos
Message 7 of 9
(3,298 Views)

Hi hao,

 

to "save" (aka store) values in loops you should use shift registers!

 


@smalhao wrote:

if  … the switch was 30 seconds on and then off how can I save that 30 seconds value?


So you want to to something on a falling edge of a boolean value?

There's a "BooleanCrossing PtByPt" function…

Best regards,
GerdW


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

I am trying to program the counter reset, for the led counter to ON and LED to OFF already managed to implement but however when the sum block is executed it always starts at 0, as I can perform the sum without always starting to zero when change state.

 

my VI is with the GerdW solution and resetting the ON and OFF counters.

0 Kudos
Message 9 of 9
(3,272 Views)