CamEraOld Posted December 16, 2005 Share Posted December 16, 2005 Hi, Perhaps it is because it is Friday way down here in New Zealand hence I am being a little think so this problem may be very straightforward. I have a U12 with 6 thermistors connected to it and based on the value from 1 thermistor I want to be able to turn a heater supply on. The thermistor in question is "Temp1" and I have specified that Dlg Out0 is called Relay. I have put a variable value component on my page which when pressed toggles between 0 and 1. I have sequence code as below Delay(5) while(1) Read(Temp1) If (Temp1[0] <20) //if temperature is too low Relay=1 //turn on hot water else Relay=0 //turn off hot water endif delay(1) endwhile I realise this code is no ideal but it does not seem to turn on Relay (Dlg Out0), my temperature value is way below the set point. I can click on the Relay variable value control and it will switch perfectly. Why does the code not work - I am sure it is something very simple? Thanks George Link to comment Share on other sites More sharing options...
LabJack Support Posted December 16, 2005 Share Posted December 16, 2005 Your code looks OK, so I am not sure what could be causing the problem. However I have a few suggestions for you to try. Since you are doing channel reads from a sequence, I assume the timing for Temp1 channel is set to zero. In the Event of your Temp1 channel place the code: If (Temp1[0] <20) //if temperature is too low Relay=1 //turn on hot water else Relay=0 //turn off hot water endif or better yet just: Relay = (Temp1[0] < 20) This second method uses boolean math. Note that neither of these methods have hysterisis so could result in your relay flipping on and off rapidly when Temp1 is near 20. The way the Event code works, is every time a new data point is read into Temp1 the code in the Event is executed. Make sure you remove the same code from your original sequence. If this still does not work, you might want to just create a sequence that toggles your digital out channel to see if that works. Something like while (1) Relay = 1 delay (1) Relay = 0 delay (1) endwhile Link to comment Share on other sites More sharing options...
CamEraOld Posted December 19, 2005 Author Share Posted December 19, 2005 Hi, Put that code into the event and it works great. no problems. Still not sure why it would not work as a sequence but no need to chase that now. Thanks George Link to comment Share on other sites More sharing options...
jrm16311 Posted February 21, 2008 Share Posted February 21, 2008 Greetings. I just started coding, and I'm having problems with a similar code as Cam-Era, with the exception that I wanted to set my "if" statement to evaluate a temperature vs. a set point I have in a virtual channel. I've tried the following but I keep getting an error. The basic code is as follows: while(1) read(A_TEMP) If (A_TEMP[0] < v.atemp1) valve=1 else valve=0 endif endwhile My problem is with the "If" statement and the inclusion of the v.channel, but I don't know how to properly formatted. Perhaps there is a better way to set user defined set points then using a v.channel, but I"m not sure. Any help would be greatly appreciated. Thank you. Link to comment Share on other sites More sharing options...
jrm16311 Posted February 21, 2008 Share Posted February 21, 2008 Okay, so figured out why I was getting an error, however, the sequence doesn't seem to work as intended. The actual code is almost identical to the one found on the DAQFactory user's guide on page 88. I've set the input timing to zero. The code is as follows: while(1) read(ATEMP) if (ATEMP[0] < V.ATEMP1) Valve = 1 while(ATEMP[0] < V.ATEMP1) delay(1) read(ATEMP) endwhile Valve = 0 endif delay(1) endwhile The sequence always opens the valve regardless of the temp reading and even if the temp reading climbs above the V.ATEMP1 setpoint, the valve doesn't turn off. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.