Synchronization (Option) | The setup order for the different synchronization options |
|
|
(8) Start all of the trigger slave boards
After having armed the synchronized boards, you must start all of the boards, that are defined as trigger slaves first. This is done with the FIFOSTART command.
Register | Value | Direction | Description | |
SPC_COMMAND | 0 | r/w | Command register of the board | |
| SPC_FIFOSTART | 10 | Starts the board with the current register settings in FIFO mode and waits for the first interrupt. |
Remember that the FIFO mode is allways interrupt driven. As a result the FIFOSTART function will not return until the first software buffer is transferred. For that reason it is absolutely necessary to start different threads for each board that runs synchronuously in FIFO mode. If this is not done a deadlock will occur and the pro- gram will not start properly.
(9) Start all of the trigger master boards
After having armed the synchronized boards, you must start all of the boards, that are defined as trigger masters.
Register | Value | Direction | Description | |
SPC_COMMAND | 0 | r/w | Command register of the board | |
| SPC_FIFOSTART | 10 | Starts the board with the current register settings in FIFO mode and waits for the first interrupt. |
This example shows how to set up three boards for synchronization in FIFO mode. Board 0 is clock master and board 2 is trigger master.
// (3) | trigger synchronization of trigger master board(s) | ||
SpcSetParam (hDrv[2], SPC_COMMAND, | SPC_SYNCTRIGGERMASTER); | ||
// (4) | trigger synchronization of trigger slave boards | ||
SpcSetParam (hDrv[0], SPC_COMMAND, | SPC_SYNCTRIGGERSLAVE); | // as trigger slaves | |
SpcSetParam (hDrv[1], SPC_COMMAND, | SPC_SYNCTRIGGERSLAVE); | // as trigger slaves | |
// (5) | synchronization information for clock master board | ||
SpcSetParam (hDrv[0], SPC_COMMAND, | SPC_SYNCMASTERFIFO); |
| |
// (6) | synchronization information for clock slave boards | ||
SpcSetParam (hDrv[1], SPC_COMMAND, | SPC_SYNCSLAVEFIFO); |
| |
SpcSetParam (hDrv[2], SPC_COMMAND, | SPC_SYNCSLAVEFIFO); |
| |
// (7) | start the synchronization |
| |
SpcSetParam (hDrv[0], SPC_COMMAND, | SPC_SYNCSTART); |
| |
// (8) | start the FIFO tasks. Trigger slaves are started first | ||
CreateThread | (NULL, 0, &dwFIFOTask, (void*) hDrv[0], 0, &dwThreadId[b]); | ||
CreateThread | (NULL, 0, &dwFIFOTask, (void*) hDRV[1], 0, &dwThreadId[b]); | ||
// (9) | start the trigger master FIFO task |
| |
CreateThread | (NULL, 0, &dwFIFOTask, (void*) hDrv[2], 0, &dwThreadId[hDrv[2]]); | ||
|
|
|
|
It is assumed, that the created threads start in the same order as they are called from within the program. As described before, starting of the FIFO mode in synchronization has to be done in different threads to avoid a deadlock. A simple example for a FIFO thread can be found below.
Example of FIFO task. It simply starts the boards and counts the buffers that have been transfered:
unsigned long __stdcall dwFIFOTask (void* phDrv) |
| ||
{ | hDrv = (int16) phDrv; |
| |
int16 |
| ||
int32 | lCmd = SPC_FIFOSTART; |
| |
int16 | nBufIdx = 0, nErr; |
| |
int32 | lTotalBuf; |
|
|
lTotalBuf = 0; |
|
| |
do |
|
|
|
{ |
|
| // wait for buffer |
nErr = SpcSetParam (hDrv, SPC_COMMAND, lCmd); | |||
lCmd = SPC_FIFOWAIT; |
| // here you can do | |
printf ("Board %d | Buffer %d total buffers: %d\n", nIdx, nBufIdx, lTotalBuf);// e.g. calculations | ||
SpcSetParam (hDrv, SPC_COMMAND, SPC_FIFO_BUFREADY0 + nBufIdx); | // just a printf here | ||
// release buffer |
nBufIdx++;
lTotalBuf++;
if (nBufIdx == FIFO_BUFFERS) nBufIdx = 0;
}
while (nErr == ERR_OK);
return 0;
}
(c) Spectrum GmbH | 73 |