LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timed counter

Hi all,

 

I'm trying to implement a counter which would count from 0 to 2 with a preset amount of time at each number i.e. 0 wait 2 sec (say) and then 1 and wait 2s and so on upto 2 and then get back to 0. This counter must start counting when a trigger signal is asserted (implemented using case structure).

 

The other constraint is that the code cannot stop running at any instant (no while loops wired to stop). I've tried using shared variable, shift reg, while loop, for loop etc but to no avail. 😞

Any help appreciated!!

 

Thanks!

Sanjay.

0 Kudos
Message 1 of 7
(2,553 Views)

Use an Elapsed Time function to get the number of seconds, divide by 2 and round down.

 

Then use the remainder from Quotient Remainder on that value divided by 3.

0 Kudos
Message 2 of 7
(2,532 Views)
0 Kudos
Message 3 of 7
(2,516 Views)

Hi,

 

Thanks for the much needed speedy help!

I tried using the proposed solution but am faced with a different problem now. I have put the whole counter vi in a case statement. This goes to case '1' when the trigger is 1 and goes to case '0' otherwise.

The main problem is that this trigger goes to 1 for a few miliseconds when a certain condition is met (using external instruments) which then activates the counter in the case statement.

 

This proposed solution goes from 0,1,2 but I am unable to bring the value out of the case statement before the loop is finished!!! If the counter goes from 0 to 2, displaying the value outside the case statement would go directly from 0 to 2 (no 1 in between). I have tried shared variables, local variables (created a project and used global variables) but no use. I am not able to update values outside the case statement in real time.

 

Please help.

 

0 Kudos
Message 4 of 7
(2,469 Views)

You need to post your VI so we can see what it is you are trying to describe.  Without pictures, the words are just confusing.

0 Kudos
Message 5 of 7
(2,461 Views)

Hi,

 

I have attached the vi alongside. There is one case statement in the vi activated by a trigger signal. Rest of it comm with the devices.

 

Thanks!

0 Kudos
Message 6 of 7
(2,457 Views)

I hate to say it, but seeing the VI didn't clear up anything of what you are describing.

 

I think your VI has several problems.

 

1.  You have a broken wire because you don't have any source for the data on that wire.

2.  You have parts of your code disable, including the section that looks most like the counter functions from the earlier message.

3.  I'm not sure you understand dataflow.  You have a while loop that runs so many times until a value is less than 148.  Since the default data type for an orange wire is zero, then I believe your while loop will run just the single time.  Then the case structure won't run until the while loop ends because the structure is dependent on a wire coming from that while loop.  Your code inside that case structure will just run one time.  (That might mean 3 iterations of the For Loops if/when they are not disabled.)  Then your VI is done never to run again until you restart it.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 7 of 7
(2,451 Views)