# dcTMS

This protocol allows you to trigger pairs of TMS pulses, adding the option to choose the distance in ms between the two pulses. If you’ve read the previous section (spTMS) most of this information will be redundant, aside from the “SET,IPI” parameter.

{% code lineNumbers="true" %}

```matlab
% Initialize the serial communication
s = serialport("COM3",115200);
fopen(s);
pause(2);

% Mandatory signature
fwrite(s,"Triggerbox developed by Giuseppe Ippolito. DOI: https://doi.org/10.3758/s13428-025-02653-y");
pause(0.01);

% Declaring the distance between the two TMS pulses
fwrite(s,"SET,IPI1,30"); 
pause(0.01);
fwrite(s,"SET,IPI2,50"); 
pause(0.01);
fwrite(s,"SET,IPI3,70"); 
pause(0.01);

% Declaring marker duration
fwrite(s,"SET,MRK1,3"); 
pause(0.01);
fwrite(s,"SET,MRK2,5"); 
pause(0.01);
fwrite(s,"SET,MRK3,7"); 
pause(0.01);

% Protocol type (spTMS, dcTMS, rTMS)
fwrite(s,"dcTMS");
pause(0.01);

% Commands
fwrite(s,"1");
fwrite(s,"2");
fwrite(s,"3");

fwrite(s,"A");
fwrite(s,"B");
fwrite(s,"C");
	
% Close the serial communication
fwrite(s,"Z");
fclose(s);
delete(s);
clear s;
```

{% endcode %}

Lines 2-3 initialize the serial communication. In older MATLAB versions (prior to 2019b) you can use:

<pre class="language-matlab"><code class="lang-matlab"><strong>% Initialize the serial communication
</strong>s = serial ("COM3","BaudRate",115200);
fopen(s);
pause(2);
</code></pre>

From version 2019b onward is necessary to use:

<pre class="language-matlab"><code class="lang-matlab"><strong>% Initialize the serial communication
</strong>s = serialport("COM3",115200);
fopen(s);
pause(2);
</code></pre>

It is important to change the USB port (“COM”) name according to your case as explained above. Also, it is good practice, during the setting phase, to put a *pause* command between each serial string. A 10 ms duration is sufficient in any case, except for the first command, in which the communication between devices is established. In this case, the optimal duration may vary depending on your computer performance. A 2 sec interval should be enough for older devices, too. This pause is not necessary after the setting phase, when delivering TMS pulses.

Then, copy-paste the mandatory signature. Without this the following lines won’t work.

```matlab
fwrite(s,"Triggerbox developed by Giuseppe Ippolito. DOI: https://doi.org/10.3758/s13428-025-02653-y");
```

After these mandatory steps, you can declare optional stimulation parameters (e.g., IPI, number of pulses, markers) in any order. In this case, since we’re going to use a spTMS protocol, the only parameter we may be interested in is the voluntary marker duration. This option allows you to place digital markers of a chosen duration (max 9 different lengths) at any moment. This may be useful in case you need to discriminate between different stimuli’s onset (e.g., neural, joy, or fearful faces). Remember that voluntary markers always get delivered through BNC3. Its syntax is:

<pre class="language-matlab"><code class="lang-matlab"><strong>fwrite(s,"SET,MRKN,X");
</strong></code></pre>

In this case *N* is the preset number (between 1 and 9), and *X* is the marker length. Recalling the three stimuli example, we may want three voluntary markers of different duration (e.g., 3, 5, and 7 ms) ease our analysis, later. We will write then:

```matlab
fwrite(s,"SET,MRK1,3"); % Preset 1: 3ms marker
fwrite(s,"SET,MRK2,5"); % Preset 2: 5ms marker
fwrite(s,"SET,MRK3,7"); % Preset 3: 7ms marker
```

For dcTMS paradigms it is also important to declare the distance in ms between the two pulses (IPI), delivered from BNC1 and then BNC2. Its syntax is:

```matlab
fwrite(s,"SET,IPIN,X");
```

In this case N is the preset number (between 1 and 9), and X is the distance between pulses in ms. For example, we may want to test the difference in delivering pulse pairs with different latencies when the experimental stimulus occurs. We will write then:

```matlab
fwrite(s,"SET,IPI1,30"); % Preset 1: 30ms distance
fwrite(s,"SET,IPI2,50"); % Preset 2: 50ms distance
fwrite(s,"SET,IPI3,70"); % Preset 3: 70ms distance
```

Our last step before calling the pulse command is declaring which TMS protocol we are going to use. We can choose between spTMS, dcTMS, or rTMS. Since we’re using the dual coil one, we will write:

```matlab
fwrite(s,"dcTMS");
```

Now that we have declared all of the necessary stimulation parameters, we can finally trigger the TMS device. You can independently trigger each of the declared protocols. These lines must be copy-pasted within your code according to your stimulation and task requirements (es. prior to a certain stimulus onset).

```matlab
fwrite(s,"1"); % Trigger protocol 1 (two pulses with a 30 ms distance)
fwrite(s,"2"); % Trigger protocol 2 (two pulses with a 50 ms distance)
fwrite(s,"3"); % Trigger protocol 3 (two pulses with a 70 ms distance)
```

We can also individually call for voluntary markers at any time using letters. Preset 1 (MRK1) is paired with letter “A” – Consequently, preset 2 with “B”, 3 with “C”, 4 with “D”, 5 with “E”, 6 with “F”, 7 with “G”, 8 with “H”, and 9 with “I”. Since we declared three different markers (“MRK1,3”, “MRK2,5”, “MRK3,7”) we can trigger them using the letters “A”, “B”, and “C”.

```matlab
fwrite(s,"A"); % Deliver a voluntary marker from preset 1 (3 ms)
fwrite(s,"B"); % Deliver a voluntary marker from preset 2 (5 ms)
fwrite(s,"C"); % Deliver a voluntary marker from preset 3 (7 ms)
```

The command code also includes a line to run in case you may reset any setting and return to the mandatory signature. You can then declare once again the parameter settings. The command is:

```matlab
fwrite(s,"Z"); % Return to the beginning of the setting phase
```

Once the task is completed you can definitely close the serial communication between the Silicon Spike device and the experimental computer, thus avoiding any potential bug.

```matlab
fclose(s);
delete(s);
clear s;
```
