Vous êtes sur la page 1sur 7

; Scifer2

;
; K21 CPU PROM VER: Scifer2 1.114 for HEEPS-E detector
; based on
; K21 CPU PROM VER: ROPA 0.105 for HEEPS-E detector
; based on
; K21 CPU PROM VER: Cascades 0.99 for HEEPS-E detector
; for Cascades Box 2 Tray 2 - K21_IC1 on 21_34_72 board
; does NOT have code to drive deflectable aperture -- that will go in the K72 CPU
;
;Scifer2 HE soldered in flight version is v1.113

;directives moved to front to make ASEM happy.


;directives added to make MetaLink ASM51.EXE happy:
$MOD51
$TITLE(K21 CPU PROM VER: Scifer2 1.114 for HEEPS-E)
$PAGEWIDTH(132)
$NOPAGING
$NODEBUG
$SYMBOLS
$OBJECT ;ASEM will object to this directive, no problem
; scf2_he.asm(19): illegal control statement
;

;Scifer2 HE soldered in flight version is v1.113


; v1.114 works on OVERSAMPLE stuff
; v1.113 adds shifts for 16 bins
; v1.112 can be assembled with ASM51 or ASEM_51 to get identical .HEX results
; the HEXBIN.EXE from ASEM will FF pad rather than 00 pad, otherwise .BINs are the same
; v1.111 adds stepping energy on every other set of bins
;
; based on K21 CPU PROM VER: Sersio 0.74 for HEEPS-E detector, which was
; based on Sersio source which was based on source from Mark Widholm,
; modified to assemble with ASM51.EXE from MetaLink
; original Sierra code used 12 HMz processor & crystal
; now running on 24 MHz processor and crystal

; Scifer2 telemetry set for 32 bins


; Cascades PFF telemetry set for 30 bins
; Cascades Main telemetry set for 32 bins (to make TM matrix align)
;
; With the 30 pad anode and the 5 bit gray code encoding for transmission
; to the box electronics, bin 00 can NEVER be used, as all bits 0 means
; no data. When outputting 32 bins, we start with the sweep step, then
; skip bin 0 (empty), and bins 1 .. 30 (the data), followed by bin 31.
; When outputting 30 bins, we skip the sweep step and we skip bin 0, and
; just output bins 1..30.

;SERSIO values:
;detector readout angle step steps sweep
; rate bins time time
;HEEPS T1 32K 64 2ms 64 128ms K21 - new prog 1
;HEEPS T2 32K 64 2ms 64 128ms K21 - new prog 1
;HEEPS M 32K 64 2ms 32 64ms K21 - new prog 3
;HEEPS E 16K 32 2ms 64 128ms K21 - prog 0
;BEEPS p 4K 16 4ms 64 256ms K21 - prog 2 modified
;BEEPS O 4K 16 4ms (64) 256ms K20 - prog 2 modified (sweep generated for BEEPS p is shared by
BEEPS O)

;Scifer2 values:
;detector readout angle step steps sweep
; rate bins time time
;HEEPS E 32K* 32 2ms 32 32ms based on K21 - prog 0
;HEEPS T 32K 64 2ms 64 128ms K21 - new prog 1
;HEEPS M 32K 64 2ms 32 64ms K21 - new prog 3
;BEEPS p 32K** 16 2ms 64 64ms K21 - prog 2 modified
;BEEPS O 32K** 16 2ms (64) 64ms K20 - prog 2 modified (sweep generated for BEEPS p is shared by
BEEPS O)
;* oversampled x2
;** oversampled x4

OVERSAMPLE EQU 1
;OVERSAMPLE EQU 0
SAMPLE EQU 2
;* oversampled x2

SKIP_ONE EQU 1 ;on RESET skip one word out


;SKIP_ONE EQU 0 ;on RESET skip one word out
SKIP_TWO EQU 1 ;on RESET skip two words out
;SKIP_TWO EQU 0 ;on RESET skip two words out

;SYNC1PPS EQU 1 ;force energy sweep to reset at 1PPS


SYNC1PPS EQU 0 ;don't force energy sweep to reset at 1PPS

DO32BINS EQU 1 ;specify conditional assembly for 32 bins output


;DO32BINS EQU 0 ;specify conditional assembly for 30 bins output
;DOHET EQU 1 ;specify conditional assembly for total counts in bin 31
DOHET EQU 0 ;specify conditional assembly for nothing in bin 31
IF (DOHET)
ECHOTWICE EQU 0
ELSE
;ECHOTWICE EQU 1
ECHOTWICE EQU 0
ENDIF ;IF (DOHET)

