<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>Dear Bianca,<BR>
<BR>
Just a few questions and hints:<BR>
<BR>
Did you define sufficient prerelease times in mainstimulus and mainmask2? This would be required since you reload images during the time critical loop. (But read on...;)<BR>
<BR>
The place of the mainstimulus.OnsetSignal statements are a bit unusual. Normally you would initialize these before mainstimulus.Run. That would be required if the TMS trigger should be in sync with ALL (including the very first) mainstimulus onsets. <BR>
<BR>
There are several good arguments for not placing the mainstimulus preparation and execution inside the first loop. The prefered way would be to run the mainstimulus object just before the loop. Then use a simplified loop to generate the trigger pulses that should be generated during the target. Also use the sleep() instruction inside the loop to specify the delays for each iteration. You should also place the OnsetSignal initialisation script somewhere before mainstimulus.run. Also set the duration and prerelease vaules of mainstimulus to the required duration of the target. This will prevent large timing error values for the following objects.<BR><BR>
The declaration of the i1 integer variable is probably misplaced because it should be declared outside the loop. I'm not sure if E-Basic will reinitialize the variable each time to zero at the start of the loop, but most programming languages will indeed do this. If this is the case then the lines inside the <EM>'if i1 = 0 then' </EM>block will be executed each iteration. However, E-Prime probable doesn't reinitialize i1 to zero again because this would have introduced an infinite loop because the mainstimonset wouldn't grow.<BR>
<BR>
The reason for the missing responses in the second part is caused by the continuous reinitialization of the input mask. The solution is the same as for the first loop: place the preparation and execution of mainmask2 before the second loop so it is ran only once. Also configure the input object to accept 2 responses and use InputMaskManager.Responses to extract the RT and RESP values of both responses. An example for this kan be found in the E-Basic help documentation.<BR>
<BR>
I also noticed that you used the WritePort command several times in sequence. This is probably required because you immediatly reset the printer port values to zero each time. This will cause VERY short pulses on fast computers. The prefered way is to reset the value to zero after a specific time. (Using sleep() for example.)<BR><BR>
Below you fill find some example script, which can be used as starting point. (Note that i wasn't sure about the number of pulses during the target.)<BR>
<BR>hope this helps<BR>
Paul<BR>
<BR>
<BR>
Paul Groot<BR>
VU University<BR>
Amsterdam<BR>
The Netherlands<BR><BR>
<BR>
<FONT face="Courier New, Courier, Monospace">'create pulsecount to make sure each pulse is only fired once<BR>dim PulseCount%<BR>dim RespCount%<BR>dim MainStimOnset as long<BR>dim PulseTime as long<BR>dim StimDisplayDuration as long<BR>Const RefreshDuration% = 20</FONT><BR>
<FONT face="Courier New, Courier, Monospace">'''''<BR>' at start of experiment<BR>writeport &H378, 0</FONT><BR>
<FONT face="Courier New, Courier, Monospace">'''''<BR>' script 1<BR>mainstimulus.OnsetSignalEnabled = True<BR>mainstimulus.OnsetSignalPort = &H378<BR>mainstimulus.OnsetSignalData = &HFF</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace">''''<BR>' show target<BR>mainstimulus.duration = StimDisplayDuration<BR>mainstimulus.prerelease = mainstimulus.duration<BR>'mainstimulus.Filename = c.GetAttrib("mainstimulus")<BR>mainstimulus.Load<BR>mainstimulus.Run ' stim onset and first trigger<BR>PulseCount = 1<BR>MainStimOnset = mainstimulus.OnsetTime <BR>c.SetAttrib "PulseTime1", MainStimOnset<BR>c.SetAttrib "mainstimulus.OnsetDelay",mainstimulus.OnsetDelay<BR>c.SetAttrib "mainstimulus.OnsetTime", mainstimulus.OnsetTime<BR>c.SetAttrib "mainstimulus.PreRelease",mainstimulus.PreRelease<BR>debug.print PulseCount & " onset=" & MainStimOnset</FONT><BR>
<FONT face="Courier New, Courier, Monospace">dim nextPulse as long<BR>dim waitms as long</FONT><BR>
<FONT face="Courier New, Courier, Monospace">'''''<BR>' block wave during target<BR>Sleep(0.5*RefreshDuration) ' start with high pulse of 50% duty cycle<BR>do<BR> ' you can modify the pulse duration by replacing RefreshDuration<BR> nextPulse = MainStimOnset + PulseCount*RefreshDuration<BR> waitms = nextPulse - clock.read()<BR> writeport &H378, 0<BR> if waitms>0 then Sleep(waitms)<BR> writeport &H378, &HFF<BR> PulseCount = PulseCount + 1<BR> c.SetAttrib "PulseTime" & PulseCount, clock.read()<BR> debug.print PulseCount & " onset=" & clock.read() & ", wait=" & waitms<BR> Sleep(0.5*RefreshDuration)<BR>loop until clock.read() >= MainStimOnset + StimDisplayDuration - RefreshDuration<BR>writeport &H378, 0</FONT><BR>
<BR><FONT face="Courier New, Courier, Monospace">'''''<BR>' show mask<BR>mainmask2.InputMasks.Reset<BR>mainmask2EchoClients.RemoveAll<BR>mainmask2.InputMasks.Add Keyboard.CreateInputMask("{ANY}", "", CLng("-1"), CLng("2"), ebEndResponseActionNone, CLogical("Yes"), "", "", "ResponseMode:All ProcessBackspace:Yes")<BR>mainmask2.Duration = 0<BR>mainmask2.Run</FONT><BR>
<FONT face="Courier New, Courier, Monospace">'''''<BR>' generate remaining pulses and stop after two responses<BR>Dim stimDisplayMasks As InputMaskManager<BR>Set stimDisplayMasks = mainmask2.InputMasks<BR>while PulseCount<5 And stimDisplayMasks.Item(1).Responses.Count<2<BR> ' time between remaining pulses = 5 refreshes ?<BR> nextPulse = MainStimOnset + 5*(PulseCount-1)*RefreshDuration <BR> waitms = nextPulse - clock.read()<BR> if waitms>0 then Sleep(waitms)<BR> WritePort &H378, &HFF<BR> PulseCount = PulseCount + 1<BR> c.SetAttrib "PulseTime" & PulseCount, clock.read()<BR> debug.print PulseCount & " onset=" & clock.read() & ", wait=" & waitms<BR> Sleep(0.5*RefreshDuration)<BR> WritePort &H378,0<BR>wend<BR>' two reponses yet?<BR>do<BR>loop until stimDisplayMasks.Item(1).Responses.Count = 2<BR>' save attributes<BR>c.SetAttrib "resp1", stimDisplayMasks.Item(1).Responses(1).RESP<BR>c.SetAttrib "rt1", stimDisplayMasks.Item(1).Responses(1).RT<BR>c.SetAttrib "resp2", stimDisplayMasks.Item(1).Responses(2).RESP<BR>c.SetAttrib "rt2", stimDisplayMasks.Item(1).Responses(2).RT<BR>c.SetAttrib "mainmask2.OnsetDelay", mainmask2.OnsetDelay<BR>c.SetAttrib "mainmask2.OnsetTime", mainmask2.OnsetTime<BR>c.SetAttrib "mainmask2.RESP", mainmask2.RESP<BR>c.SetAttrib "mainmask2.CRESP", mainmask2.CRESP<BR>c.SetAttrib "mainmask2.ACC", mainmask2.ACC</FONT><BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<HR id=stopSpelling>
<BR>
> From: bianca.de-haan@klinikum.uni-tuebingen.de<BR>> To: eprime@mail.talkbank.org<BR>> Subject: trigger TMS + collect responses during stimulus presentation<BR>> Date: Fri, 15 Jun 2007 16:22:19 +0200<BR>> <BR>> Dear E-prime list,<BR>> <BR>> I've been racking my brain over this problem longer than I care to think<BR>> about, so I hope someone can help me figure this out.<BR>> <BR>> I want to present a targetstimulus (mainstimulus) followed by a maskstimulus<BR>> (mainmask2). Depending on the targetstimulus duration (titrated in a<BR>> previous block) an x amount of TMS pulses occur during presentation of the<BR>> targetstimulus (first pulse synchronized with stimulus onset) and the<BR>> remaining TMS pulses occur during presentation of the maskstimulus.<BR>> Furthermore, during presentation of the maskstimulus, I would also like to<BR>> be able to collect 2 button presses.<BR>> <BR>> Mostly, I've managed to get it all to work (see code at the end of this<BR>> email). I have put the ImageDisplays of both the targetstimulus and the<BR>> mainstimulus under unreferenced objects with a duration of 0, time limit<BR>> infinite and end action none. The stimuli are presented correctly and the<BR>> tms pulses are fired during stimulus presentation) However, there are 2<BR>> problems I can't seem to solve.<BR>> <BR>> Firstly, the timing seems to be way off. The most critical timing is the<BR>> timing of the targetstimulus and the TMS pulses. I have applied all the<BR>> tricks in the Timing-chapter of the E-Prime manual. Furthermore, I have run<BR>> the RefreshClockTest which shows that my computer is theoretically capable<BR>> of achieving millisecond precision. Finally, I calculate the exact Refresh<BR>> duration at the start of the experiment (using part of the code of the<BR>> RefreshClockTest experiment) and specify all my timings in multiples of the<BR>> calculated refresh duration (8.333ms at 120Hz monitor) with half a refresh<BR>> duration subtracted to make sure events happen on the exact vertical<BR>> refresh. Still, I don't achieve anything near good timing, especially for<BR>> the TMS pulses. <BR>> <BR>> Secondly, during presentation of the maskstimulus it does not register all<BR>> button presses. Sometimes a button press is detected, sometimes it's not.<BR>> I've had a look at monitoring responses using Inputmasks, but have not been<BR>> able to get this to work at all (mainmask2.Inputmasks.(Responses?).RT <> 0<BR>> cannot be compiled).<BR>> <BR>> If anyone can provide me with any tips or tricks as to how to solve these 2<BR>> problems, they will earn my eternal gratitude.<BR>> <BR>> Many thanks,<BR>> <BR>> Bianca de Haan<BR>> <BR>> Excerpt of code follows:<BR>> ################################################################<BR>> <BR>> 'create pulsecount to make sure each pulse is only fired once<BR>> PulseCount = 1<BR>> <BR>> do 'start loop that will display mainstimulus till<BR>> stimdisplayduration has elapsed<BR>> <BR>> dim i1 as integer 'start loop counter<BR>> <BR>> 'draw mainstimulus for infinite duration, terminated by<BR>> StimDisplayDuration<BR>> mainstimulus.Filename = c.GetAttrib("mainstimulus")<BR>> mainstimulus.Load<BR>> mainstimulus.Run<BR> <BR>
<BR>
<BR>
<BR>
<BR>
<BR>> <BR>> 'onsettime will only be collected in first loop and first<BR>> tms pulse synched with stimulus onset<BR>> if i1 = 0 then <BR>> MainStimOnset = mainstimulus.OnsetTime <BR>> mainstimulus.OnsetSignalEnabled = True<BR>> 'send pulse at stimulus onset<BR>> mainstimulus.OnsetSignalPort = &H378<BR>> mainstimulus.OnsetSignalData = &HFF<BR>> 'write time that the pulse was really sent<BR>> PulseTime = clock.read()<BR>> c.SetAttrib "PulseTime1", PulseTime<BR>> 'switch port off again to enable second pulse<BR>> writeport &H378, 0<BR>> PulseCount = PulseCount + 1<BR>> end if<BR>> <BR>> i1 = i1 + 1<BR>> <BR>> 'end loop when stimulus duration has elapsed<BR>> loop until clock.read() > MainStimOnset + StimDisplayDuration<BR>> <BR>> <BR>> 'create respcount to count the responses<BR>> RespCount = 0<BR>> 'create place to log the 2 responses<BR>> dim resp1 as Integer<BR>> dim resp2 as Integer<BR>> <BR>> do 'start loop that runs mainmask2 until 2 responses are collected<BR>> while firing remaining tms pulses<BR>> <BR>> mainmask2.InputMasks.Reset<BR>> mainmask2EchoClients.RemoveAll<BR>> mainmask2.InputMasks.Add Keyboard.CreateInputMask("{ANY}",<BR>> "", CLng("-1"), CLng("2"), ebEndResponseActionNone, CLogical("Yes"), "", "",<BR>> "ResponseMode:All ProcessBackspace:Yes")<BR>> mainmask2.Run<BR>> c.SetAttrib "mainmask2.OnsetDelay", mainmask2.OnsetDelay<BR>> c.SetAttrib "mainmask2.OnsetTime", mainmask2.OnsetTime<BR>> c.SetAttrib "mainmask2.RTTime", mainmask2.RTTime<BR>> c.SetAttrib "mainmask2.ACC", mainmask2.ACC<BR>> c.SetAttrib "mainmask2.RT", mainmask2.RT<BR>> c.SetAttrib "mainmask2.RESP", mainmask2.RESP<BR>> c.SetAttrib "mainmask2.CRESP", mainmask2.CRESP<BR>> <BR>> 'fire pulse 2<BR>> if clock.read() >= MainStimOnset + (4.5 * RefreshDuration)<BR>> and PulseCount = 2 then<BR>> WritePort &H378,255<BR>> WritePort &H378,255<BR>> WritePort &H378,255<BR>> PulseTime = clock.read()<BR>> c.SetAttrib "PulseTime2", PulseTime<BR>> WritePort &H378,0<BR>> PulseCount = PulseCount + 1<BR>> end if <BR>> <BR>> 'fire pulse 3<BR>> if clock.read() >= MainStimOnset + (9.5 * RefreshDuration)<BR>> and PulseCount = 3 then<BR>> WritePort &H378,255<BR>> WritePort &H378,255<BR>> WritePort &H378,255<BR>> PulseTime = clock.read()<BR>> c.SetAttrib "PulseTime3", PulseTime<BR>> WritePort &H378,0<BR>> PulseCount = PulseCount + 1<BR>> end if <BR>> <BR>> 'fire pulse 4<BR>> if clock.read() >= MainStimOnset + (14.5 * RefreshDuration)<BR>> and PulseCount = 4 then<BR>> WritePort &H378,255<BR>> WritePort &H378,255<BR>> WritePort &H378,255<BR>> PulseTime = clock.read()<BR>> c.SetAttrib "PulseTime4", PulseTime<BR>> WritePort &H378,0<BR>> PulseCount = PulseCount + 1<BR>> end if <BR>> <BR>> 'fire pulse 5<BR>> if clock.read() >= MainStimOnset + (19.5 * RefreshDuration)<BR>> and PulseCount = 5 then<BR>> WritePort &H378,255<BR>> WritePort &H378,255<BR>> WritePort &H378,255<BR>> PulseTime = clock.read()<BR>> c.SetAttrib "PulseTime5", PulseTime<BR>> WritePort &H378,0<BR>> PulseCount = PulseCount + 1<BR>> end if <BR>> <BR>> 'continuously check whether a response has been made and<BR>> then log which<BR>> 'response has been made<BR>> if mainmask2.RT <> 0 then<BR>> RespCount = RespCount + 1<BR>> <BR>> if RespCount = 1 then<BR>> resp1 = mainmask2.RESP<BR>> c.SetAttrib "resp1", resp1<BR>> elseif RespCount = 2 then<BR>> resp2 = mainmask2.RESP<BR>> c.SetAttrib "resp2", resp2<BR>> 'collate the 2 responses in 1 column so I don't have<BR>> to change a previous response assignment<BR>> c.SetAttrib "BothResps", resp1 & resp2<BR>> end if<BR>> <BR>> end if<BR>> <BR>> 'loop until 2 responses are collected<BR>> loop until RespCount = 2<BR>> <BR>> ############################################################################<BR>> #<BR>> <BR>> <BR><BR><br /><hr />In 2 tellen een webpagina voor al je fotos makkelijk en gratis met <a href='http://clk.atdmt.com/MSN/go/msnnksac0030000001msn/direct/01/?href=http://www.imagine-msn.com/spaces' target='_new'>Windows Live Spaces</a></body>
</html>