LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Basics - edge detect or software counter

I'm trying to build a basic counter in software - push a button and a number increments - with a while loop (or any other way). Can't get it to work. The loop clears and doesn't hold a boolean in a shift register when the enable is cleared so I can't single step it. This should be real easy stuff yet can't find any info anywhere, search for "software counter" comes up with nothing. Just using LabView, no hardware. Where is all the basic beginner stuff that would have this?
0 Kudos
Message 1 of 9
(5,580 Views)


Hi,

I am attaching a simple 7.0 VI which shows this. A shift-register is used to accumulate the counts.

Note that the mechanical action for the button is (and should be) Latch When Released.

Also, the same can be implemented using the Events Structure (instead of the While loop), and in fact is the better way of doing it.

Hope this is what you wanted.

Regards,

Khalid

0 Kudos
Message 2 of 9
(5,580 Views)
Sorry, I only have version 6.0 of Labview and it won't open this. Any way of saving as an old version, or sending me PDF of the diagram? Thanks for your help.
0 Kudos
Message 3 of 9
(5,580 Views)

I am attaching the diagram screenshot as a JPEG file.

Hope this helps.

Khalid

0 Kudos
Message 4 of 9
(5,580 Views)
This just counts continuously as long as the button is held down. I could just hook the button to the loop enable and use the index as the count to do this. I need to count button pushes, need to detect the edge of the button signal.

I tried using an AND to the loop enable, ANDing the button and NOT return from a boolean shift register (the shift register output is the button). This should allow it to run one loop cycle and then stop, but it doesn't work. Can you explain why? And in general, where is the detail on the loop and shift register operation? All the help and manual just give the basics, none explain why the above doesn't work. Is there a Labview for Dummies or something that goes into the fine details?

Thanks-
0 Kudos
Message 5 of 9
(5,580 Views)



This is the problem when viewing the "diagram" versus actually using the VI. As I said in my first response, the Mechanical Action of the button is important -- it should be 'Latch When Released.'

Right-click on the button, select Mechanical Action, and then select 'Latch When Released.' This will give you the desired behavior with my diagram. Try it.

As for the in-depth fundamentals of G programming, in addition to the Online Help, and manuals, you may want to consider taking an Advanced LabVIEW course from NI. Here's the link for the training dept.:

http://www.ni.com/training/

Can you attach your version of the VI so we can know why it isn't doing what you want it to do.

Thanks,

Khalid>


0 Kudos
Message 6 of 9
(5,580 Views)
Changing the mechanical action defeats the purpose of edge detect. This signal may come from an external I/O or elsewhere where the timing relative to the while loop is not known. I have attached a VI. I still don't see why this doesn't work, and why the count resets to zero every time. Nothing in the info about the While or shift register describes this behaviour.

Thanks again for your help.
0 Kudos
Message 7 of 9
(5,580 Views)


In your VI you have the mechanical action as switch-until-released (which may be exactly what you want), BUT this means its boolean value is false except when you click on it. And running the VI and clicking on the button precisely when it is read is almost impossible to do. So, the loop always stops after first iteration.

You're not running the VI in the 'Run Continuously' mode are you? That may give you the impression that your While Loop is running continously whereas in fact it only re-running the VI as soon as it stops.

If you run the VI in execution highlight mode (click on the light bulb on the diagram toolbar), you can "debug" and see why your VI doesn't work.

Hope this helps.


Regards,

Khalid

0 Kudos
Message 8 of 9
(5,580 Views)
Hello, 

The problem I have is almost the same. I also want to count the number of times a input (bool) get's the value True. In my case the input isn't a switch and so it can stay True for a couple of seconds. In the included VI i did place a switch, but in the final program i get this value from a input. In this case, it sometimes keeps counting when the input is true and if I try it a different way it won’t count at all. I tried to fix this problem using a formula node, a extra variable z and some if statements (as you can see in the attached VI) but I can’t get it working.

 Does anyone know how to solve this problem?

 

Message Edited by Adrie de H on 10-22-2008 03:33 AM
0 Kudos
Message 9 of 9
(5,104 Views)