IF (DO32BINS)
;PAD8 EQU 1
PAD8 EQU 0
ELSE ;IF (DO32BINS)
;PAD8 EQU 1
PAD8 EQU 0
ENDIF ;IF (DO32BINS)

;ORG_ECHO EQU 0
ORG_ECHO EQU 1

TWO6 EQU 0
TWO5 EQU 32
TWO4 EQU 0

USING 0 ;Select addresses for Bank 0

; PORT USAGE
; P0 FIFO output
; P1 BNn input
; P2 DAC output - K21
; P3 single bit IO

; IO BITS
TST BIT P3.0
MAJF BIT P3.1
PPS1 BIT P3.2
;INT1 BIT P3.3
; BIT P3.4 ;COUNTER INPUT (NOT USED)
EVENT BIT P3.5
;WR BIT P3.6 ;LOAD FIFO
ACK BIT P3.7

; the AD-7111A can only sweep down when presented


; an ascending count, so the count must be provided as a count down to get an
; upward sweep with the AD-7111A
;

;tailored sweep information -- Presently same as for Sersio


;HEEPS-E sweep simulation program SWEEPE.FOR
; khe = 5.9 DETECTOR FACTOR
; hv = 300.0 HV BOARD AMPLIFICATION FACTOR
; board = 1.0 K21 BOARD DE-AMPLIFICATION FACTOR
; numsteps = 32
RESTART_HE EQU 200 ;194 - -6 == START_HE - INC_HE
START_HE EQU 194
INC_HE EQU -6
LAST_HE EQU 8
END_HE EQU 2 ;8 + -6 == LAST_HE + INC_HE

;INTERNAL RAM
;directive added to make MetaLink ASM51.EXE happy:
DSEG ;directly addressable Data memory SEGment definition

ORG 20H ;skip over register banks 0..3


SWP: DS 1 ;SWEEP STEP NUMBER
VECL: DS 1
VECH: DS 1
DS 8
IGNORE: DS 3

FLAG EQU R7

IF (OVERSAMPLE)
SKIP:
DS 1
ENDIF
ORG 40H ;IMAGE BINS. MUST BE AT 40H FOR HARDWARE
BIN0: DS 1
BIN1: DS 14
BIN15: DS 1
BIN16: DS 3
BIN19: DS 1
BIN20: DS 11
BIN31: DS 1 ;USED FOR TOTAL COUNTS
BIN32: DS 7
BIN39: DS 1
BIN40: DS 24
;ASEM will object to this, no problem: scf2_he.asm(164): segment limit exceeded
BIN64: DS 0

;directive added to make MetaLink ASM51.EXE happy:


CSEG ;code memory SEGment definition
ORG 0
JMP RESET_ ;1us JUMP AROUND INTR HANDLER

; ---------------------------------
ORG 13H
; External INT 1 vectors to here, so each external INT 1 will jump via this
; dispatch code to the appropriate PROGn
INTV1:
MOV SP,#VECH ;1us JUMP INDIRECT THRU VEC BY LOADING SP
RETI ;1us AND DOING A RET
; ---------------------------------

; RESET HAPPENS ONLY ON POWER UP (OR ATTEMPT TO READ EMPTY FIFO)


RESET_:
;
; write out data to FIFO a.s.a.p.
;
CLR A
IF (SKIP_TWO)
; MOVX @R0,A ;WRITE 0 TO FIFO BIN0 (ADDR NOT USED)
ELSE
IF (SKIP_ONE)
; MOVX @R0,A ;WRITE 0 TO FIFO BIN0 (ADDR NOT USED)
ELSE
MOVX @R0,A ;WRITE 0 TO FIFO BIN0 (ADDR NOT USED)
ENDIF ;IF (SKIP_ONE)
ENDIF ;IF (SKIP_TWO)

IF (DO32BINS)
MOV R0,#BIN0
ELSE
MOV R0,#BIN1
ENDIF ;IF (DO32BINS)

IF (SKIP_TWO)
INC R0
ENDIF ;IF (SKIP_TWO)

;----------------------------------- SET DATA TO TEST RAMP and output test ramp


