# LabVIEW

cancel
Showing results for
Did you mean:

Highlighted

## newbe help with understanding order of execution and timing

Hi,

I feel silly needing help with such a simple problem, but I'm new to labview and I'm having a hard time understanding using simple loops to time events.

here's the problem I'm trying to solve:

" build a disyplay with four LEDs; green, red, yellow, and orange. Design code to make the red and green LEDs flash alternelty in 10 seocond intervals.

The yellow LED will turn on everyother time the green LED is lit, but will stay on for only 5 seconds. The orange LED will flash in 1/2 Hz intervals for 7 seconds anfter the yellow LED has shut off.

(Using loops and shift registers only)

"

As you can see below I figured out how to make the red and green led part, but I loop for the yellow and orange LED is not working right at all.

The order in which the loops exicuite makes no sense to me coming from traditional programing.

Any help would be GREATLY apreicated,

Thank you!

Message 1 of 19
(1,722 Views)
Highlighted

## Re: newbe help with understanding order of execution and timing

Sometimes it helps to step back and focus on the Big Picture.

First, it looks like things are happening on a 1-second time scale.  Some LEDs turn on every 5 seconds and off five seconds later, some turn on a certain amount of time after something else happens, etc.

I'd make a While loop whose index ("i") counts seconds.  I'd then think of what logic I need to illuminate a light.  For example, suppose I say "The Brown Light goes on after 4 seconds being off, then stays on for 3 seconds".  How can I express this mathematically?  Well, the Brown Light is cycling every 7 seconds.  Suppose I do an Integer Divide (the Quotient/Remainder function) of the Seconds by 7.  If the number is 4, 5, or 6, the Brown Light is on, otherwise it is off.  [The Coerce and In Range function can be very helpful here].

Do similar logic/math for your lights.  I haven't looked carefully at your Homework Assignment, but this should at least get you started ...

Bob Schor

Message 2 of 19
(1,713 Views)
Highlighted

## Re: newbe help with understanding order of execution and timing

I would use the Elapsed Time express VI here.  Have your loop run at like 100ms.  But then the elapsed time will tell you if 10 seconds have passed.  When 10 seconds have passed, toggle the green and red LEDs.  You can add some more logic and another Elapsed Time for the yellow LED.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 3 of 19
(1,689 Views)
Highlighted

## Re: newbe help with understanding order of execution and timing

OK. it is your first post, and you obviously found the forums to help with "Homework"-

I COMMEND that! However, let's start with the basics- post a "snippet" of the four Boolean Front panel objects that have properties set to those colors you describe?  A picture of a block diagram is not the right way to start to "Build a display"  Then we can get into timing on the BD.  Can you show that display?

Trust me! the "USER" wants four bool indicators with certain properties set... how did you start?... Knowing that, I bet you learn more.

"Should be" isn't "Is" -Jay
Message 4 of 19
(1,668 Views)
Highlighted

## Re: newbe help with understanding order of execution and timing

Hey guys,

Thank you for the replies guys and sorry for my delay. Here's what I've been able to come up with in the past 24 hours. The lights all flash at the right rate and right number of times, but their timing is still incorrect. Sorry for also not including the display as well.

Bob, that makes sense what you said, logically , but I'm not sure how to implement it in the loops. What's funny is I could build this whole circuit in analog in about an hour. I thought labview would be like that, but I guess not.

This the second assignment of the class and I'm still pretty much clueless, especially we were never provided with any kind of course material (teach yourself labview class, yay).

Crossrulz, interesting, I'm sure that's a better way to do but they wanted us to use on the real basics to make this program work.

Jeff, I included a diagram this time!

Message 5 of 19
(1,607 Views)
Highlighted

## Re: newbe help with understanding order of execution and timing

First: You should know that you can select the entire block diagram and then use Menu>>Edit>>Create VI Snippet from selection to generate a *.png file that actually contains code!  Posting one of those instead of just a picture helps us help you!

Then: You are correct, the timing is not quite right.  The while loop will iterate every 20 seconds.

Why?

You have three parallel For Loops:

2 iterations at 10second = 20 sec

14 iterations at 1/2 sec = 7 seconds

2 iterations at 5 seconds = 10 seconds

Since this is homework I'm only going to give you a hint rather than earn your grade for you (Fair enough?)

Shift registers to store current state of each independant LED is necessary and correct- GOOD!

You got the FP properties correct! Good!

Each "Blink rate" is a multiple of 1/2 sec.  What if: you used a single while loop and used three "Quotient And Remainder" primitives to determine when to change state?

There are other possibilities.  Kudos for each you might propose.

"Should be" isn't "Is" -Jay
Message 6 of 19
(1,593 Views)
Highlighted

## Re: newbe help with understanding order of execution and timing

The easiest solution to your problem will require a single loop.  You'll want to remove those for loops.

You've made a couple mentions related to other languages and hardware methods.  Let's step away from the LabVIEW code.

Give me pseudo code to handle this in a text-based language.  Please tell me you wouldn't be using multiple loops there.

Message 7 of 19
(1,577 Views)
Highlighted

## Re: newbe help with understanding order of execution and timing

Jeff,

So I know where you're going with this, but not really how to impliment it.

I'm trying to generate either a 0 or a 2 and then feed that into the led for loop??? So somthinig like this?

Message 8 of 19
(1,573 Views)
Highlighted

## Re: newbe help with understanding order of execution and timing

Only 1 loop with no loops inside.  Your shift registers will need to be on the only while loop and there is only 1 wait.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 9 of 19
(1,566 Views)
Highlighted

## Re: newbe help with understanding order of execution and timing

Getting there.....

You do not need three loops. and DO look at the rest of the Comparisons palatte

Try one more time on your own

Then and only then look at the spoiler.  (I might not make it back to the forums later and do not want to leave you hanging

Spoiler

"Should be" isn't "Is" -Jay
Message 10 of 19
(1,552 Views)