02-11-2025 05:37 AM
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:)
Solved! Go to Solution.
02-11-2025 05:55 AM - edited 02-11-2025 05:57 AM
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:
02-11-2025 12:54 PM
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.
02-11-2025 03:08 PM
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?
02-11-2025 03:27 PM
02-12-2025 07:59 AM
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.
02-12-2025 11:12 PM
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:)
02-13-2025 12:57 AM
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:
02-13-2025 09:28 AM
@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!)
02-13-2025 11:14 PM
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:)