LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending output value using user-defined sequence

Dear all,

 

I am trying to write a VI that sends output signals (intensity) to a LED with variations of the intensity with time by consecutive sequences.

I cannot use a sequence since I want to be possible for the user to change the number of times he wants to change the intensity of the LED. I’ve done the following VI (in NI 2016) using a state machine, but I guess there might be an easier way to provide the same function. The VI includes only the visualization of the output value (LED intensity) as I’ll get to the actual thing once I’ve managed to program the sequencing properly.

To explain the VI:

The array “Time and Output”: the first column being the time (1 to 6 with a step of 1 which is equivalent to 5s) and the second column being the output value, or the LED intensity.

Two counters: one for the line in the array and one for the first one to stop increasing when switching from one line to the other

A slide to show the output and one indicator to show the time.

“Start time”, “Current Time” and “Time for output change” for time management purposes

 

When the “Current Time” is > “Time for output change” and if “Counter 1” = “ Counter 2”, Counter 1 increases by 1which changes the Time and Output Value.

When the “Current Time” is < “Time for output change” and if “Counter 2” < “ Counter 1”, Counter 2 increases by 1.

 

What do you think? Is there a way to improve/simplify this program?

 

Thanks a lot,

 

Iforire

0 Kudos
Message 1 of 6
(1,065 Views)

When I think of an LED, I think of something that has two values, Off and On.  Clearly you are thinking of something else.  So let me suppose you have a Gadget that can be set from 0 to 10.

 

You want to control the Gadget using a three-position switch -- Up 1, Hold, and Down 1.  Every 5 seconds, you read the switch and either increment, do nothing, or decrement the value going to the Gadget, but keeping it in the range 0 .. 10 (so if you leave the switch in "Up 1" for 50 seconds, it will reach 10 and stay there until you change to "Down 1".  You also have a "Stop" button that stops the program.

 

How do you do this? 

  • What LabVIEW Structure lets you do something until you push a Stop button?
  • What "data type(s)" are you using to drive your Gadget (which takes values 0, 1, 2, ... 10)?
  • What "data types" are you using to handle "every 5 seconds"?
  • How do you want to handle a 3-position switch (or do you have another idea for controlling how the Gadget changes every 5 seconds)?
  • What sort of control do you want to stop the program?

These parameters might not be exactly the ones you mentioned (is this a Homework assignment?).  I've tried to structure the questions to get you to "think LabVIEW" and remember that "wires" carry "data" and you want to manipulate these data, change how their behavior varies with time (and with input from you).  You may want to "store" the data (keep it in a wire, I'd suggest), and you definitely want "time" to play a role in this process.

 

You should be able to write a little routine that "runs every 5 seconds" and "does something".  Put indicators on wires to let you see the values in the wires.  Maybe start with having a wire increase by one every 5 seconds, stoppings (its increase) when it gets to 10.  

 

Bob Schor

0 Kudos
Message 2 of 6
(1,000 Views)

Thank you Bob for your answer.

You are totally right, the project is a little more complex that what I have explained. I wanted to simplify it (for it to be easier to understand, and because it is something for work, not that it's confidential at all, but I don't like to expose it entirely in the forum).

But, that is realy light intensities that I want to vary throughout the day.

The differnece between my example and what I want to do is that the intensity will vary from 0 to 100% and the time will be in the format of an hour of the day. The difference between two time points will not be always the same, as it will be user defined.

here is a theoretical example:

Time / LED Intensity

00:00       0%

04:00       25%

08:00       50%

12:00       100%

18:00       50% 

22:00       25%

24:00       0%  

 

So I'm not sure what you propose will help me.

Anyway, the program I've done is running, I just thought there was an easier way to do that 🙂

 

Thank you

0 Kudos
Message 3 of 6
(982 Views)

Ah, now we are getting somewhere!  You've put "units" on your values (a very helpful thing for the "human" looking at the code, and not at all a problem for LabVIEW, which can handle and interpret many representations of data).

 

So here's a question:  Are your Time values (e.g. 18:00) meant as "time of day" (so it would be 6 p.m.) or as time invervals (where it might be "18 hours from some arbitrary starting point)?  To me, the "sensible" answer is the first, but that has a direct input to what I'm about to suggest.  A related question -- do you only have 4 fixed intensities (0%, 25%, 50%, and 100%)?

 

I'm going to assume "sensible" answers to both questions.  I'm also going to assume that once you start this thing, it will run until you say "Stop" (i.e. it might run for a year or more without changing any parameters, and if you want to change a parameter, you'll stop the program, change, and start it again).

 

OK.  So you need an association between "TOD" (Time of Day) and "LED %".  Sounds like a Cluster to me.  And you need several of these with different values.  Sounds like an Array (of Clusters).

 

How should TOD be represented?  By a TimeStamp, of course, that shows Time only, in 24-hour notation.  How about LED %?  The most "User-Friendly" way would be a control that takes on the values "0 %", "25 %", "50 %", "100 %".  This is called an "enum" (for enumerated variable).

 

So I made a Cluster with a left element Time Stamp (called "When") showing HH:MM and a right element enum (called "LED %".  I made an Array of this Cluster and made it 6 elements long with the "When/%LED" values you showed (leaving out 24:00, as it's the same as 00:00).

 

So now you have an Array of times you want to "do something", based on a 24-hour clock.  What do you do?  You periodically "check the time", and if its within (some distance) of one of your "When" values, you set the LED according to the corresponding LED %.  How often do you check?  How about once a minute?  How do you (easily) compare two times, "When" and the current time?  Ah, that's a little tricky.

 

Oh, dear.  I think I might have found a "flaw" in the LabVIEW Time routines (and it was going so well, why did I have to try it out, myself?).  I'll tell you where the problem lies -- I made "When" a TimeStamp, but didn't specify the date, so it made it "0", or 1 Jan 1904 UTC.  00:00 become (for me) 19:00 31 Dec 1903, which is fine.  But when I ask LabVIEW to take the TimeStamp and give me the Hour and Minute, instead of 0 and 0, it gives 19 and 0.  That's a bug.  I'm thinking how to program around it (the easiest way is probably to add a days-worth of seconds to the time, but now it is super-messy, and dinner is almost ready).

 

Otherwise, the code is simply this:  Have a While Loop that "runs until you push Stop" (or almost "forever").  Put a "Wait 1000 ms" clock inside so you waste very little time.  When it "ticks", convert seconds to Date/Time, which will give you a Cluster, one element of which is Seconds, one is Minutes, one is Hours.  If Seconds = 0, see if Minutes and Hours are in your list of Times (if you make "When" not a Time Stamp, but "Hours" and "Minutes", or just "Hours" if you don't need minutes, the Problem in the preceding paragraph goes away!).  If they are, use the corresponding value of LED %.

 

Whew.  Dealing with "Clock Time" is always tricky, even in LabVIEW.  Have fun, good luck.

 

Bob Schor

 

 

 

 

 

0 Kudos
Message 4 of 6
(945 Views)

I looked at your VI.  I saw zero effort at clean wiring.  So I stopped looking.

Before I retired I had to look at a lot of messy code.  But now I'm old and crotchetty and I just have no interest in looking at anything messy.

I don't help people who won't even bother to do a little straightening out.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 5 of 6
(935 Views)

Thank you Bob for your kind advices.

 

 

Sorry Paul, I am kind of the messy type. To be honest, that is th first time I hear about clean wiring, and I certainly have to improve on that because all my VIs are not cleaned at all and they are very difficult to read for me too... So I take your comment as an advice and will work on that!

 

Thanks

0 Kudos
Message 6 of 6
(924 Views)