LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Relay switch and control

Hi all,

 

I am trying to write a Labview program to control a powered relay. I have to acquire 2 analog inputs and compare one of them to a fixed value and if the voltage acquired is higher or equal to the fixed value then the relay should switch position BUT remain in that position even if that voltage is reduced to be smaller than the fixed value compared with. Also the data acquisition should still take place until I press a stop button.

I did write a code for this purpose but does not seem to work for some reason, It does not quite do what I want.


I have attached the code.

 

0 Kudos
Message 1 of 11
(3,258 Views)

@persseur wrote:

Hi all,

 

I am trying to write a Labview program to control a powered relay. I have to acquire 2 analog inputs and compare one of them to a fixed value and if the voltage acquired is higher or equal to the fixed value then the relay should switch position BUT remain in that position even if that voltage is reduced to be smaller than the fixed value compared with. Also the data acquisition should still take place until I press a stop button.

I did write a code for this purpose but does not seem to work for some reason, It does not quite do what I want.


I have attached the code.

 


 

you need a latch, plus your while loops are running %100, put a wait ms function....

 

what do you mean, can you explain? "I did write a code for this purpose but does not seem to work for some reason, It does not quite do what I want."

 

Spoiler
latch.png

 

0 Kudos
Message 2 of 11
(3,247 Views)

Apok,

 

Thank you for your response.

Excuse my ignorance, I am quite a beginner in terms of Labview coding.

I understand that in the latch.vi code you attached, when the slider reaches a value of 5 or higher the boolean light turns on. And if the slider returns to a value below 5, the boolean stays on. How is that achieved on the code? In other words, can you explain how the code works?

Also what is the use of the wait time you added, is it just to wait 50ms before the next iteration takes place?

 

Thank you for your time.

 

0 Kudos
Message 3 of 11
(3,213 Views)

What I meant about the code I wrote that doesnt do what I want is abt the code I attached on my first post. It doesnt do what I want it to do: first I get some error "attempted to read samples that are no longer available". Secondly when the value compared is reached, the Digital output and the boolean do not swith on as I want it to.

0 Kudos
Message 4 of 11
(3,205 Views)

@persseur wrote:

Apok,

 

Thank you for your response.

Excuse my ignorance, I am quite a beginner in terms of Labview coding.

I understand that in the latch.vi code you attached, when the slider reaches a value of 5 or higher the boolean light turns on. And if the slider returns to a value below 5, the boolean stays on. How is that achieved on the code? In other words, can you explain how the code works?

Also what is the use of the wait time you added, is it just to wait 50ms before the next iteration takes place?

 

Thank you for your time.

 


yes...the OR logic bool ouputs a '1' when any input is '1' or 'true statement', so i suggest putting that into your code and wire the latch bool to your Daq write digital output.a shift register holds that memory until you have changed it. the wait ms function is how long the loop iterates the code within the while loop, if you had not put that within the loop...you will use %100 of the CPU, try atleast in putting a '0' connected to it. on the block diagram or front panel is a 'question mark' tab in the upper right hand corner of the window, depress it and then hover over these functions and you will get a quick description window popup...click the detail link within it and get a full description.  try the online tutorials  Smiley Wink

Message 5 of 11
(3,197 Views)

Thank you for your reply.

 

I have modified the code to include something similar to the latch code.

I have attached the new code. However when I run it on "highlight execution"...I get error message "Attempted to read samples that are no longer available. The requested sample was previously available, but has since been overwritten.  Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem."

 

Do you have any idea how to fix this? and does the code look correct to you?

 

Thanks.

0 Kudos
Message 6 of 11
(3,189 Views)

i ran your vi and don't see the problem you are facing...i cleaned up your vi a little with putting a wait function within the loop, try not to use local variables if you can directly wire to the function Smiley Wink

0 Kudos
Message 7 of 11
(3,177 Views)

Thanks again Apok.

If you try to run the vi when "highlight execution" button (the little bulb on the tools next to pause button) is on and you let the vi run for a minute...the error pops up indicating the problem coming from the DAQmx clear task vi.

Also I want the code to be running at real speed...so as soon as the voltage compared is reached I want the digital output to swith position instantly. Is that not delayed by having the 50ms wait time?

 

 

0 Kudos
Message 8 of 11
(3,169 Views)

it sould not...you can do this instead...i probed the error lines and i get no error?  Smiley Indifferent

time.png

 

try this little vi to uderstand why...

 

for errors: add simple error handler and wire errors to stop. your vi is running like a champ for me and has not stopped on error as shown...

 

Spoiler
Volt-code V4 11-04-2013mod_BD.png

 

0 Kudos
Message 9 of 11
(3,163 Views)

hmmm that is very strange...anyhow I have added the error handler vi and wired the errors to stop But I still get the error.

Please see below a screenshot after a highleted excution run, its error 200279 (note that when I do run the vi without highlight excution, it seems to run fine, it seems so anyway).

 

 

0 Kudos
Message 10 of 11
(3,143 Views)