;-------------------------------------------------------- ; S I N E ; ; S A C T R A C K S E Q U E N C E ;-------------------------------------------------------- ;Cannot exceed 1023 lines of instructions. ; SET 0.010 2 0 ;0.01 milliseconds per tick ;+/-10 volts ;0 degree offset; TABSZ 150000 ;set maximum table space ;DELAY command is based on the 100 microsecond clock ticks specified above ;TICKS command is based on the ADC sampling clock rate subject to num channels ;VAR V1 ;RE-USABLE variables for use only within mode subroutines ;VAR V2 ;these variables should not pass parameters between ;VAR V3 ;modes or subroutines ;VAR V4 ;VAR V5 ;VAR V6 ;VAR V7 ;VAR V8 ;VAR V9 ;VAR V10 ;VAR V11 ;VAR V12, ;VAR V13, ;VAR V14, ;VAR V15, ;VAR V16, ;VAR V17, ;VAR V18, ;VAR V19, ;VAR V20, ;VAR V21, ;VAR V22, ;VAR V23, ;VAR V24, ;VAR V25, ;VAR V26, ;----------------------------------------------------------- ;above variables are zeroed every time a new mode is entered ;----------------------------------------------------------- VAR V27,ELAPSED=0 ;when OT testing began VAR V28,TIMECURR ;current SPIKE2 time VAR V29,TIMECHEK ;when to check if it is time to move VAR V30,TIMEFEED VAR V31,TEMPTRAK ;OT testing (convert to TABLE field?) VAR V32,TEMPWIND VAR V33,LEDBRD1 ;indicate which LED board (RED) VAR V34,LEDADD1 ;indicate which LED light (RED) VAR V35,LEDBRD2 ;indicate which LED board (GRN) VAR V36,LEDADD2 ;indicate which LED light (GRN) VAR V37,TRACKING ;is he tracking VAR V38,HITTYPE1 ;times all loc shown or step, non-adapt, etc shown VAR V39,HITTYPE2 ;times step-ramp, adapt shown VAR V40,ZERO=0 ;for many branching comparisons VAR V41,NAN=999999999 ;represents "not a number" VAR V42,SHUT1=1 ;primary shutter (normally open) VAR V43,SHUT2=0 ;secondary shutter (normally close) VAR V44,HE ;eye vertical position VAR V45,VE ;eye horizontal position VAR V46,HT2 ;target-2 horizontal position VAR V47,VT2 ;target-2 vertical position VAR V48,HT1 ;target-1 horizontal position VAR V49,VT1 ;target-1 vertical position VAR V50,DURFORG ;how long he has been forgiven VAR V51,DURFEED=0 ;duration he has been on-target before getting fed VAR V52,DURCONT=0 ;contiguously on-target VAR V53,DURON=0 ;total time on-target VAR V54,PARAMCHG=0 ;signals parameters changed -- VAR V55,SUCCESS ;comlete the task? ;we test the Digitial Input so the following VAR is reserved ;VAR V56 ;Collision and Mayhem ;we have DAC 0,1,2,3 so the following VAR are reserved ;V57, last DAC 0 value ;won't work ;V58, last DAC 1 value ;with galvo ;V59, last DAC 2 value ;V60, last DAC 3 value ;we don't have DAC 4,5,6,7 so ok to use the following VAR VAR V61,TEMPTIME ;time counter variable ;VAR V62, VAR V63,SBUFFER=1 ;which serial buffer to use 1 or 2 (must start with 1) VAR V64,FORGIVE=0 ;forgiveness ;the data table transfered to the sequencer ;0000 - 0999 Common parameters ;[0] := gWindowHvgDAC%; HWIND ;[1] := gWindowVvgDAC%; VWIND ;[10] := pRealMinTime*1000; ASSOONAS ;[11] := pRealMaxTime*1000; NOLATER ;[12] := pRealContiguousTime*1000; CONTTON ;[13] := pRealTimeOn*1000; TOTALTON ;[14] := pOnFirst*1000; DURFIRST ;[15] := pOnSubsequent*1000; DURSUB ;[16] := pForgiveness*1000; FORGTIME ;[30] := gWhichBooth ;[31] := update report window info ;1000 - and above = for passing Table parmeters related to this behavioral mode ;-------------------------------------------------------- ; I N I T I A L I Z E L E D A R R A Y ;Initialize the LED array so buffer #1 will be active first. ;3/19/03 ;-------------------------------------------------------- DIGLOW [10101111] ;1-AF CLEAR all boards DELAY 12 ;13-120 microsecond delay DIGLOW [10111111] ;14-BF INTENSITY all boards DELAY 12 ;27-120 microsecond delay ;CALL BRITE doesn't run on the LED array TICKS TIMECURR ;set this up just so the IDLE routine will get started TICKS TIMECHEK,msTick(1) ;1ms, 0.001s later OFFSET 0,ZERO OFFSET 1,ZERO RATE 0,HZ(0) ;stop the ch 0 sinewave if it is running RATE 1,HZ(0) ;stop the ch 1 sinewave if it is running DIGOUT [....1...] ;low de-activates the SONALERT MOVI SHUT1,1 ;open the primary shutter MOVI SHUT2,0 ;close the secondary shutter CALL SHUTTER MOVI V5,0 ;degrees increment per clock cycle ;-------------------------------------------------------- ; M A I N ;Directs program control to the mode of choice. ;10/11/04 ;-------------------------------------------------------- MAIN: MARK 67 ;ramp down velocity SINE2: ADDI V5,-1 ;gradually DEcrease the sine wave amplitude RATE 0,V5 ;degrees increment per clock cycle RATE 1,V5 ;sine wave frequency DELAY 5 ;5=0.0002 delay between steps BGT V5,ZERO,SINE2 MARK 68 ;at zero velocity ;-------------------------------------------------------- ; S I N E ;Setup an auto-running sine wave and return to IDLE. ; ;Sequence Variable Map: ; V2 = temporary ; V5 = angle increment rate ; V10 = table offset ; ;04/03/03 ;-------------------------------------------------------- SINE: BEQ PARAMCHG,0,SINE ;wait for parameters to arrive MOVI PARAMCHG,2 ;new parameters grabbed ;CALL ZEROVAR ;clear all the re-usable VAR MOVI V2,1 ;so it will update report first time through TABST V2,[ZERO+31] ;report just once MOVI V10,1000 ;table offset OFFSET 0,[V10+4] ;horizontal offset OFFSET 1,[V10+5] ;vertical offset SZ 0,[V10+2] SZ 1,[V10+3] ;Y, 0-32768, 32768 is +/-10 degrees MARK 65 ;ramp up velocity MOVI V5,0 SINE1: ADDI V5,1 ;gradually INcrease the sine wave amplitude RATE 0,V5 ;degrees increment per clock cycle RATE 1,V5 ;sine wave frequency DELAY 5 ;5=0.0002 delay between steps BLT V5,[V10+1],SINE1 MARK 66 ;at full velocity ;JUMP IDLE ;sine mode is self-running, nothing to do now ;-------------------------------------------------------- ; I D L E ;Control spends most of the time here. It leaves when new ;choices have been made or when it is time to move. ;9/28/04 ;Table Data Map: ; ;On Target parameter stored in TABLE, ZERO=0000 ; ZERO+14 = pOnFirst*1000; DURFIRST ; ZERO+15 = pOnSubsequent*1000; DURSUB ;-------------------------------------------------------- IDLE: BEQ PARAMCHG,1,MAIN ;the user choices have changed TICKS TIMECURR ;get the current time ;time to check again? BLT TIMECURR,TIMECHEK,IDLE ADDI TIMECHEK,msTick(1) ;1ms, 0.001s later (much more accurate! no time drift) CALL OTTEST ;read target and eye values then compare (takes < 0.24 ms) ;is he on-target? IDLE5: BLT TRACKING,2,IDLE7 ;confirm both H & V are on target DIGOUT [....0...] ;high activates the SONALERT ADDI DURFEED,1 ;increase feed accumulator ;has he been OT long enough to be fed? BLT DURFEED,TIMEFEED,IDLE ;test if it is time to feed CALL FEED ;0.103ms, feed him MOVI DURFEED,0 ;reset the accumulator TABLD TIMEFEED,[ZERO+15] ;DURSUB, use shorter subsequent time on-target dur JUMP IDLE ;he is off target reset everything IDLE7: DIGOUT [....1...] ;low de-activates the SONALERT MOVI DURFEED,0 ;reset the feed time on TABLD TIMEFEED,[ZERO+14] ;DURFIRST, subsequent time on-target duration JUMP IDLE ;-------------------------------------------------------- ; G E T P O S ;Load the eye and target positions for processing by ;script routine TimeToMoveOrFeed. ;10/1/03 ;-------------------------------------------------------- GETPOS: CHAN HE,2 ;1-read the current H eye CHAN VE,3 ;2-read the current V eye CHAN HT1,4 ;3-read the current H primary target CHAN VT1,5 ;4-read the current V primary target CHAN HT2,8 ;5-read the current H secondary target CHAN VT2,9 ;6-read the current V secondary target RETURN ;7- ;-------------------------------------------------------- ; O T T E S T ;Tests if the animal is on-target horizontally and ;vertically and reports the result. Requires 0.26ms or less. ; ;Sequence Variable Map: ; TEMPWIND = window size ; TEMPTRAK = target position ; TRACKING = 0, 1 or 2 depending if he is OT or not ; V2 = holds data from table ; ;On Target parameter stored in TABLE, ZERO=0000 ; ZERO+0 = gWindowHvgDAC%; HWIND ; ZERO+1 = gWindowVvgDAC%; VWIND ; ZERO+17= pForceOT%; 'override, make him OT at all times ; ;10/7/04 ;-------------------------------------------------------- OTTEST: MOVI TRACKING,0 ;1-initialize CALL GETPOS ;8-find out where targ & eye are TABLD TEMPWIND,[ZERO] ;9-HWIND MOV TEMPTRAK,HT1 ;10-load horizontal target SUB TEMPTRAK,HE ;11-subtract horizonal eye BGT TEMPTRAK,0,OTTEST1 ;12-test if result is negative MULI TEMPTRAK,-1 ;13-abs() OTTEST1: BGT TEMPTRAK,TEMPWIND,OTTEST2 ;14-test if he is H-OT ADDI TRACKING,1 ;15-horizontally on-target OTTEST2: TABLD TEMPWIND,[ZERO+1] ;16-VWIND MOV TEMPTRAK,VT1 ;17-load vertical target SUB TEMPTRAK,VE ;18-subtract vertical eye BGT TEMPTRAK,0,OTTEST3 ;19-test if result is negative MULI TEMPTRAK,-1 ;20-abs() OTTEST3: BGT TEMPTRAK,TEMPWIND,OTTEST4 ;21-test if he is V-OT ADDI TRACKING,1 ;22-vertically on-target OTTEST4: TABLD V2,[ZERO+17] ;23-test if using OT override BEQ V2,0,OTTEST5 ;24-do it the old fashioned way, earn it! MOVI TRACKING,2 ;25-force him to be on-target, cheater! OTTEST5: RETURN ;26- ;-------------------------------------------------------- ; S H U T T E R ;Sets the shutters open or closed. ;12/17/02 ;-------------------------------------------------------- SHUTTER: CALL SHUTTER1 ;set the primary shutter CALL SHUTTER2 ;set the secondary shutter RETURN ;-------------------------------------------------------- ; S H U T T E R 1 ;Sets primary shutter open or closed. ; 0 = HIGH OUTPUT ; 1 = LOW OUTPUT ;9/4/03 ;-------------------------------------------------------- SHUTTER1: TABLD V2,[ZERO+30] BEQ V2,0,SHUT1ROB ;Robinson convention is opposite of the Fuchs convention ;BEQ V2,3,SHUT1ROB ;Visual convention is opposite of the Fuchs convention ;0=ROB,1=OKN,2=LED,3=VIS ;Fuchs shutters BEQ SHUT1,1,OPENF DIGOUT [.......1] ;close the primary shutter MARK 70 ;"F" for "OFF" RETURN OPENF: DIGOUT [.......0] ;open the primary shutter MARK 78 ;"N" for "ON" RETURN ;Robinson shutters SHUT1ROB: BEQ SHUT1,1,OPENR DIGOUT [.......0] ;close the primary shutter MARK 70 ;"F" for "OFF" RETURN OPENR: DIGOUT [.......1] ;open the primary shutter MARK 78 ;"N" for "ON" RETURN ;-------------------------------------------------------- ; S H U T T E R 2 ;Sets secondary shutter open or closed. ; 0 = HIGH OUTPUT ; 1 = LOW OUTPUT ;9/4/03 ;-------------------------------------------------------- SHUTTER2: BEQ SHUT2,1,S2OPEN DIGOUT [......0.] ;close the secondary shutter MARK 102 ;"f" for "off" RETURN S2OPEN: DIGOUT [......1.] ;open the secondary shutter MARK 110 ;"n" for "on" RETURN ;-------------------------------------------------------- ; F E E D ;Sends a feeder pulse. ;10/12/04 ;-------------------------------------------------------- FEED: DIGOUT [.....1..] ;1-high triggers the feeder DELAY 100 ;101-1 ms pulse width DIGOUT [.....0..] ;102-low is the feeder off state MARK 64 ;@ RETURN ;103- ;-------------------------------------------------------- ; Z E R O V A R ; ;Zeros all the re-usable VAR so that they are empty before ;using. ; ;11/8/04 ;-------------------------------------------------------- ZEROVAR: MOVI V1,0 MOVI V2,0 MOVI V3,0 MOVI V4,0 MOVI V5,0 MOVI V6,0 MOVI V7,0 MOVI V8,0 MOVI V9,0 MOVI V10,0 MOVI V11,0 MOVI V12,0 MOVI V11,0 MOVI V14,0 MOVI V15,0 MOVI V16,0 MOVI V17,0 MOVI V18,0 MOVI V19,0 MOVI V20,0 MOVI V21,0 MOVI V22,0 MOVI V23,0 MOVI V24,0 MOVI V25,0 MOVI V26,0 RETURN