LPRESET:
MOV @R0,A
INC R0
ADD A,#7
MOVX @R0,A ;WRITE TEST VALUE TO FIFO BIN?? (ADDR NOT USED)
IF (DO32BINS)
CJNE R0,#BIN31,LPRESET ;LOOP FOR 30 BINS
MOV @R0,A ;and output one more afterwards
INC R0
ADD A,#7
MOVX @R0,A ;WRITE TEST VALUE TO FIFO BIN?? (ADDR NOT USED)
ELSE
CJNE R0,#BIN30,LPRESET ;LOOP FOR 29 BINS
;only 29 bins because we output one already
ENDIF ;IF (DO32BINS)
IF (PAD8)
LPRESET8:
MOV @R0,A
INC R0
ADD A,#7
MOVX @R0,A ;WRITE TEST VALUE TO FIFO BIN?? (ADDR NOT USED)
CJNE R0,#BIN40,LPRESET8 ;LOOP FOR 8 BINS
ENDIF ;IF (PAD8)
;----------------------------------- END -- SET DATA TO TEST RAMP

; now that FIFO is filled, do rest of initialization


;
MOV TCON,#04H ;1us EDGE TRIG FOR INT1
MOV SWP,#START_HE ;RESET VALUE
MOV FLAG,#0
; MOV R7,#FLAG
MOV VECH,#00H
MOV VECL,#80H ;1us 80H LEAVES ROOM FOR RESET CODE
MOV SP,#IGNORE ;1us PLACE TO PUT PC IF INTERUPTED

IF (OVERSAMPLE) ; 1.113 -> 1.114


MOV SKIP,#SAMPLE ; 1.113 -> 1.114
ENDIF ; 1.113 -> 1.114

MOV IE,#84H ;1us ENABLE EXT INT1


JMP INTV1 ;1us

;-------------------------------------------------------

; EVENT WAIT LOOP (USED BY ALL PROGS)


IF (SYNC1PPS)
SWEEPSYNC:
CJNE FLAG,#0,WT_FOO
MOV SWP,#RESTART_HE ;RESET VALUE
MOV FLAG,#255
JMP WT_FOO
ENDIF ;IF (SYNC1PPS)

OK:
INC @R0 ;1/2us COUNT EVENT
IF (DOHET)
IF (DO32BINS)
MOV R0,#BIN31
CJNE @R0,#255,OK2 ;1us CHECK FOR WRAP
JMP WT
OK2:
INC @R0 ;1/2us COUNT TOTAL COUNTS
ENDIF ;DO32BINS
ELSE ;IF (DOHET)
IF (DO32BINS)
IF (ECHOTWICE)
MOV A,SWP ;1/2 uS
MOV R0,#BIN31
MOV @R0,A
ENDIF ;IF (ECHOTWICE)
ENDIF ;IF (DO32BINS)
ENDIF ;IF (DOHET)

WT:
IF (SYNC1PPS)
JB PPS1,SWEEPSYNC
MOV FLAG,#0
WT_FOO:
ENDIF ;IF (SYNC1PPS)

JNB EVENT,WT ;1us WAIT FOR: NEXT EVENT OR INTR


MOV A,P1 ;1us GET BIN # INTO A

IF (TWO4)
; mask out high bits
ANL A,#3FH ;1/2us 1.113 -> 1.114
CLR C ;1/2us 64 -> 32 mapping
RRC A ;1/2us shift bin number right 1 bit
ORL A,#40H ;1/2us 1.113 -> 1.114
ELSE ; IF (TWO4)
; do nothing
ENDIF ; IF (TWO4)

CLR ACK ;1/2us PULSE ACK- TO ENABLE NEXT EVENT


MOV R0,A
SETB ACK ;1/2us
IF (DOHET)
IF (DO32BINS)
CJNE R0,#BIN31,OK3 ;accumulating HET in BIN31, don't want noise to write there; all five bits on is NOT a
valid code
JMP WT
OK3:
ENDIF ;IF (DO32BINS)
ENDIF ;IF (DOHET)
CJNE @R0,#255,OK ;1us CHECK FOR WRAP
JMP WT ;1us IGNORE EVENT IF AT 255
;-------------------------------------------------------
ORG 80H
;detector readout angle step steps sweep
; rate bins time time
;HEEPS E 32K 32 1ms 32 32ms based on K21 - prog 0
;PROG0 HE 32 BYTE READOUT (SWP + 31 BINS). 32 STEP SWEEP.
; Cascades: HE == HEEPS-E: X26 & X34 for detection; X4a for bias; X18 for sweep
;RESTART_HE EQU 200 ;194 - -6 == START_HE - INC_HE
;START_HE EQU 194
;INC_HE EQU -6
;LAST_HE EQU 8
;END_HE EQU 2 ;8 + -6 == LAST_HE + INC_HE

