From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SIngle Push Button toggle

On the face of it, when first told it looked a simple requirement : There is a single push - to - on hardware switch which is read by a DAQMX read function as a digital input inside of a 50ms timed loop.  Every time the user pushes the switch momentarily ( momentary can be anything from 100 to 500ms depending on the user's mood), I should toggle the state of a lamp - If its ON it must go OFF and if OFF must come ON.
 
Enclosing a small code ( in LV8.0) that attempts doing this and  is reasonably successful when the Timed Loop is set for a timing of 1000ms. But do it with 50ms timing ( which is what I want ) and you find getting the required state of the lamp is a challenge of reflexes !!
 
Yes I can solve the problem easily with a Event structure but the input comes from a field element - hardware switch. And the machine uses code written in LV7.1.
 
Any suggestions ? 
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 18
(5,398 Views)

Problem solved Smiley Very Happy

Attaching the VI that just does not care what your reflex speeds are and for every click  reliably changes the state of the lamp.

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 2 of 18
(5,394 Views)

I don't think you need so many stacked case structures. Here's a quick alternative that looks a bit simpler. 😄



Message Edited by altenbach on 05-03-2008 11:36 PM
Download All
0 Kudos
Message 3 of 18
(5,386 Views)
>>Here's a quick alternative that looks a bit simpler.
 
Agreed. But only when you can figure out boolean logic like the back of your hand.
 
As for me I never even knew that a function called "Implies" is there !  Thanks for sharing the novel code.
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 4 of 18
(5,377 Views)
An XOR of the old an the new button returns TRUE when the state changed.
On true you could invert your lamp.

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 5 of 18
(5,370 Views)


Raghunathan wrote:
Agreed. But only when you can figure out boolean logic like the back of your hand.

It is useful to know the boolean palette a little bit!
 
Looking at your code, a few thing jump right out:
  1. For example the entire innermost case is just an "invert" (much less exotic than an "implies". 🙂
  2. Looking at you specs, I am pretty sure that you actually want an "=0" instead of an "=1". It will react quicker.

Still, I recommend my code. It does the same thing wilth much less code. 🙂



Message Edited by altenbach on 05-04-2008 10:39 AM
Message 6 of 18
(5,356 Views)

Can we do the same thing using hex values. I mean

when 00011110 received I should get 11111110 ( if 7 Led are present in the front panel)

when I  send 00011110 again I should get 11111111 (Last bit toggled)

 

similarly , when i send 00011101  ---------->  11111101

               when I send 00011101 again -----> 11111101

 

               when i send 00011011  ---------->  11111011

               when I send 00011011 again -----> 11111011

 

               when i send 0001011  ---------->  11110111

               when I send 0001011 again -----> 11110111

 

               when i send 00001111 ---------->  11101111

               when I send 00001111 again -----> 11101111

 

And any of the bits should not change until I receive the same value again.  And I can send Randamly any of the bit low and corresponding to that my led in front panel should vary.

 

Plz help me in this.

 

 

 

 

0 Kudos
Message 7 of 18
(4,963 Views)

Sippy wrote:

Can we do the same thing using hex values. I mean

when 00011110 received I should get 11111110 ( if 7 Led are present in the front panel)

when I  send 00011110 again I should get 11111111 (Last bit toggled)

 

similarly , when i send 00011101  ---------->  11111101

               when I send 00011101 again -----> 11111101

 

               when i send 00011011  ---------->  11111011

               when I send 00011011 again -----> 11111011

 

               when i send 0001011  ---------->  11110111

               when I send 0001011 again -----> 11110111

 

               when i send 00001111 ---------->  11101111

               when I send 00001111 again -----> 11101111

 

And any of the bits should not change until I receive the same value again.  And I can send Randamly any of the bit low and corresponding to that my led in front panel should vary.

 

Plz help me in this.

 

 

 

 


 

Your description is ambiguous.  After thte word "similarly", The binary values on the right side do not change.  But in your first statement, the value changes.  It looks like you are wanting a 0 in any bit position meaning to toggle a certain LED.  Yet, your first three binary digits are always 0's and the right side shows no toggling.   You stated you had seven LEDs, but you are showing eight bits.  This is very confusing.  Assuming you had seven LEDs, is this what you want:

 

               Normal output  1111111

Send 1111110    Output  1111110  (toggles bit 0)

Send 1111111    Output  1111110  (stays the same)

Send 1111110    Output  1111111  (toggles bit 0)

 

Send 1111101    Output  1111101  (toggles bit 1)

Send 1111101    Output  1111111  (toggles bit 1)

 

Send 1111010   Outptut  1111010  (toggles bits 0 and 2)

Send 1111101   Outptut  1111000  (toggles bit 1 but leaves 0 and 2 alone)

 

Send 1111000   Output   1111111  (toggles bits 0,1,2)

 

In other words, a 0 in any position will toggle the corresponding LED.  Is  this what you want?

 

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 18
(4,932 Views)

Kind off, 

 

I have 5 different input values. for example A1,A2,A3,A4,A5.

and 7 leds at the output (Default all are forced to be high)

 

When input is A1 (00011110)  ---->  Out put is 11111110 (last bit goes off)  and when input is A1 again the 0th bit toggles.

When input is A2 (00011101)  -----> 11111101   and when input is A2 the 0th bit toggles.  

When input is A3 (00011011) --> 111111011     and when input is A3 the 0th bit toggles.

When input is A4 (00011011)   ---> 11110111     and when input is A4 the 0th bit toggles.

when input is A5 (00010111) ---> output is 11101111    and when input is A5 any point of time the 0th bit toggles.

 

And when A1,A2 sent together Logically i ll get 00011100 (A1&A2) so the output is 11111100 

 similarly with other combinations like A1A3, A2A3 ..... A1A2A3A4A5 you get 32 such combinations but i want a generic design. It can be done using 32 case structures but I don't want to do so.

 

Basically I am receiving the A1,A2,A3,A4,A5 from Status port of parallel port (which is a push button) and I am using input.vi and using address 379 and doing some combinations so that in my outport.vi which has address 378 and D0 to D7 lines (LEDS) I get the output as mentioned above. 

  

 

In my understanding I should play only with single bit. I am able to turn off the leds when A1,A2,A3,A4,A5 are sent and with the combinations. but not able to turn them ON when sending A1,A2,A3,A4,A5 again. 

 

what i am doing is when I send 00011110  ---> I check if the last bit is 0 or not if it is 0 then enter the loop and perform this opeeration 11111111 & FE and send to Data port using outort.vi when A2 (00011101) checks if the bit is 0 or not in the input side if 0, now the output is *******0... so 

what ever output I am getting I am again ANDing with FD  to get ******0* this way my previous status of LED will not get affected.  

for A3 (00011011) what ever output i get ANDed with FB... and so on. 

 

When A1 (00011110) is received again in the input side it checks if the bit is 0 or not and it should check if D7 bit (*******0) is 0 or not if 0 the it should toggle.

when A2 (00011101) is received again in the input side it checks if the bit is 0 or not and also it should check if D6 bit (******0*) is 0 or 1 if 0 then toggle that bit to 1 and if its 1 toggle that bit to 0...  

0 Kudos
Message 9 of 18
(4,914 Views)

I'm sorry.  I'm even more confused that ever.  Judging from lack of response to your question, I would say that others are confused too.  Perhaps if you stated these properties:

 

1.  What generates the A1 through A5 numbers?

2.  How do you process them exactly (AND with FE and such - use bit notation D7 for MSB and D0 for LSB)?

3.  After processing, where does the output go?

4.  How are the LEDs controlled?

 

Here are some ambiguities in your statements:

 

"When input is A2 (00011101)  -----> 11111101   and when input is A2 the 0th bit toggles"  -  its not the 0th bit that toggled, it is bit 1 that toggled.  Use notation like D0 and D1, the bit pattern would be D7 D6 D5 D4 D3 D2 D1 D0.

 

"In my understanding I should play only with single bit"  -  yet you show manipulations of several bit, not a single one.

 

"perform this opeeration 11111111 & FE "  -  why perform the operation?  11111111 & anything will always produce the anything number.  Just send out FE.

 

"when A2 (00011101) checks if the bit is 0 or not in the input side if 0, now the output is *******0"  -  which bit are you checking for 0, D1 I guess.  But your output shows D0 bit being 0, not D1 bit.  Are you wanting to always toggle D0 for the output whenever any input pattern has a 0 in it?

 

It seems like this is what you want to do:

input = 00011110 - toggle output bit D0

input = 00011111 - no change

input = 00011110 - toggle output bit D0

input = 00011101 - toggle output bit D1

input = 00011010 - toggle output bits D2 and D0 but leave D1 alone

input = 00011000 - toggle output bits D2 D1 D0

Is this correct?

 

I'm not trying to pick your explanation apart, I'm just trying to help you.  But I cannot help if I don't understand your criteria.

 

 

 

- tbob

Inventor of the WORM Global
Message 10 of 18
(4,906 Views)