Image display delay

Peter Quain pquain at une.edu.au
Fri Apr 17 12:09:05 UTC 2009



Hi -  a previous suggestion was to do away with 
the image display object and use canvas to remove 
your reported display delay and also ensure ttl 
pulse accurately marks stimulus onset.

If it is of any use, here is some example code 
that preloads the image info into video memory - 
offScreenCanvas - prior to the time critical 
parts of the trial .. fixation, and then image 
display, where the offScreenCanvas is drawn to 
screen (copied to the display canvas [cnvs]), and 
a ttl pulse is sent to some NeuroScan equipment. 
The copy operation takes <1ms (t6-t5), so the 
image becomes available to subject over the ~11.7 
ms @ 85Hz (i.e., half drawn by ~6 ms) as the 
screen is drawn, and ttl pulse is reliably sent on same screen refresh.

Sequence is: 1) InLine - StimPrep; 2) Fixation (a 
text object); 3) InLine - DisplayStim

- Key variables are declared in User Script
- TrialList needs attributes 1) Pic = image name; 2) PicType = condition
- 9 conditions in this example, with event codes 1 to 9
- Image display duration is set at the beginning 
of the experiment with an integer value (intDur) 
collected by an AskBox. This could be hard coded if you wanted.
- There is a delay (blank screen) of 3 screen 
refreshes (~35 ms) between Fixation offset and stimulus onset
- Stimulus displayed centred on gray background
- The Attributes t1, t2, ... t9, start, are all 
timing information used for diagnostics. Fixation 
onset and offset are grabbed as well .. intervals 
between these are easily computed later (e.g., in 
SPSS) and for each trial you can see how long 
various bits of code execution take (e.g., 
preload image, t2-t1); stimulus duration 
(t9-start); whether your machine accurately 
tracks retraces (t3-fixation.OffsetTime; t4-t3; 
t5-t4); and the accuracy of your ttl 
communication.. that is, that the pulse is sent 
on the screen refresh where the stimulus is drawn 
to screen (t7-t6), and the duration of the pulse 
(t8-t7). 7 ms has been OK for us (no missed event 
markers), recording EEG @ 500Hz.

Some of this code might be a bit rough. If anyone 
notices any errors in this approach, please post.

'--------------------------------------------------------------------------
' User Script
'--------------------------------------------------------------------------
Public dstim As String
Public hh, gg As Long
Dim cnvs As Canvas
Dim offScreenCnvs As Canvas
Dim intDur As Integer


         '''''''''''''''''''''''''''''''''''''''''''''
         ' InLine - StimPrep BEGIN
         '''''''''''''''''''''''''''''''''''''''''''''

dstim = c.GetAttrib ("Pic")
hh = Clock.Read
c.SetAttrib "t1", hh

'Define the display canvas for later
Set cnvs = Display.Canvas

cnvs.BackStyle = "transparent"

cnvs.FillColor = CColor("Gray")

'use the CreateCanvas to create an off-screen canvas
Set offScreenCnvs = Display.CreateCanvas
offScreenCnvs.Clear

offScreencnvs.BackStyle = "transparent"

offScreenCnvs.FillColor = CColor("Gray")

offscreenCnvs.LoadImage dstim

hh = Clock.Read
c.SetAttrib "t2", hh

' Image loads in top left corner - all images 512*384
' ..so define region - rectangle - of offScreenCnvs to copy
Dim srcRect As Rect
srcRect.Left = 0
srcRect.Right = 512
srcRect.Top = 0
srcRect.Bottom = 384

         '''''''''''''''''''''''''''''''''''''''''''''
         ' InLine - StimPrep END
         '''''''''''''''''''''''''''''''''''''''''''''

         ' Fxation set to terminate synched with vertical retrace

         Fixation.Run
         c.SetAttrib "Fixation.OnsetTime", Fixation.OnsetTime
         c.SetAttrib "Fixation.OffsetTime", Fixation.OffsetTime


         '''''''''''''''''''''''''''''''''''''''''''''
         ' InLine - DisplayStim BEGIN
         '''''''''''''''''''''''''''''''''''''''''''''


' include a delay of 3 vertical retraces...1st is 
between Fixation Offset and this one
Display.WaitForVerticalBlank

' grab timing info: start 1st of vertical retrace
hh = Clock.Read
c.SetAttrib "t3", hh

' 2nd vertical retrace delay is between 1st 
WaitForVerticalBlank command and this one
Display.WaitForVerticalBlank

' grab timing info: start of 2nd vertical retrace
hh = Clock.Read
c.SetAttrib "t4", hh

' 3rd delay between 2nd WaitForVerticalBlank command and this one,
' after which stimuli is drawn to screen
Display.WaitForVerticalBlank

' grab timing info: start of 3rd vertical retrace
hh = Clock.Read
c.SetAttrib "t5", hh

' Define destination rectangle for centred display
Dim desRect As Rect
desRect.Left = 256
desRect.Right = 768
desRect.Top = 192
desRect.Bottom = 576

