LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

latch to switch boolean conversion, or toggling flip flop in labview

Solved!
Go to solution

I'm a labview newbie, and i've been scratching my head about a particular problem.

 

I want to use a joystick (11button, 3 axis) to operate 2 PI microscope stages in tandem. I am thinking about the best solution to this problem:

 

 the joystick buttons provide latched booleans: they are only true while the button is held down. once the button is released, the boolean becomes false again.

I want to take this toggle and produce a true boolean the first time the button is pressed, and change that boolean to a false when the button is subsequently pressed.

My current idea is to try and construct something with either an occurance structure or notifier structure, or even something like a boolean to integer conversion then modulo-2 division.

 

Can anyone give me some pointers here?

 

thanks!

 

0 Kudos
Message 1 of 8
(14,178 Views)

Hi zipmanx,

 

Thanks for your post and I hope your well today.

 

You want, 

1st press --> LED = TRUE

2nd press --> LED = FALSE

3rd press --> LED = TRUE

 

I would sugget using a shift reigistor to remember the number of times the switch has been pressed. Then if the number of presses = 0 and the Switch is high then LED is = true, then in all other cases LED = False. For this you could use a case structure or logic, up to you. 

 

I hope this helps,

 

Kind Regards,
James.

Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
0 Kudos
Message 2 of 8
(14,153 Views)

I think you really want an output to toggle every time the button is pressed:

 

1st press = TRUE

2nd press = FLASE

3rd press = TRUE

4th press = FALSE

and so on.

 

If this is so then all you need is an event structure with shift register and a boolean NOT function.  See attached vi.

 

- tbob

Inventor of the WORM Global
Message 3 of 8
(14,135 Views)

One alternative i have that works is to read the latched bool, convert to int, mod2, reconvert to bool, all in a while loop with a shift register. It seems pretty bulky

 

latch to switch

 From a programming standpoint, which is better to use? an event handler as trob has suggested, or something like an occurance or a notifier?

Here's another one: can you do a bitwise shift in labview?

0 Kudos
Message 4 of 8
(14,132 Views)

zipmanx wrote:

 the joystick buttons provide latched booleans: they are only true while the button is held down. once the button is released, the boolean becomes false again.

I want to take this toggle and produce a true boolean the first time the button is pressed, and change that boolean to a false when the button is subsequently pressed.


You got the LabVIEW definition of "latched" wrong. In LabVIEW, a latched button turns true until it's value is read by the code (no matter how long that takes). Once the value is read, it automatically reverts to false again.

 

What you are describing is "switch until released". (Similar to the horn on your car).

 

You certainly don't need two CPU burner loops, local variables, integers, mod, and trimmings. What is your LabVIEW version and how are you reading the switches?

Message 5 of 8
(14,127 Views)
Solution
Accepted by topic author zipmanx

zipmanx wrote:

From a programming standpoint, which is better to use? an event handler as trob has suggested, or something like an occurance or a notifier?

Here's another one: can you do a bitwise shift in labview?


Since you are reading hardware, you probably need to poll it, so an event is out.

 

Yes, you ca do bitwise shifts in LabVIEW. Look in the "numeric...data manipulation" palette.

 

Here's one possibility to solve your problem (LabVIEW 8.5). There are many other ways to do this, but you dfefinitely don't need any blue wires for the logic. :).

 

Message Edited by altenbach on 12-01-2008 01:05 PM
Download All
Message 6 of 8
(14,122 Views)

altenbach wrote:

What is your LabVIEW version and how are you reading the switches?


We have labview 8.2, 8.5, and 8.6. by default we're now coding in 8.6

 

You are correct about the nomenclature error i have made, the joystick buttons are switch until released. I will read the axes of the joystick and the buttons from the directinput based labview subvi.

 

In my case will use labview globals to provide communication to dependencies, as the joystick operation subvi PI provides contains a while loop with a long cycle time. The joystick polling will have to be in a separate loop as it will not be uniquely operating this subvi, but more than one, simultaneously.

 

Would an occurance be better suited to this?

0 Kudos
Message 7 of 8
(14,073 Views)

altenbach wrote:

Here's one possibility to solve your problem (LabVIEW 8.5). There are many other ways to do this, but you dfefinitely don't need any blue wires for the logic. :).

 


This is better than what i coded before. In fact, i see that what i've coded is flawed with a switch when released behaviour. Another improvement on my algorithm is that you're only carrying 2 bits in memory for the loop iteration rather than 16 or 8 for the integer. The integer to bool array to array index, can be replaced by a bit rotation with a carry as the boolean indicator; but as you have stated, this is not a latch situation.

 

I would be quite interested to see what other alternate ways you have in mind are.

 

thanks altenbach.

0 Kudos
Message 8 of 8
(14,068 Views)