PROG0:
MOV A,SWP ;1/2 uS
IF (DO32BINS)
MOV R0,#BIN0
MOV @R0,A ;1uS WRITE SWP TO FIFO BIN0 (ADDR NOT USED)
IF (ORG_ECHO)
MOVX @R0,A ;1uS WRITE SWP TO FIFO BIN0 (ADDR NOT USED)
ENDIF ;ORG_ECHO
IF (ECHOTWICE)
MOV R0,#BIN31
MOV @R0,A ;WRITE SWP TO BIN31 (WILL BE WRITTEN TO FIFO IN LOOP, BELOW)
ENDIF ;ECHOTWICE
ENDIF ;DO32BINS
MOV SP,#IGNORE ;1uS PLACE TO PUT PC IF INTERRUPTED
MOV P2,A ;OUTPUT SWEEP STEP TO DAC

; ADD A,#INC_HE
IF (OVERSAMPLE)
DJNZ SKIP,SKIPIT
ADD A,#INC_HE
MOV SKIP,#SAMPLE
SKIPIT:
ELSE ;IF (OVERSAMPLE)
ADD A,#INC_HE
ENDIF ;IF (OVERSAMPLE)

;
; since this next is an EQUAL compare, and the increment is not required to
; be +1 or -1, the starting value needs to be carefully chosen both for use
; here in restarting the next sweep and initially on RESET
;
CJNE A,#END_HE,FOO0 ;otherwise do restart of sweep when end value seen
MOV A,#START_HE ;RESET VALUE IF OVERFLOW
FOO0:
MOV SWP,A ;UPDATE SWEEP
JB TST,TST0

IF (ORG_ECHO)
MOV R0,#BIN1 ;OUTPUT BINS 1..30/31 TO FIFO
ELSE
IF (DO32BINS)
MOV R0,#BIN0 ;OUTPUT BINS 0..31 TO FIFO
ELSE
MOV R0,#BIN1 ;OUTPUT BINS 1..30 TO FIFO
ENDIF ;DO32BINS
ENDIF ;ORG_ECHO

LP0:
MOV A,@R0 ;GET BIN
MOVX @R0,A ;WRITE TO FIFO. (ADDR NOT USED)
CLR A
MOV @R0,A ;CLEAR BIN
INC R0
;IF (DO32BINS)
; CJNE R0,#BIN32,LP0 ;LOOP FOR 31 BINS
;ELSE
; CJNE R0,#BIN31,LP0 ;LOOP FOR 30 BINS
;ENDIF
IF (DO32BINS)
IF (PAD8)
CJNE R0,#BIN40,LP0 ;LOOP FOR 39 BINS; 31ST BIN IS EITHER HET OR OTHER BYTE OF TWO BYTE HET
ELSE ;IF (PAD8)
CJNE R0,#BIN32,LP0 ;LOOP FOR 31 BINS; 31ST BIN IS EITHER HET OR OTHER BYTE OF TWO BYTE HET
ENDIF ;IF (PAD8)
ELSE ;IF (DO32BINS)
IF (PAD8)
CJNE R0,#BIN39,LP0 ;LOOP FOR 38 BINS
ELSE ;IF (PAD8)
CJNE R0,#BIN31,LP0 ;LOOP FOR 30 BINS
ENDIF ;IF (PAD8)
ENDIF ;IF (DO32BINS)
SETB ACK ;MAKE SURE ACK- IS HI
JMP WT

; 32 BIN TEST PATTERN GENERATOR.


; LOADS RAMP INTO 32 BINS WHEN TST BIT IS HIGH
TST0:
MOV R1,#8 ;R1 IS RAMP COUNTER

IF (ORG_ECHO)
MOV R0,#BIN1 ;OUTPUT BINS 1..30/31 TO FIFO
ELSE
IF (DO32BINS)
MOV R0,#BIN0 ;OUTPUT BINS 0..31 TO FIFO
ELSE
MOV R0,#BIN1 ;OUTPUT BINS 1..30 TO FIFO
ENDIF ;DO32BINS
ENDIF ;ORG_ECHO

