LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring ON and OFF Time of an LED in VI

Solved!
Go to solution

Hello all.

 

I am trying to measure On and Off time of an LED.I will get that data from a GPIO Pin from other PCBA in my real project. But to simulate that, I just added a switch in the VI itself and i am trying to measure the ON time by detecting rising edge and falling edge and capturing the time straps at that time. I am not getting the data as expected. Can you please verify the below attached code and help me where i am missing something.

 

Waiting for your reply:)

0 Kudos
Message 1 of 14
(197 Views)
Solution
Accepted by VarshiniPasumamula

Hi Varshini,

 


@VarshiniPasumamula wrote:
I am not getting the data as expected.

Because you use too many locals and sequence frames!

You also created too much Rube-Goldberg code, like those comparisons with boolean constants…  (Compare with FALSE is the same as NOT, compare with TRUE is the same as NOP!)

 

Recommendations:

  • Cleanup the block diagram. Errors are clearer to detect in clean code…
  • Use the HighResRelativeSeconds instead of the Tick function to get relative time in seconds (instead of ms ticks)…
  • Replace those locals by wires!!!
  • Replace those case structures with Select nodes…
  • The wait inside the loop defines the resolution of your time measurement: is a 1s interval good enough?
Best regards,
GerdW


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

I would suggest u to use a state machine to measure the time. 

 State 1 - Idle -Waiting for start - when the start condition occurs, register the tick time.

 

State 2 - Waiting for Falling Edge - Reads the LED condition - when falling edge is detected, register the Tick time and move to the last stage

 

State 3 Calculate time lapsed - Calculate the Time difference between the tick counts. - Goes back to state 1 Idle.

 

0 Kudos
Message 3 of 14
(154 Views)

Done right, you code could fit on a postage stamp. Many problem areas have already been mentioned.

 

Apparently you only want to measure the last on and off times and not keep a history, right?

 

0 Kudos
Message 4 of 14
(145 Views)

See if this can give you some basic ideas...

 

altenbach_0-1739309218971.png

 

0 Kudos
Message 5 of 14
(141 Views)

Thank you for your reply!!

 

I have implemented the suggestions that you gave made some changes to implement ON and OFF Time measurement and it is working as expected.

0 Kudos
Message 6 of 14
(124 Views)

I am trying to log the data into spread sheet...If i am keeping "write delimited spread sheet" in while loop,it is logging lot of data.

So i want to simplify the data logging.I want to log the data when On, Off time changes.So, I tried using event case and kept data logging inside the event case.I tried keeping event case inside and outside of while loop but nothing helped me to log the data as my expectation.

So,Which method is correct wany for this

 

Waiting for your reply:)

0 Kudos
Message 7 of 14
(105 Views)

Hi Varshini,

 


@VarshiniPasumamula wrote:

So i want to simplify the data logging.I want to log the data when On, Off time changes.So, I tried using event case

So,Which method is correct wany for this


You forgot to attach your current VI so we cannot comment on what you did wrong…

 

As I have to rely on your textual description of a graphical code I guess:

  • Using an event structure is wrong here.
  • When you want to act upon falling/rising edges all you need is a case structure. Use the edge detection output for the case selector. (You already have that edge detection in use!)
Best regards,
GerdW


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

@VarshiniPasumamula wrote:

So i want to simplify the data logging.I want to log the data when On, Off time changes.So, I tried using event case and kept data logging inside the event case.I tried keeping event case inside and outside of while loop but nothing helped me to log the data as my expectation.


Typically you would use low-level file IO, open the file before the loop, append a row as needed, and close after the loop.

Here's a quick draft to conditionally append new rows to an existing string (or file in your case!)

 

 

altenbach_0-1739460418090.png

 

altenbach_1-1739460488006.png

 

 

0 Kudos
Message 9 of 14
(70 Views)

Here,i have attached the code that have been implemented. In this case the data is logging to excel for every 500ms. Which leads to lot of repetitive data. So,i want to log the file in the excel when the value of on or off time changes. So,i have tried using event structure for that and kept "Write delimited spread sheet" inside if that.But it is not giving as expected.So,what will be the best way for implementing this.

 

Waiting for your reply:) 

0 Kudos
Message 10 of 14
(51 Views)