Hi,
I have a function that uses the DAQ toolbox to send a sinusoidal loading profile to a motor while gathering force and displacement data from sensors. An excerpt from my code that is causing the issue is below.
If its running correctly, each loop iteration should take more or less the exact same amount of time, but occasionaly this is not the case. Recently, I ran the code and it took much longer during a loop iteration than usual (about 0.5s instead of the usual 0.01s) about 3.96 seconds (and again the next time I ran it after 2.96s) into the sinusoid which meant that the motor got the message to change speed/direction too late and it overloaded my samples before continuing with the next iteration (all of the other ~345,000 iterations occured at correct speed). This is the first time I've ran into this issue in the last few months of regular use, but I have ran into this issue a while ago so this doesn't seem like a one time event. I also don't believe this is a hardware issue since a previous program we used to control them (written in C++ but unable to be used anymore) didn't have this issue. Any ideas what is causing this issue and how I can go about fixing it?
obj.ctr.Frequency = freqWForm(iter);
write(obj.ports,[1 1 1 0 directionArray(iter)])
start(obj.c, "Continuous")
for i = 1:obj.samplesPerCycle*obj.cycles
if i > 1 && mod(i,(obj.samplesPerCycle/12)) == 1
obj.ctr.Frequency = freqWForm(iter);
write(obj.ports,[1 1 1 0 directionArray(iter)])
[a,~] = read(d,"OutputFormat","Matrix");
dataOutput(i,2) = (dataOutput(i,2)-dispOffset)*dispScale;
dataOutput(i,3) = (dataOutput(i,3)-forceOffset)*forceScale;
dataOutput(i,1) = toc(t);
pTime = timePerSample - toc;
write(obj.ports, [0 0 0 0 0])
Thanks for your help!