11-25-2011 04:41 PM - edited 11-25-2011 04:46 PM
I do not really know what you tried to achieve in the last version. I didn't suggest you to replace "Tick Count" block, but the "Wait" function inside the for loops that are used for controlling LEDs.
I will not give you a ready solution, but I can give you a hint. Consider the diagrams (they are VI Snippets) below:
We have a boolean control "Condition" and a boolean indicator called "Alarm". Whenever "Condition" is true, we will start blinking the "Alarm" every 200ms. What would happen in this implementation? The same as happened to you before - setting the condition to "1" would not only start blinking the LED, but it would also delay the execution of the WHOLE program by 200ms (when you run the code, please notice that when you change the value of "Condition", the "Numeric" indicator also starts to increase slower).
How to do it correctly?
Have a look below:
This time, when the "Condition" is a true value, we do not delay the execution, but we start the timer and in each subsequent iteration we check whether set time (200ms = 0,2s) has passed. If it has, the signal changes it's value, hence the diode blinks.
BR,
11-26-2011 08:52 AM
I understood the difference between the two snippets and the way to avoid slowing the code, but the concept behind each is different.
In my previous vi, the LED turnd on for 300ms and turn off directly; now I have changed the code I believe that it is IMPOSSIBLE to keep the LED as in the previous vi on for 300ms and then off.
Thank you
11-26-2011 10:58 AM
Did I say impossible I'm sorry but I think I'm mistaken.
I have changed some parts in the vi but still it's not giving the result that I aimed for.
I changed the conditions if the elapsed time is false then the LED should light,
when the elapsed time is true the array should change back to zero and the integer responsible for moving between the elements of the array changes ++1
still the vi is not working; the value of elapsed time is always true.... the array remains zero.
Any suggestions?
Thank you
11-26-2011 12:59 PM
I forgot to attach this image:
The graph im getting is different than the graph on the left.
11-26-2011 06:24 PM
I am not sure what you are trying to do, but I think you have a flaw in your logic.
The only time the boolean arrays are not all False is when the gas concentrations are above the limits AND the elapsed time is False. The only time the array index is greater than zero is when the elapsed time is True. So you can never get any array elelment to be True except the zero element.
Put a Wait (ms) inside your loop. It does not need to run thousands of iterations per second.
Lynn
11-27-2011 03:08 AM - edited 11-27-2011 03:11 AM
@johnsold wrote:
The only time the boolean arrays are not all False is when the gas concentrations are above the limits AND the elapsed time is False. The only time the array index is greater than zero is when the elapsed time is True. So you can never get any array elelment to be True except the zero element.
Doesn't the elapsed time become true every 0.3 sec? What I tried to do is:
When the elasped time is false, It makes an element from the array true according to the index. [**]
So how to get the index?
Well what I did is:
So every time the elapsed time is false( according to [**], the LED becomes on for 300ms;the time when the elapsed time is false)
If the elapsed time is true(here I thought that I should increment the index each time because for the next 300sec the elapsed time is false and the LED will be on for 300ms) and the concentration of gas becomes higher than the limit the index is incremented.
If any of them is false, then no increment for the value of the index.
What I tried to program is:
When elapsed time is false which is about 300ms the LED is true.
When it is true which is about 0sec then the LED are false and the increment happens when it is above limit and when it is true.
I think that it is the a good way because here we can follow the graph directly[ but I think the first LED may not light for 300ms]
@johnsold wrote:
Put a Wait (ms) inside your loop. It does not need to run thousands of iterations per second.
Lynn
I have included the wait in previous attached vi but the graph becomes illogical when we reach the limit;
the program runs hundreds of times per sec before we reach the limit and when we reach , it runs max of 3 time.
I attached the pic of the graph with the wait.
I have changed the condition of the elapsed time to true, the program seems to respond well. Any suggestions on solving the problem for the first LED or improving the code?
EDIT: I know it is convoluted but its the only way not to cause the above problem with the graph.
11-27-2011 11:56 AM
Read the detailed help for the Elapsed Time Express VI. I think you want to set Auto Reset to True. Put boolean indicators on the Time has Elapsed and on the CO >= 45 and NH >= 25 comparators. Watch what happens. Then change the Auto Reset and try again. ---- I see you have found this on your own.
I am not seeing any problems with the Charts.
As for changes to your program, I would probably use a state machine. If what you have is working satisfactorily and you do not expect to make many changes, it might not be worth taking the time to change it. I would claen up the diagram and eliminate much of the redundant code. Moving the Array to Cluster primitives outside tha case structures means that you only need two rather than six. You only need to intialize the boolean array once. Just wire a copy where needed.
Lynn
11-27-2011 12:26 PM
Thanks, I will clean up the code and follow your comments.