Jerry1 Posted October 26, 2010 Share Posted October 26, 2010 I have included a very simple file that increments a DAC output by 0.005 Volts every second. The DAC0 output is connected to the AIN0 input of a LabJack U3-HV. This ADC channel "voltage" is read 10 times a second. If the "voltage" from the ADC channel is plotted along with the "output" DAC channel, everything appears about as expected. When I add a trace to the plot with the expression "voltage-output" strange things happen. The "voltage-output" trace continually moves up and down as time goes on. That is the history of this voltage difference is changing. If I slow down the ADC channel to 1 sample/second the voltage difference trace no longer continues its steady march up or down, and spends most of its time around zero as it should. However, if you look closely you'll see that periodically the history will briefly shift up and then back to where it belongs. Lastly, upon close evaluation it appears that the DAC is only able to change at an 8-bit resolution. That is, the minimum change appears to be about 0.020 volts. The DAC on this device is supposed to be 10 bits so it should be settable to something like 0.005 volt resolution. I'm not sure if this is a DAQFactory issue or a LabJack hardware issue. Got any Ideas? Link to comment Share on other sites More sharing options...
AzeoTech Posted October 26, 2010 Share Posted October 26, 2010 The attachments didn't come through, so I can't say until I see it. As for the DAC, you'd have to ask LabJack. We just pass the number to their driver and they quantize it as they need it. Link to comment Share on other sites More sharing options...
Jerry1 Posted October 26, 2010 Author Share Posted October 26, 2010 Sorry.. Here's the file simpleloop2.ctl Link to comment Share on other sites More sharing options...
AzeoTech Posted October 27, 2010 Share Posted October 27, 2010 This is because of alignment. The channel history is basically two arrays. For the A to D channel you have 10 array elements each second. For the D to A, only 1. DAQFactory has an Align() function that will align data by time, and will do it automatically with XY graphs, however when you do Voltage - Output you are simply subtracting the arrays as is, so the the most recent output value is subtracted from the most recent voltage input, then the second most recent output value (which is 1 second old) is subtracted from the second most recent voltage input (which is only 0.1 seconds old), etc. When you change the voltage to read once a second, that improves the issue, but you have to remember that the sequence setting the output, the background thread doing the input polling, and the refreshing of the graph are all running independently of each other. Sometimes it all lines up and you get 0. Sometimes, the graph refreshes after the output has changed, but before there has been an input reading with that updated value. This means that the whole array is shifted so you get the whole trace shifting from zero. The solution is to do the output and the input from the same thread. This can either be done by doing read(voltage) inside your ramp sequence after setting the output, or by setting the output from within the Event of the voltage channel. Link to comment Share on other sites More sharing options...
Jerry1 Posted October 27, 2010 Author Share Posted October 27, 2010 Thank You Very Much! I want to keep the 10:1 sampling ratio so I'm not sure how to do that as an event or reading inside the ramp sequence. It would seem like I could eliminate the alingment problem with this expression in the plot: voltage[0]-output[0] But I can't get it to plot. Am I missing something? Link to comment Share on other sites More sharing options...
AzeoTech Posted October 27, 2010 Share Posted October 27, 2010 Doing voltage[0] - output[0] returns the difference between the most recent readings, which is a scalar value and has no history, so it can't be graphed. If you want to keep the 10/1, probably the best way is to extend your sequence: output=0.25 private count = 1 while(1) if (count == 10) output = output + iif(output < 0.5, 0.005, -0.005) count = 0 endif read(voltage) myChan = voltage[0] - output[0] count++ wait(0.1) endwhile myChan is a new channel you'll create with Device Type "Test", I/O type "D to A". I did a couple of other tricks to make the sequence cleaner. There are several ways to skin the setting of the output. Finally, while usually wait() is something I usually discourage, this is a case where it is appropriate as long as we're working with a LabJack. If this was a serial/ethernet based device, it might cause problems because of timeouts. Link to comment Share on other sites More sharing options...
Jerry1 Posted October 27, 2010 Author Share Posted October 27, 2010 Thanks GURU, you people are terrific! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.