Hello,
I've been working at the motion program approach for some time now but had some success today....
I found that I could get reliable triggering from a PLC (but obviously without any motions) with the following code:
#define DET_TRIGGER_OUTPUT Acc65E[0].DataReg[3].3
#define trig_count p1401
#define TimeDelay 0.005
open plc 14
local delayTimer;
while(trig_count < 5000)
{
delayTimer = Sys.Time + TimeDelay;
DET_TRIGGER_OUTPUT = 1;
while (Sys.Time < delayTimer)
{
}
delayTimer = Sys.Time + TimeDelay;
DET_TRIGGER_OUTPUT = 0;
while (Sys.Time < delayTimer)
{
}
trig_count++;
}
CLOSE;
So this morning I stripped the motion program right down and removed all motion elements so it resembled the PLC code as closely as possible (with the main loop identical to above).
Curiously this setup could never achieve more than 4096 while loop cycles before it locked up. Less than 4096 it would run to completion, but any more and it would hang. 4096 is too much of a magic number to not be linked to some limitation in the system....I would be interested to know if anyone can shed any light on this limitation?
However, even with this stripped down version running less than 4096 loops it still couldn't reliably trigger. I tried various arrangements of the code and subroutines with no luck.
In the end the successful collections came by modifying the motion program so that it didn't send trigger requests to the hardware directly but would just set a p-variable. Then I had a PLC running alongside the motion program and monitoring this p-variable. The PLC would be the one to actually send the request to the GPIO hardware.
It is not a very elegant solution but seems very reliable. Every collection has been successful. I have run 4 successful collections with a 20ms mark/space length (2 of 4000 steps, 2 of 5000 steps), and 2 successful 5000 step scans at 5ms mark/space length.
It seems that motion programs are unreliable at talking to hardware directly, I'm guessing it has something to do with the way they buffer upcoming moves; it must mess up the timing?
Thanks,
James