rlrepoff Posted June 17, 2014 Share Posted June 17, 2014 Hello, I am setting up a project that will measure the temperature and adjust appropriate flows of air through my system. Right now, I have 2 different sequences that are controlling each the flow and the reading of the temperature and RH (using a SHT15 Temperature and RH sensor). I have these connected to a LabJack. My flow is adjustable through a stepper motor, which is controlled by one of the sequences. The SHT15 Temp and RH sensor is controlled by another sequence. When I run the stepper motor sequence alone, the motor works at regular speeds. When I run the stepper motor sequence with the SHT15 sequence, the stepper motor slows down drastically. I do have other sequences in my system, but they do not adversely effect the stepper motor's speed. I think it has to do with the way the data is collected from the SHT15 sensor via the LabJack. The SHT15 Temperature and RH are both Test channels. I have attached the two sequences below for reference. Any help is greatly appreciated! ****************SHT15 Data Collection Sequence:******** private err; global string strIn private CO2PPM // Get reading and save them while(1) // Line up requests AddRequest (ID, LJ_ioSHT_GET_READING, LJ_chSHT_TEMP, 0, 0, 0) AddRequest (ID, LJ_ioSHT_GET_READING, LJ_chSHT_RH, 0, 0, 0) // Execute requests and check for errors GoOne(ID); ErrorHandler(ID); // Get temperature reading err = GetResult (ID, LJ_ioSHT_GET_READING, LJ_chSHT_TEMP, @dblValue) eErrorHandler(err, LJ_chSHT_TEMP, LJ_ioSHT_GET_READING) Temperature.AddValue(dblValue-273.15) // Get humidity reading err = GetResult (ID, LJ_ioSHT_GET_READING, LJ_chSHT_RH, @dblValue) eErrorHandler(err, LJ_chSHT_RH, LJ_ioSHT_GET_READING) Humidity.AddValue(dblValue) catch() // catch any comm errors and ignore delay(.1) endcatch endwhile ********************STEPPER MOTOR SEQUENCE:************************** global n=0 global string moving = "" while(1) global DilutionCalc = 0 global LowFlowCalc = 0 global HighFlowCalc = 0 LowFlowCalc = ((MicroAethFlow*((DilutionRatio-1)/DilutionRatio))-(MicroAethFlow*Tolerance/100)) ?LowFlowCalc HighFlowCalc = ((MicroAethFlow*((DilutionRatio-1)/DilutionRatio))+(MicroAethFlow*Tolerance/100)) ?HighFlowCalc while ((mean(honeywellflow2[0,300]) > MicroAethFlow) || (mean(honeywellflow2[0,300]) > (HighFlowCalc))) //change the conditions to variables //need to turn counterclockwise to get flow reduced step_dir[0] = -1 if(step_dir[0]==-1) while(n<15) for(private.i = 0, i <= 7, i++) for(private.j=0,j<4,j++)//loop to set up all digital channel output settings private.chanpass = testbit(motor_lookup,j) j=j+2 AddRequest (0, LJ_ioPUT_DIGITAL_BIT, @j, @chanpass, 0, 0)//channel j to setting dictated in binary lookup values j=j-2 endfor goOne(0) delay(motorSpeed/1e6)//delay to allow for motor movement endfor n=n+1 endwhile moving = "Moved CCW to lessen flow" ?moving n=0 delay(60) endif endwhile //switch // case(step_dir[0]==1 || step_dir[0] ==-1) // step_dir.addvalue(0) // case(step_dir[0]== 0 && step_dir[1]==1) // step_dir.addvalue(-1) // case(step_dir[0]== 0 && step_dir[1]==-1) // step_dir.addvalue(1) //endcase while(mean(Honeywellflow2[0,300]) < LowFlowCalc) //change conditions to variables step_dir[0]=1 if(step_dir[0]==1) while(n<15) for(private.i = 7, i >= 0, i--) for(private.j=0,j<4,j++)//loop to set up all digital channel output settings private.chanpass = testbit(motor_lookup,j) j=j+2 AddRequest (0, LJ_ioPUT_DIGITAL_BIT, @j, @chanpass, 0, 0)//channel j to setting dictated in binary lookup values j=j-2 endfor goOne(0) delay(motorSpeed/1e6)//delay to allow for motor movement endfor n=n+1 endwhile n=0 endif moving = "Moved CW to increase flow" ?moving delay(60) endwhile while(mean(HoneywellFlow2[0,300]) > 35 && mean(HoneywellFlow2[0,300]) < 50) step_dir = 0 moving = "The flow is correct. No movement neccesary." ?moving delay (120) endwhile endwhile Link to comment Share on other sites More sharing options...
AzeoTech Posted June 18, 2014 Share Posted June 18, 2014 The problem is that your SHT collection sequence runs at full bore. There is no delay, except in the catch() which will only execute if there is an error. This doesn't flat out hang DAQFactory because you are most likely on a multicore machine, and because there are small delays for the LabJack communications. The problem is that 99.9% of the time spent in the loop is actually doing labjack comms, and when you have that running, you aren't leaving any space for the stepper motor commands to get through. The pipe to the LabJack is only so big and you are filling it with the SHT sequence. I don't know what the motorspeed variable is set to, so don't know how fast you are sending commands to the LabJack from that sequence. So, add a delay to the SHT, maybe delay(1)? Or maybe (0.1) if you really need it that fast. That will likely fix it. BTW: it takes about 5ms (0.005 secs) to query the LabJack, i.e. in the GoOne() call. During that time, any other GoOne()'s to the same device cannot execute and will wait. BTW: Put 0's in front of your decimal places so the decimal doesn't get lost: 0.1 not .1, and don't forget to properly indent. Link to comment Share on other sites More sharing options...
AzeoTech Posted June 18, 2014 Share Posted June 18, 2014 I got some feedback from LabJack. The 5ms time I mentioned is for just doing the query. However, for the SHT15, it takes an additional 320ms to read the temp sensor and 80ms to read the humidity and the LabJack is fully blocked during that time, meaning your stepper motor control won't be able to communicate. This means putting a delay() in the SHT sequence isn't going to fix the problem. You have two choices here really: 1) switch to analog temperature and humidity readings, though you'd still have the issue of the 5ms, though it may not be a problem provided you add a delay 2) buy a U3 or another LabJack and have one do the SHT and any other slow stuff, and the other do the stepper control Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.