module tmgdec; "Sten Hansen Fermilab 10-19-00 "Decodes Gap, Sync Gap and FC from 53MHz encoded data when in remote mode. "Generates these signals internally when in local mode. "Phase detector compares phase of incoming encoded timing with local VXO. "Divides 53MHz by 4 for use by ST49C101 x8 frequency multiplier. "Generates a status output when 53MHz RF is present "Generates 2.9 us reference pulse from FC for CBDelay chip. "Inputs.. Clk106MHz,VXO53MHz,Reset pin 15,18,2; RF_In,Rem_Loc,nEncTmg,EncTmg pin 37,39,42,43; Init pin 28; "Outputs.. Gap,SGap,FC,VXO_Div2 pin 30,21,20,44 istype 'reg'; Clk53MHzOut pin 11 istype 'reg'; UP,DN pin 13,12 istype 'com'; RF_Dtct pin 22 istype 'reg'; EnR,EnL pin 34,35 istype 'com'; "Buried nodes.. XCnt7..XCnt0,PSTC,XCTC node istype 'reg'; PS3..PS0,Mult_Div2 node istype 'reg'; S2..S0,D1,D0 node istype 'reg'; VXOCnt2..VXOCnt0,IDtct node istype 'reg'; Enc_FF,VXO_FF node istype 'reg'; "Set Definitions.. VXOCnt = [VXOCnt2..VXOCnt0,VXO_Div2]; PS = [PS3..PS0]; XCnt = [XCnt7..XCnt0]; "Define serial data bit patterns.. SData = [D1,D0,EncTmg]; SGapHi = [0,0,0]; FCHi = [0,0,1]; FCLo = [0,1,0]; SGapFCHi = [0,1,1]; GapHi = [1,0,0]; AllLo = [1,0,1]; "State definitions.. IState = [S2..S0]; IdleLo = [0,0,0]; "0 IdleHi = [0,0,1]; "1 Shft0 = [0,1,0]; "2 Shft1 = [0,1,1]; "3 Shft2 = [1,0,0]; "4 Shft3 = [1,0,1]; "5 Shft4 = [1,1,0]; "6 Shft5 = [1,1,1]; "7 Equations [Gap.C,SGap.C,FC.C,Clk53MHzOut.C,IState.C,D1.C,D0.C,PS.C,XCnt.C, XCTC.C,PSTC.C] = !Clk106MHz; "Clocks for phase detector related signals.. [VXOCnt.C] = VXO53MHz; Mult_Div2.C = !Clk106MHz; [Gap.AR,SGap.AR,FC.AR,Clk53MHzOut.AR,IState.AR,VXOCnt.AR, PS.AR,XCnt.AR,D1.AR,D0.AR] = Reset; Mult_Div2.t := 1; VXO_FF := 1; VXO_FF.AR = VXO_FF & Enc_FF; VXO_FF.C = Mult_Div2; Enc_FF := Rem_Loc; Enc_FF.AR = VXO_FF & Enc_FF; Enc_FF.C = !nEncTmg; "In Remote mode enable UP and DN according to Phase Detector FFs "In Local mode, produce a 50% duty cycle square wave on DN, tri-state "UP off to supply ~1.8V to the tuning pin of the VXO UP = 1; UP.OE = !VXO_FF & Enc_FF; DN = VXOCnt1 & !Rem_Loc; DN.OE = VXO_FF & !Enc_FF; "Reset internal clock detect periodically IDtct.C = RF_In; IDtct := 1; IDtct.AR = (VXOCnt == 15); "Arrange for external clock detect to be a DC level for less EMI RF_Dtct.C = RF_In; RF_Dtct := 1; RF_Dtct.AR = !IDtct & (VXOCnt == 7); EnR = 1; EnL = 0; "Use bit 1 of the counter as VXO/4 to get correct frequency for x8 multiplier VXOCnt := (VXOCnt + 1); "Keep clock in phase with encoded clock, or with internal signal generator.. Clk53MHzOut := !Clk53MHzOut # !PS0 & !Rem_Loc # (IState == Shft1) & Rem_Loc; " Shift in 2 data bits from Encoded Clock stream D0 := EncTmg; D1 := D0; " Once data is shifted in, output transitions depend on the resulting " 3 bit pattern (D1,D0,Encoded Clock) if in remote mode. In local mode " outputs are dependent on internal counter values (XCnt) SGap.T := !SGap & ((IState == Shft2) & ((SData == SGapHi) # (SData == SGapFCHi)) & Rem_Loc # (XCnt == 1) & PSTC & !Rem_Loc) # SGap & ((IState == Shft2) & (SData == AllLo) & Rem_Loc # (XCnt == 18) & PSTC & !Rem_Loc); FC.T := !FC & ((IState == Shft2) & ((SData == FCHi) # (SData == SGapFCHi)) & Rem_Loc # (XCnt == 11) & PSTC & !Rem_Loc) # FC & ((IState == Shft2) & ((SData == FCLo) # (SData == AllLo)) & Rem_Loc # (XCnt == 12) & PSTC & !Rem_Loc); Gap.T := !Gap & ((IState == Shft2) & (SData == GapHi) & Rem_Loc # ((XCnt == 54) # (XCnt == 108)) & PSTC & !Rem_Loc) # Gap & ((IState == Shft2) & (SData == AllLo) & Rem_Loc # ((XCnt == 71) # (XCnt == 125)) & PSTC & !Rem_Loc); "Prescale 106MHz by 14 to get 7MHz crossing rate.. PS := (PS + 1) & !PSTC; "Terminal count for prescale counter PSTC := (PS == 12) # ((IState == Shft2) & (SData == FCHi)) & Rem_Loc; "Increment crossing counter once for each 14 106MHz clocks.. When (!XCTC & PSTC) then {XCnt := (XCnt + 1); } else When ( XCTC & PSTC) then { XCnt := 0; } else { XCnt := XCnt; } "Terminal count for crossing counter.. XCTC := (XCnt == 158) & !Rem_Loc # FC & Rem_Loc; State_Diagram IState "Bounce between IdleLo and IdleHi until EncTmg is high for 2 cycles.. State IdleLo: If EncTmg then IdleHi else IdleLo; State IdleHi: If !EncTmg then IdleLo else Shft0; "Go through a total of 8 states before looking for another pattern.. State Shft0: goto Shft1; State Shft1: goto Shft2; State Shft2: goto Shft3; State Shft3: goto Shft4; State Shft4: goto Shft5; State Shft5: goto IdleLo; end tmggen;