TLP0:
MOV A,@R0 ;GET BIN
MOVX @R0,A ;WRITE TO FIFO. (ADDR NOT USED)
MOV A,R1
MOV @R0,A ;SET BIN TO RAMP VALUE
ADD A,#7
MOV R1,A ;BUMP RAMP BY 7
INC R0
IF (DO32BINS)
IF (PAD8)
CJNE R0,#BIN40,TLP0 ;LOOP FOR 39 BINS; 31ST BIN IS EITHER HET OR OTHER BYTE OF TWO BYTE HET
ELSE ;IF (PAD8)
CJNE R0,#BIN32,TLP0 ;LOOP FOR 31 BINS; 31ST BIN IS EITHER HET OR OTHER BYTE OF TWO BYTE HET
ENDIF ;IF (PAD8)
ELSE ;IF (DO32BINS)
IF (PAD8)
CJNE R0,#BIN39,TLP0 ;LOOP FOR 38 BINS
ELSE ;IF (PAD8)
CJNE R0,#BIN31,TLP0 ;LOOP FOR 30 BINS
ENDIF ;IF (PAD8)
ENDIF ;IF (DO32BINS)

SETB ACK ;MAKE SURE ACK- IS HI


JMP WT

;Nominal sweep information:


;"Step", "N", "Vout", "Scaled"
;000, 194, -.276491E-02, .276491E-02
;001, 188, -.358246E-02, .358246E-02
;002, 182, -.464175E-02, .464175E-02
;003, 176, -.601425E-02, .601425E-02
;004, 170, -.779258E-02, .779258E-02
;005, 164, -.100967E-01, .100967E-01
;006, 158, -.130822E-01, .130822E-01
;007, 152, -.169505E-01, .169505E-01
;008, 146, -.219625E-01, .219625E-01
;009, 140, -.284565E-01, .284565E-01
;010, 134, -.368707E-01, .368707E-01
;011, 128, -.477729E-01, .477729E-01
;012, 122, -.618987E-01, .618987E-01
;013, 116, -.802013E-01, .802013E-01
;014, 110, -.103916 , .103916
;015, 104, -.134642 , .134642
;016, 098, -.174454 , .174454
;017, 092, -.226038 , .226038
;018, 086, -.292874 , .292874
;019, 080, -.379473 , .379473
;020, 074, -.491678 , .491678
;021, 068, -.637061 , .637061
;022, 062, -.825432 , .825432
;023, 056, -1.06950 , 1.06950
;024, 050, -1.38574 , 1.38574
;025, 044, -1.79548 , 1.79548
;026, 038, -2.32638 , 2.32638
;027, 032, -3.01426 , 3.01426
;028, 026, -3.90554 , 3.90554
;029, 020, -5.06036 , 5.06036
;030, 014, -6.55664 , 6.55664
;031, 008, -8.49535 , 8.49535

ROM_ID:
DB 'K21 CPU PROM VER: Scifer2 1.114 for HEEPS-E; '
IF (OVERSAMPLE)
SWEEPDATA:
DB 'HEEPS E 32K* 32bins 2mS/Step 32Steps 64mS/sweep; '
DB 'Step energy sweep every SECOND set of bins '
;* oversampled x2
;ELSE ;IF (OVERSAMPLE)
;SWEEPDATA:
; DB 'HEEPS E 32K 32bins 1mS/Step 32Steps 32mS/sweep; '
; DB 'Step energy sweep every set of bins '
ENDIF ;IF (OVERSAMPLE)

OPTIONS:
;IF (FAST_OUT)
DB 'Fast_Out; '
;ELSE
; DB 'NO_Fast_Out; '
;ENDIF ;IF (FAST_OUT)

IF (SKIP_TWO)
DB 'on RESET skip two words out; '
ELSE ;IF (SKIP_TWO)
IF (SKIP_ONE)
DB 'on RESET skip ONE word out; '
ELSE ;IF (SKIP_ONE)
DB 'on RESET DO NOT Skip ANY words out; '
ENDIF ;IF (SKIP_ONE)
ENDIF ;IF (SKIP_TWO)

IF (SYNC1PPS)
DB 'force energy sweep to reset at 1PPS; '
ELSE
DB 'NO_SYNC1PPS; '
ENDIF ;IF (SYNC1PPS)

IF (DO32BINS)
IF (PAD8)
DB '40 bins output; '
ELSE ;IF (PAD8)
DB '32 bins output; '
ENDIF ;IF (PAD8)
IF (DOHET)
DB 'pseudo-total counts in bin 31; '
ELSE ;IF (DOHET)
DB 'nothing in bin 31; '
ENDIF ;IF (DOHET)
ELSE ;IF (DO32BINS)
IF (PAD8)
DB '38 bins output; '
ELSE ;IF (PAD8)
DB '30 bins output; '
ENDIF ;IF (PAD8)
ENDIF ;IF (DO32BINS)

;IF (PARANOID)
; DB 'PARANOID; '
;ELSE
DB 'NOT_PARANOID; '
;ENDIF ;IF (PARANOID)

END