06-06-2021 12:50 PM
Hello everyone
I am writing the goal/problems in our code and in addition, I am attaching the VI file with 3 issues highlighted on the front panel as comments. (Issue# , #= 1,2,3)
Note: if you want to run the code please don't forget to change the path of the text file in the code according to where are you saving it on your PC. The text file contains the variables we are using.
Goal: Two variables (data type is String – “Plant 1” & “Plant 2”) are inputs from the user. If “Plant 1” selected the LED should blink at “X” frequency and if “Plant 2” then at “Y” frequency. Note: The user can select One Plant or Both Plants (at a time). Code and Questions: 1. A code for blinking the LED using while and the shift register is working. 2. Next, we have tried to use Case Structure (selector, using with string data type – not sure, it is feasible: Question: How to use it?) to select “Plant 1” and “Plant 2”. Adding the code (blinking LED) inside the case structure, we are struggling to stop the while of that selected plant. Then we thought of using Event Structure. Still not helping it. Are we thinking of the right way to go ahead with Case Structure / Event Structure to achieve our goal or else there are some different functions in LabView which might help us to achieve it?
Thanks for helping
Ali
06-06-2021 01:49 PM
Hi ali,
all your "issues" are due to not understanding the basic LabVIEW mantra of "THINK DATAFLOW!"
(You really should take the beginner courses offered in the "Training resources" in the LabVIEW board header.)
Issue #1: Due to DATAFLOW that selection is only read once when your VI starts…
Issue #2: The stop button is stopping your while loop - but that may take some time depending on your frequency/OnTime settings…
Issue #3: It's the very same problem as in issue #1 - you don't obey to THINK DATAFLOW!
Btw. the meaning of "DATAFLOW" is explained in the LabVIEW help…
06-06-2021 04:42 PM
As Gerd already saind, do some basic tutorials. So far, you are completely misunderstanding the meaning of dataflow, a very simple concept once learn it.
Some more comments:
06-06-2021 05:42 PM
06-07-2021 01:34 PM
Hi altenbach
Thanks for your reply.
I have gone through your code and try to understand the logic behind it but I struggled with that subtract gate (substruct the output from build array from 1-second wait). what exactly mean here?
and why we have built an array of the millisecond timer value? I have googled that and I see how does this tick clockwork but I am not sure what are you trying to use it for in this code.
are you trying to approach real-time compilation (when the user presses some button to reduce the delay in response on the output LEDs)?!!
2. Why frequency is divided by 1000? so the final form, when it goes to be compared with that output from the subtractor, is ( ( 1000 / frequency) * Duty cycle %).
one more question please,
3. Why and how are we using shift registers with an array?
Thanks for helping.
Ali
06-07-2021 03:19 PM
The output of the wait is the same as the ms tick count, which is a relative counter that increments every ms.
Since the wait is in ms, we need to scale the frequency, which is in Hz, to something that makes sense to a millisecond counter. Thus the factor of 1000.
Since the elapsed time is relative to a start tick count, we need one for each LED, because they reset at different times, depending on the frequency. For each LED, we maintain a start tick and the difference to the current tick will give us the elapsed time. If the cycle is complete, we need to update to the new start tick so the difference start over with zero.
We need an array to store a starting tick for each LED. You can easily expand the same code to 10 LEDs by just increasing the array sizes. If you only had one LED, you would not need an array.
Basically, we calculate how many ticks it takes for a given frequency, and if we account for the duty cycle, we know how many ticks it takes for the LED to turn off. For example if the frequency is 10Hz, we wait for 100 tics to repeat, and if the duty cycle is 30%, the LED is true for 30 ticks. And so on.