' Copy source rectangle to destination rectangle
cnvs.Copy offScreenCnvs, srcRect, desRect

Dim start As Long
start = Clock.Read
c.SetAttrib "t6", start

Dim dHex As Double

' parse condition and send appropriate trigger code to NuAmps
If c.GetAttrib ("PicType") = 1 then
                 dHex = Val(&H1)

         elseif c.GetAttrib ("PicType") = 2 then
                 dHex = Val(&H2)

         elseif c.GetAttrib ("PicType") = 3 then
                 dHex = Val(&H3)

         elseif c.GetAttrib ("PicType") = 4 then
                 dHex = Val(&H4)

         elseif c.GetAttrib ("PicType") = 5 then
                 dHex = Val(&H5)

         elseif c.GetAttrib ("PicType") = 6 then
                 dHex = Val(&H6)

         elseif c.GetAttrib ("PicType") = 7 then
                 dHex = Val(&H7)

         elseif c.GetAttrib ("PicType") = 8 then
                 dHex = Val(&H8)

         elseif c.GetAttrib ("PicType") = 9 then
                 dHex = Val(&H9)


End If

' set time trigger code begins execution
gg = Clock.Read
c.SetAttrib "t7", gg

' send pulse for 7ms
Do
WritePort &H378, dHex
hh = Clock.Read
Loop While hh - gg < 7

'toggle all bits low (turn off TTL pulse)
WritePort &H378, &H0

c.SetAttrib "dTrig", dHex

gg = Clock.Read
c.SetAttrib "t8", gg

' Display the stimuli for appropriate duration (set at start of experiment)
Do
gg = Clock.Read
Loop While gg - start < intDur

hh = Clock.Read
c.SetAttrib "t9", gg


         '''''''''''''''''''''''''''''''''''''''''''''
         ' InLine - DisplayStim END
         '''''''''''''''''''''''''''''''''''''''''''''


At 12:30 PM 15/04/2009, you wrote:

>get rid of image display object. use canvas to 
>display image. Use inline to preload image to 
>video memory at start of each trial. In inline 
>that draws canvas, have ttl pulse code 
>immediately after write to screen code. Hold 
>high for maybe 7ms, then pull all pins low. 
>Pulse should occur on screen refresh where image is drawn.
>
>At 12:22 PM 15/04/2009, you wrote:
>>Dear David
>>         I have read Chapter 3 of Userguide 
>> thoroughly, but still feel a little confusion. 
>> In each block of my programme, there was a 
>> TextDisplay, a Inline Scripe and a 
>> ImageDisplay(stimulous).To synchronize the 
>> signal of NeroScan and the stimuli of e-Prime, 
>> I have inverted a in-line WritePort command 
>> before "ImageDisplay" and set the PreRelease 
>> time (100ms) in the TextDisplay. However, the 
>> unwanted delay or unsynchronization still 
>> existed between the e-Prime and EEG recording 
>> system result in anormal delay of N170 
>> component. Thus, I want to ask whether the 
>> WritePort command was sent to the recording 
>> system at the beginning of Prelease time or at 
>> the point when stimulous presents on the 
>> screen. In other word, I want to know whether 
>> the WritePort command and image were sent at the same time from E-Prime.
>>       Thank you for your concerning.
>> 
>>
>> > Date: Wed, 8 Apr 2009 11:26:12 -0400
>> > To: e-prime at googlegroups.com
>> > From: mcfarla9 at msu.edu
>> > Subject: Re: Image display delay
>> >
>> >
>> > At 4/5/2009 09:35 PM Sunday, maocong wrote:
>> > >I am a greenhand in programming on e-prime, and I need some help on
>> > >the fellowing issue:
>> > >
>> > >I designed an ERP visual stimulous experiment by using the control of
>> > >ImageDisplay on e-Prime 2.0v and the EEG recording system is NeroScan
>> > >4.3v. And I found a 8~14ms delay on image display(shown by the
>> > >programme running result file), and the help file showed this delay is
>> > >the difference between orignial onset time and actual display time.
>> > >This random image display delay greatly effect the accuracy of N170
>> > >latency recorded, which lead to the unreliablity of the experiment
>> > >result. Therefore I hope you can give me some advices about how to
>> > >eliminate/compensate this display delay or how to uniform this display
>> > >delay
>> >
>> > Please read thoroughly chapter 3 ("Critical timing...") of the User's
>> > Guide that came with E-Prime.
>> >
>> > -- David McFarlane, Professional Faultfinder
>> >
>> >
>> > More than mail–Windows Live™ goes way beyond 
>> your inbox.ox. 
>> <http://www.microsoft.com/windows/windowslive/>More than messages
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en
-~----------~----~----~----~------~----~------~--~---

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.linguistlist.org/pipermail/eprime/attachments/20090417/b76ae563/attachment.htm>


More information about the Eprime mailing list