module tmgdec; "Sten Hansen Fermilab 9-26-98 "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 " "Modified by ETM on 9/15/00 to use the new PLL system "Inputs.. Clk106MHz,VXO53MHz,Rf_Inn,Up pin 15,18,2,12; RF_Inp,Down,EncTmgp,EncTmgm pin 37,39,42,43; "Outputs.. Gap,SGap,FC,VXO_Div4 pin 28,21,33,44 istype 'reg'; Clk53MHzOut pin 34 istype 'reg'; PhDet pin 13 istype 'com'; RF_Dtct pin 22 istype 'reg'; "Buried nodes.. XCnt7..XCnt0,PSTC,XCTC node istype 'reg'; PS3..PS0,Enc_Div2 node istype 'reg'; S2..S0,D1,D0 node istype 'reg'; VXOCnt2..VXOCnt0,IDtct node istype 'reg'; "Set Definitions.. VXOCnt = [VXOCnt2..VXOCnt1,VXO_Div4,VXOCnt0]; PS = [PS3..PS0]; XCnt = [XCnt7..XCnt0]; EncTmg = EncTmgp; RF_In = RF_Inp; "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.. Enc_Div2.C = EncTmg; VXOCnt.C = VXO53MHz; [Gap.AR,SGap.AR,FC.AR,Clk53MHzOut.AR,IState.AR,VXOCnt.AR, PS.AR,XCnt.AR,D1.AR,D0.AR,Enc_Div2.AR] = Reset; "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); "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 := ((IState == IdleHi) # (IState == Shft1) # (IState == Shft3) # (IState == Shft5)) & Rem_Loc # !PS0 & !Rem_Loc; "Divide input by 2 to get 50% duty cycle before phase comparison Enc_Div2.T := 1; "Phase detector is just an XOR.. PhDet = Enc_Div2 $ VXOCnt0; " 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 & !Rem_Loc; "Terminal count for prescale counter PSTC := (PS == 12); "Increment crossing counter once for each 14 106MHz clocks.. When (!XCTC & PSTC & !Rem_Loc) then {XCnt := (XCnt + 1); } else When (Rem_Loc # XCTC & PSTC) then { XCnt := 0; } else { XCnt := XCnt; } "Terminal count for crossing counter.. XCTC := (XCnt == 158); 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 tmgdec;