S5443TopS.v 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // company:
  4. // engineer:
  5. //
  6. // create date: 12:23:20 05/20/2019
  7. // design name:
  8. // module name: S5443Top
  9. // project name:
  10. // target devices:
  11. // tool versions:
  12. // description:
  13. //
  14. // dependencies:
  15. //
  16. // revision:
  17. // revision 0.01 - file created
  18. // additional comments:
  19. //
  20. //================================================================================
  21. //
  22. //Spi clock for ADC initialization is 15Mhz.
  23. //Spi clock for RegMap work is 41Mhz.
  24. //Нужно сделать процедуру сброса для импульсных измерений, такую же как для обычных, тоесть по детектированию спадающего фронта StartMeas.
  25. //Забрать из команды настройки измерения, биты управления ключем и замкнуть на выходы.
  26. //////////////////////////////////////////////////////////////////////////////////
  27. // xc7s25-2csga225
  28. module S5443TopS
  29. #(
  30. parameter LpDataWidth = 16,
  31. parameter CtrlWidth = 4,
  32. parameter AdcDataWidth = 14,
  33. parameter ThresholdWidth = 24,
  34. parameter ResultWidth = 32,
  35. parameter ChNum = 4,
  36. parameter PGenNum = 7,
  37. parameter TrigPortsNum = 6,
  38. parameter Ratio = 8,
  39. parameter DelayValue = 24000,
  40. parameter LengthWidth = 2000,
  41. parameter DataWidth = 24,
  42. parameter DataNum = 26,
  43. parameter CmdRegWidth = 32,
  44. parameter HeaderWidth = 7,
  45. parameter CmdDataRegWith = 24,
  46. parameter DataCntWidth = 5,
  47. parameter Divparam = 4,
  48. parameter MeasPeriod = 9,
  49. parameter PhIncWidth = 32,
  50. parameter NcoWidth = 18
  51. )
  52. (
  53. //common ports
  54. input Clk_i,
  55. //fpga-adc1 data interface
  56. input Adc1FclkP_i,
  57. input Adc1FclkN_i,
  58. input Adc1DataDa0P_i,
  59. input Adc1DataDa0N_i,
  60. input Adc1DataDa1P_i,
  61. input Adc1DataDa1N_i,
  62. input Adc1DataDb0P_i,
  63. input Adc1DataDb0N_i,
  64. input Adc1DataDb1P_i,
  65. input Adc1DataDb1N_i,
  66. //fpga-adc2 data interface
  67. input Adc2FclkP_i,
  68. input Adc2FclkN_i,
  69. input Adc2DataDa0P_i,
  70. input Adc2DataDa0N_i,
  71. input Adc2DataDa1P_i,
  72. input Adc2DataDa1N_i,
  73. input Adc2DataDb0P_i,
  74. input Adc2DataDb0N_i,
  75. input Adc2DataDb1P_i,
  76. input Adc2DataDb1N_i,
  77. //fpga-adc's initialization interface
  78. output AdcInitMosi_o,
  79. output AdcInitClk_o,
  80. output Adc1InitCs_o,
  81. output Adc2InitCs_o,
  82. output AdcInitRst_o,
  83. //ditherCtrl
  84. output DitherCtrlCh1_o,
  85. output DitherCtrlCh2_o,
  86. //fpga-dsp cmd interface
  87. input Mosi_i,
  88. input Sck_i,
  89. input Ss_i,
  90. // input Miso_i,
  91. output Miso_o,
  92. //fpga-dsp data interface
  93. output LpOutClk_o,
  94. output LpOutFs_o,
  95. output [LpDataWidth-1:0] LpOutData_o,
  96. //fpga-dsp signals
  97. input StartMeasEvent_i, //"high"- start meas, "low"-stop meas
  98. //overload lines
  99. output Overload_o,
  100. //gain lines
  101. inout SensEnS_io,
  102. output [ChNum-1:0] AmpEn_o, // 0-adc1ChA 1-adc1ChB 2-adc2ChA 3-adc2ChB
  103. ///test port for testbench
  104. input [AdcDataWidth-1:0] AdcData_i
  105. );
  106. //================================================================================
  107. // reg/wire
  108. //================================================================================
  109. //captured data
  110. wire [AdcDataWidth-1:0] adc1ChT1Data;
  111. wire [AdcDataWidth-1:0] adc1ChR1Data;
  112. wire [AdcDataWidth-1:0] adc2ChR2Data;
  113. wire [AdcDataWidth-1:0] adc2ChT2Data;
  114. reg startMeasSync;
  115. wire pGensRst = (startMeasSync & !StartMeasEvent_i);
  116. wire StartMeasEvent_i;
  117. wire gatingPulse;
  118. wire sampleStrobe;
  119. //spi signals for adc init
  120. wire adcInitRst;
  121. wire adcInitMosi;
  122. wire adcInitSck;
  123. wire adc0InitCs;
  124. wire adc1InitCs;
  125. wire [ResultWidth-1:0] adc1ImT1;
  126. wire [ResultWidth-1:0] adc1ReT1;
  127. wire [ResultWidth-1:0] adc1ImR1;
  128. wire [ResultWidth-1:0] adc1ReR1;
  129. wire [ResultWidth-1:0] adc2ImT2;
  130. wire [ResultWidth-1:0] adc2ReT2;
  131. wire [ResultWidth-1:0] adc2ImR2;
  132. wire [ResultWidth-1:0] adc2ReR2;
  133. wire measDataRdy;
  134. wire timersClk;
  135. wire [ThresholdWidth-1:0] lowThreshold;
  136. wire [ThresholdWidth-1:0] highThreshold;
  137. wire initRst;
  138. wire gclk;
  139. reg ledReg;
  140. wire [CmdRegWidth-1:0] cmdDataReg;
  141. wire cmdDataVal;
  142. wire [CmdDataRegWith-1:0] ansReg;
  143. wire [HeaderWidth-1:0] ansAddr;
  144. wire [CmdDataRegWith-1:0] gainCtrl;
  145. wire [CmdDataRegWith-1:0] gainLowThreshT1;
  146. wire [CmdDataRegWith-1:0] gainHighThreshT1;
  147. wire [CmdDataRegWith-1:0] gainLowThreshR1;
  148. wire [CmdDataRegWith-1:0] gainHighThreshR1;
  149. wire [CmdDataRegWith-1:0] gainLowThreshT2;
  150. wire [CmdDataRegWith-1:0] gainHighThreshT2;
  151. wire [CmdDataRegWith-1:0] gainLowThreshR2;
  152. wire [CmdDataRegWith-1:0] gainHighThreshR2;
  153. wire [ChNum-1:0] overCtrlChannels;
  154. wire [CmdDataRegWith-1:0] overCtrl = {{CmdDataRegWith-ChNum{1'b0}},overCtrlChannels};
  155. wire [CmdDataRegWith-1:0] overThresh;
  156. wire [CmdDataRegWith-1:0] ditherCtrl;
  157. wire [CmdDataRegWith-1:0] windowGenPhase1;
  158. wire [CmdDataRegWith-1:0] windowGenPhase2;
  159. wire [CmdDataRegWith-1:0] adcCtrl;
  160. wire [CmdDataRegWith-1:0] adcDirectRd0;
  161. wire [CmdDataRegWith-1:0] adcDirectRd1;
  162. wire [CmdDataRegWith-1:0] ifFtwL;
  163. wire [CmdDataRegWith-1:0] ifFtwH;
  164. wire [CmdDataRegWith-1:0] measCtrl;
  165. wire [CmdDataRegWith-1:0] amplitudeMod;
  166. wire [CmdDataRegWith-1:0] dspTrigIn;
  167. wire [CmdDataRegWith-1:0] dspTrigOut;
  168. wire [CmdDataRegWith-1:0] dspTrigIn1;
  169. wire [CmdDataRegWith-1:0] dspTrigIn2;
  170. wire [CmdDataRegWith-1:0] dspTrigOut1;
  171. wire [CmdDataRegWith-1:0] dspTrigOut2;
  172. wire [CmdDataRegWith-1:0] filterCorrCoefL;
  173. wire [CmdDataRegWith-1:0] filterCorrCoefH;
  174. wire trigToDsp0;
  175. wire trigToDsp1;
  176. wire intTrigToExtDev0;
  177. wire intTrigToExtDev1;
  178. wire delayDoneFlag0;
  179. wire delayDoneFlag1;
  180. wire trigEn0;
  181. wire trigEn1;
  182. wire stopMeas;
  183. reg stopMeasR;
  184. wire [NcoWidth-1:0] ncoCos;
  185. wire [NcoWidth-1:0] ncoSin;
  186. wire [CmdDataRegWith-1:0] gainLowThresholdBus [ChNum-1:0];
  187. wire [CmdDataRegWith-1:0] gainHighThresholdBus [ChNum-1:0];
  188. wire [ChNum-1:0] ampEnNewStates;
  189. wire [ChNum-1:0] sensEn;
  190. reg sensEnReg;
  191. wire sensEnNeg = (sensEnReg&!SensEnS_io);
  192. wire [ChNum-1:0] gainManual;
  193. wire [AdcDataWidth-1:0] adcDataBus [ChNum-1:0];
  194. wire overCtrlR = |overCtrlChannels[ChNum-1:0];
  195. localparam TESTCNTPARAM = 32'd100000000;
  196. reg [31:0] testCnt;
  197. wire refClk;
  198. wire Clk100;
  199. wire measWind;
  200. wire measTrig;
  201. wire measTrigVal;
  202. wire refSeqPulse;
  203. wire refSeq;
  204. //Pmeas wires
  205. //PG1 Regs
  206. wire [CmdDataRegWith-1:0] pG1P1Del;
  207. wire [CmdDataRegWith-1:0] pG1P2Del;
  208. wire [CmdDataRegWith-1:0] pG1P3Del;
  209. wire [CmdDataRegWith-1:0] pG1P123Del;
  210. wire [CmdDataRegWith-1:0] pG1P1Width;
  211. wire [CmdDataRegWith-1:0] pG1P2Width;
  212. wire [CmdDataRegWith-1:0] pG1P3Width;
  213. wire [CmdDataRegWith-1:0] pG1P123Width;
  214. //PG2 Regs
  215. wire [CmdDataRegWith-1:0] pG2P1Del;
  216. wire [CmdDataRegWith-1:0] pG2P2Del;
  217. wire [CmdDataRegWith-1:0] pG2P3Del;
  218. wire [CmdDataRegWith-1:0] pG2P123Del;
  219. wire [CmdDataRegWith-1:0] pG2P1Width;
  220. wire [CmdDataRegWith-1:0] pG2P2Width;
  221. wire [CmdDataRegWith-1:0] pG2P3Width;
  222. wire [CmdDataRegWith-1:0] pG2P123Width;
  223. //PG3 Regs
  224. wire [CmdDataRegWith-1:0] pG3P1Del;
  225. wire [CmdDataRegWith-1:0] pG3P2Del;
  226. wire [CmdDataRegWith-1:0] pG3P3Del;
  227. wire [CmdDataRegWith-1:0] pG3P123Del;
  228. wire [CmdDataRegWith-1:0] pG3P1Width;
  229. wire [CmdDataRegWith-1:0] pG3P2Width;
  230. wire [CmdDataRegWith-1:0] pG3P3Width;
  231. wire [CmdDataRegWith-1:0] pG3P123Width;
  232. //PG4 Regs
  233. wire [CmdDataRegWith-1:0] pG4P1Del;
  234. wire [CmdDataRegWith-1:0] pG4P2Del;
  235. wire [CmdDataRegWith-1:0] pG4P3Del;
  236. wire [CmdDataRegWith-1:0] pG4P123Del;
  237. wire [CmdDataRegWith-1:0] pG4P1Width;
  238. wire [CmdDataRegWith-1:0] pG4P2Width;
  239. wire [CmdDataRegWith-1:0] pG4P3Width;
  240. wire [CmdDataRegWith-1:0] pG4P123Width;
  241. //PG5 Regs
  242. wire [CmdDataRegWith-1:0] pG5P1Del;
  243. wire [CmdDataRegWith-1:0] pG5P2Del;
  244. wire [CmdDataRegWith-1:0] pG5P3Del;
  245. wire [CmdDataRegWith-1:0] pG5P123Del;
  246. wire [CmdDataRegWith-1:0] pG5P1Width;
  247. wire [CmdDataRegWith-1:0] pG5P2Width;
  248. wire [CmdDataRegWith-1:0] pG5P3Width;
  249. wire [CmdDataRegWith-1:0] pG5P123Width;
  250. //PG6 Regs
  251. wire [CmdDataRegWith-1:0] pG6P1Del;
  252. wire [CmdDataRegWith-1:0] pG6P2Del;
  253. wire [CmdDataRegWith-1:0] pG6P3Del;
  254. wire [CmdDataRegWith-1:0] pG6P123Del;
  255. wire [CmdDataRegWith-1:0] pG6P1Width;
  256. wire [CmdDataRegWith-1:0] pG6P2Width;
  257. wire [CmdDataRegWith-1:0] pG6P3Width;
  258. wire [CmdDataRegWith-1:0] pG6P123Width;
  259. //PG7 Regs
  260. wire [CmdDataRegWith-1:0] pG7P1Del;
  261. wire [CmdDataRegWith-1:0] pG7P2Del;
  262. wire [CmdDataRegWith-1:0] pG7P3Del;
  263. wire [CmdDataRegWith-1:0] pG7P123Del;
  264. wire [CmdDataRegWith-1:0] pG7P1Width;
  265. wire [CmdDataRegWith-1:0] pG7P2Width;
  266. wire [CmdDataRegWith-1:0] pG7P3Width;
  267. wire [CmdDataRegWith-1:0] pG7P123Width;
  268. wire [CmdDataRegWith-1:0] measNum1;
  269. wire [CmdDataRegWith-1:0] measNum2;
  270. wire [CmdDataRegWith-1:0] pgMode0;
  271. wire [CmdDataRegWith-1:0] pgMode1;
  272. wire [CmdDataRegWith-1:0] muxCtrl1;
  273. wire [CmdDataRegWith-1:0] muxCtrl2;
  274. wire [CmdDataRegWith-1:0] muxCtrl3;
  275. wire [CmdRegWidth-29:0] pgModeArray [PGenNum-1:0];
  276. wire pgPulsePolArray [PGenNum-1:0];
  277. wire pgEnEdgeArray [PGenNum-1:0];
  278. wire [CmdRegWidth-29:0] pgMuxCtrlArray [PGenNum-1:0];
  279. wire [CmdRegWidth-29:0] extTrigMuxCtrlArray [TrigPortsNum-1:0];
  280. wire [TrigPortsNum-1:0] extTrigDirCmd = measCtrl[21:16];
  281. wire [CmdRegWidth-1:0] pgP1DelArray [PGenNum-1:0];
  282. wire [CmdRegWidth-1:0] pgP2DelArray [PGenNum-1:0];
  283. wire [CmdRegWidth-1:0] pgP3DelArray [PGenNum-1:0];
  284. wire [CmdRegWidth-1:0] pgP1WidthArray [PGenNum-1:0];
  285. wire [CmdRegWidth-1:0] pgP2WidthArray [PGenNum-1:0];
  286. wire [CmdRegWidth-1:0] pgP3WidthArray [PGenNum-1:0];
  287. wire [PGenNum-1:0] pulseBus;
  288. wire [PGenNum-1:0] pgMuxedOut;
  289. wire [TrigPortsNum-1:0] extPortsMuxedOut;
  290. wire measEnd;
  291. wire modOut;
  292. wire [3:0] modKeyCtrl;
  293. wire tirgToDspEvent;
  294. wire trigFromDspEvent;
  295. //================================================================================
  296. // assignments
  297. //================================================================================
  298. assign pgModeArray [PGenNum-1] = pgMode0[21:18];
  299. assign pgModeArray [PGenNum-2] = pgMode0[17:15];
  300. assign pgModeArray [PGenNum-3] = pgMode0[14:12];
  301. assign pgModeArray [PGenNum-4] = pgMode0[11:9];
  302. assign pgModeArray [PGenNum-5] = pgMode0[8:6];
  303. assign pgModeArray [PGenNum-6] = pgMode0[5:3];
  304. assign pgModeArray [PGenNum-7] = pgMode0[2:0];
  305. assign pgPulsePolArray [PGenNum-1] = pgMode1[16];
  306. assign pgPulsePolArray [PGenNum-2] = pgMode1[15];
  307. assign pgPulsePolArray [PGenNum-3] = pgMode1[14];
  308. assign pgPulsePolArray [PGenNum-4] = pgMode1[13];
  309. assign pgPulsePolArray [PGenNum-5] = pgMode1[12];
  310. assign pgPulsePolArray [PGenNum-6] = pgMode1[11];
  311. assign pgPulsePolArray [PGenNum-7] = pgMode1[10];
  312. assign pgEnEdgeArray [PGenNum-1] = pgMode1[23];
  313. assign pgEnEdgeArray [PGenNum-2] = pgMode1[22];
  314. assign pgEnEdgeArray [PGenNum-3] = pgMode1[21];
  315. assign pgEnEdgeArray [PGenNum-4] = pgMode1[20];
  316. assign pgEnEdgeArray [PGenNum-5] = pgMode1[19];
  317. assign pgEnEdgeArray [PGenNum-6] = pgMode1[18];
  318. assign pgEnEdgeArray [PGenNum-7] = pgMode1[17];
  319. assign pgMuxCtrlArray [PGenNum-1] = muxCtrl2[3:0];
  320. assign pgMuxCtrlArray [PGenNum-2] = muxCtrl1[23:20];
  321. assign pgMuxCtrlArray [PGenNum-3] = muxCtrl1[19:16];
  322. assign pgMuxCtrlArray [PGenNum-4] = muxCtrl1[15:12];
  323. assign pgMuxCtrlArray [PGenNum-5] = muxCtrl1[11:8];
  324. assign pgMuxCtrlArray [PGenNum-6] = muxCtrl1[7:4];
  325. assign pgMuxCtrlArray [PGenNum-7] = muxCtrl1[3:0];
  326. assign extTrigMuxCtrlArray [TrigPortsNum-1] = muxCtrl3[23:20];
  327. assign extTrigMuxCtrlArray [TrigPortsNum-2] = muxCtrl3[19:16];
  328. assign extTrigMuxCtrlArray [TrigPortsNum-3] = muxCtrl3[15:12];
  329. assign extTrigMuxCtrlArray [TrigPortsNum-4] = muxCtrl3[11:8];
  330. assign extTrigMuxCtrlArray [TrigPortsNum-5] = muxCtrl3[7:4];
  331. assign extTrigMuxCtrlArray [TrigPortsNum-6] = muxCtrl3[3:0];
  332. assign pgP1DelArray[PGenNum-1] = {pG7P123Del[7:0],pG7P1Del};
  333. assign pgP1DelArray[PGenNum-2] = {pG6P123Del[7:0],pG6P1Del};
  334. assign pgP1DelArray[PGenNum-3] = {pG5P123Del[7:0],pG5P1Del};
  335. assign pgP1DelArray[PGenNum-4] = {pG4P123Del[7:0],pG4P1Del};
  336. assign pgP1DelArray[PGenNum-5] = {pG3P123Del[7:0],pG3P1Del};
  337. assign pgP1DelArray[PGenNum-6] = {pG2P123Del[7:0],pG2P1Del};
  338. assign pgP1DelArray[PGenNum-7] = {pG1P123Del[7:0],pG1P1Del};
  339. assign pgP2DelArray[PGenNum-1] = {pG7P123Del[15:8],pG7P2Del};
  340. assign pgP2DelArray[PGenNum-2] = {pG6P123Del[15:8],pG6P2Del};
  341. assign pgP2DelArray[PGenNum-3] = {pG5P123Del[15:8],pG5P2Del};
  342. assign pgP2DelArray[PGenNum-4] = {pG4P123Del[15:8],pG4P2Del};
  343. assign pgP2DelArray[PGenNum-5] = {pG3P123Del[15:8],pG3P2Del};
  344. assign pgP2DelArray[PGenNum-6] = {pG2P123Del[15:8],pG2P2Del};
  345. assign pgP2DelArray[PGenNum-7] = {pG1P123Del[15:8],pG1P2Del};
  346. assign pgP3DelArray[PGenNum-1] = {pG7P123Del[23:16],pG7P3Del};
  347. assign pgP3DelArray[PGenNum-2] = {pG6P123Del[23:16],pG6P3Del};
  348. assign pgP3DelArray[PGenNum-3] = {pG5P123Del[23:16],pG5P3Del};
  349. assign pgP3DelArray[PGenNum-4] = {pG4P123Del[23:16],pG4P3Del};
  350. assign pgP3DelArray[PGenNum-5] = {pG3P123Del[23:16],pG3P3Del};
  351. assign pgP3DelArray[PGenNum-6] = {pG2P123Del[23:16],pG2P3Del};
  352. assign pgP3DelArray[PGenNum-7] = {pG1P123Del[23:16],pG1P3Del};
  353. assign pgP1WidthArray[PGenNum-1] = {pG7P123Width[7:0],pG7P1Width};
  354. assign pgP1WidthArray[PGenNum-2] = {pG6P123Width[7:0],pG6P1Width};
  355. assign pgP1WidthArray[PGenNum-3] = {pG5P123Width[7:0],pG5P1Width};
  356. assign pgP1WidthArray[PGenNum-4] = {pG4P123Width[7:0],pG4P1Width};
  357. assign pgP1WidthArray[PGenNum-5] = {pG3P123Width[7:0],pG3P1Width};
  358. assign pgP1WidthArray[PGenNum-6] = {pG2P123Width[7:0],pG2P1Width};
  359. assign pgP1WidthArray[PGenNum-7] = {pG1P123Width[7:0],pG1P1Width};
  360. assign pgP2WidthArray[PGenNum-1] = {pG7P123Width[15:8],pG7P2Width};
  361. assign pgP2WidthArray[PGenNum-2] = {pG6P123Width[15:8],pG6P2Width};
  362. assign pgP2WidthArray[PGenNum-3] = {pG5P123Width[15:8],pG5P2Width};
  363. assign pgP2WidthArray[PGenNum-4] = {pG4P123Width[15:8],pG4P2Width};
  364. assign pgP2WidthArray[PGenNum-5] = {pG3P123Width[15:8],pG3P2Width};
  365. assign pgP2WidthArray[PGenNum-6] = {pG2P123Width[15:8],pG2P2Width};
  366. assign pgP2WidthArray[PGenNum-7] = {pG1P123Width[15:8],pG1P2Width};
  367. assign pgP3WidthArray[PGenNum-1] = {pG7P123Width[23:16],pG7P3Width};
  368. assign pgP3WidthArray[PGenNum-2] = {pG6P123Width[23:16],pG6P3Width};
  369. assign pgP3WidthArray[PGenNum-3] = {pG5P123Width[23:16],pG5P3Width};
  370. assign pgP3WidthArray[PGenNum-4] = {pG4P123Width[23:16],pG4P3Width};
  371. assign pgP3WidthArray[PGenNum-5] = {pG3P123Width[23:16],pG3P3Width};
  372. assign pgP3WidthArray[PGenNum-6] = {pG2P123Width[23:16],pG2P3Width};
  373. assign pgP3WidthArray[PGenNum-7] = {pG1P123Width[23:16],pG1P3Width};
  374. assign adcDataBus [ChNum-4] = adc1ChT1Data;
  375. assign adcDataBus [ChNum-3] = adc1ChR1Data;
  376. assign adcDataBus [ChNum-2] = adc2ChR2Data;
  377. assign adcDataBus [ChNum-1] = adc2ChT2Data;
  378. assign gainManual [ChNum-4] = gainCtrl[2];
  379. assign gainManual [ChNum-3] = gainCtrl[1];
  380. assign gainManual [ChNum-2] = gainCtrl[3];
  381. assign gainManual [ChNum-1] = gainCtrl[4];
  382. assign AdcInitMosi_o = adcInitMosi;
  383. assign AdcInitClk_o = adcInitSck;
  384. assign Adc1InitCs_o = adc0InitCs;
  385. assign Adc2InitCs_o = adc1InitCs;
  386. assign AdcInitRst_o = adcCtrl[0];
  387. assign Led_o = ledReg &(adc1ImT1|adc1ReT1|adc1ImR1|adc1ReR1|adc2ImT2|adc2ReT2|adc2ImR2|adc2ReR2);
  388. assign EndMeas_o = stopMeas|stopMeasR; //stretching pulse for 1 more clk period
  389. assign gainLowThresholdBus [ChNum-4] = gainLowThreshT1;
  390. assign gainLowThresholdBus [ChNum-3] = gainLowThreshR1;
  391. assign gainLowThresholdBus [ChNum-2] = gainLowThreshR2;
  392. assign gainLowThresholdBus [ChNum-1] = gainLowThreshT2;
  393. assign gainHighThresholdBus [ChNum-4] = gainHighThreshT1;
  394. assign gainHighThresholdBus [ChNum-3] = gainHighThreshR1;
  395. assign gainHighThresholdBus [ChNum-2] = gainHighThreshR2;
  396. assign gainHighThresholdBus [ChNum-1] = gainHighThreshT2;
  397. assign AmpEn_o [3] = ~ampEnNewStates[3];
  398. assign AmpEn_o [2] = ~ampEnNewStates[2];
  399. assign AmpEn_o [1] = ~ampEnNewStates[0];
  400. assign AmpEn_o [0] = ~ampEnNewStates[1];
  401. assign Overload_o = overCtrlR;
  402. assign SensEnS_io = (|sensEn)? 1'b0:1'bz;
  403. //================================================================================
  404. // CODING
  405. //================================================================================
  406. integer m;
  407. always @(posedge gclk) begin
  408. stopMeasR <= stopMeas;
  409. end
  410. always @(posedge gclk) begin
  411. sensEnReg <= SensEnS_io;
  412. end
  413. //--------------------------------------------------------------------------------
  414. // Data Receiving Interface
  415. //--------------------------------------------------------------------------------
  416. IBUF iob_50m_in
  417. (
  418. .I (Clk_i),
  419. .O (gclk)
  420. );
  421. Clk200Gen Clk200Gen
  422. (
  423. .Clk_i (gclk),
  424. .Rst_i (initRst),
  425. .Clk200_o (refClk),
  426. .Clk10Timers_o (TimersClk_o),
  427. .Clk100_o (Clk100),
  428. .Locked_o (Locked200)
  429. );
  430. AdcDataInterface
  431. #(
  432. .AdcDataWidth (AdcDataWidth),
  433. .ChNum (ChNum),
  434. .Ratio (Ratio)
  435. )
  436. AdcDataInterface
  437. (
  438. .Clk_i (gclk),
  439. .RefClk_i (refClk),
  440. .Locked_i (Locked200),
  441. .Rst_i (initRst),
  442. .Adc1FclkP_i (Adc1FclkP_i),
  443. .Adc1FclkN_i (Adc1FclkN_i),
  444. .Adc1DataDa0P_i (Adc1DataDa0P_i),
  445. .Adc1DataDa0N_i (Adc1DataDa0N_i),
  446. .Adc1DataDa1P_i (Adc1DataDa1P_i),
  447. .Adc1DataDa1N_i (Adc1DataDa1N_i),
  448. .Adc1DataDb0P_i (Adc1DataDb0P_i),
  449. .Adc1DataDb0N_i (Adc1DataDb0N_i),
  450. .Adc1DataDb1P_i (Adc1DataDb1P_i),
  451. .Adc1DataDb1N_i (Adc1DataDb1N_i),
  452. .Adc2FclkP_i (Adc2FclkP_i),
  453. .Adc2FclkN_i (Adc2FclkN_i),
  454. .Adc2DataDa0P_i (Adc2DataDa0P_i),
  455. .Adc2DataDa0N_i (Adc2DataDa0N_i),
  456. .Adc2DataDa1P_i (Adc2DataDa1P_i),
  457. .Adc2DataDa1N_i (Adc2DataDa1N_i),
  458. .Adc2DataDb0P_i (Adc2DataDb0P_i),
  459. .Adc2DataDb0N_i (Adc2DataDb0N_i),
  460. .Adc2DataDb1P_i (Adc2DataDb1P_i),
  461. .Adc2DataDb1N_i (Adc2DataDb1N_i),
  462. .Adc1ChT1Data_o (adc1ChT1Data),
  463. .Adc1ChR1Data_o (adc1ChR1Data),
  464. .Adc2ChR2Data_o (adc2ChR2Data),
  465. .Adc2ChT2Data_o (adc2ChT2Data)
  466. );
  467. //--------------------------------------------------------------------------------
  468. // External DSP Interface
  469. //--------------------------------------------------------------------------------
  470. DspInterface
  471. #(
  472. .ODataWidth (LpDataWidth),
  473. .ResultWidth (ResultWidth),
  474. .ChNum (ChNum),
  475. .CmdRegWidth (CmdRegWidth),
  476. .CmdDataRegWith (CmdDataRegWith),
  477. .HeaderWidth (HeaderWidth),
  478. .DataCntWidth (DataCntWidth)
  479. )
  480. ExternalDspInterface
  481. (
  482. .Clk_i (gclk),
  483. .Rst_i (initRst),
  484. .Mosi_i (Mosi_i),
  485. .Sck_i (Sck_i),
  486. .Ss_i (Ss_i),
  487. .Mosi_o (adcInitMosi),
  488. .Sck_o (adcInitSck),
  489. .Ss0_o (adc0InitCs),
  490. .Ss1_o (adc1InitCs),
  491. .Miso_i (Miso_i),
  492. .Miso_o (Miso_o),
  493. .CmdDataReg_o (cmdDataReg),
  494. .CmdDataVal_o (cmdDataVal),
  495. .AnsReg_i (ansReg),
  496. .AnsAddr_o (ansAddr),
  497. .LpOutFs_o (LpOutFs_o),
  498. .LpOutClk_o (LpOutClk_o),
  499. .LpOutData_o (LpOutData_o),
  500. .Adc1T1ImResult_i (adc1ImT1),
  501. .Adc1T1ReResult_i (adc1ReT1),
  502. .Adc1R1ImResult_i (adc1ImR1),
  503. .Adc1R1ReResult_i (adc1ReR1),
  504. .Adc2R2ImResult_i (adc2ImR2),
  505. .Adc2R2ReResult_i (adc2ReR2),
  506. .Adc2T2ImResult_i (adc2ImT2),
  507. .Adc2T2ReResult_i (adc2ReT2),
  508. .ServiseRegData_i (gainNewStates),
  509. .LpOutStart_i (measDataRdy)
  510. );
  511. //--------------------------------------------------------------------------------
  512. // Internal DSP calculation module
  513. //--------------------------------------------------------------------------------
  514. always @(posedge gclk) begin
  515. if (!initRst) begin
  516. startMeasSync <= StartMeasEvent_i;
  517. end else begin
  518. startMeasSync <= 1'b0;
  519. end
  520. end
  521. InternalDsp
  522. #(
  523. .AdcDataWidth (AdcDataWidth),
  524. .ChNum (ChNum),
  525. .ResultWidth (ResultWidth),
  526. .CmdDataRegWith (CmdDataRegWith)
  527. )
  528. InternalDsp
  529. (
  530. .Clk_i (gclk),
  531. .WindCalcClk_i (refClk),
  532. .Rst_i (initRst),
  533. .Adc1ChT1Data_i (adc1ChT1Data), //T1
  534. .Adc1ChR1Data_i (adc1ChR1Data), //R1
  535. .Adc2ChR2Data_i (adc2ChR2Data), //R2
  536. .Adc2ChT2Data_i (adc2ChT2Data), //T2
  537. // .Adc1ChT1Data_i (AdcData_i), //T1
  538. // .Adc1ChR1Data_i (AdcData_i), //R1
  539. // .Adc2ChR2Data_i (AdcData_i), //R2
  540. // .Adc2ChT2Data_i (AdcData_i), //T2
  541. .GatingPulse_i (gatingPulse),
  542. .StartMeasEvent_i (sampleStrobe),
  543. .StartMeasEvent_i (startMeasSync),
  544. .SensEnAll_i (sensEnNeg),
  545. .MeasNum_i ({measNum2[7:0],measNum1}),
  546. .MeasCtrl_i (measCtrl),
  547. .FilterCorrCoefH_i (filterCorrCoefH),
  548. .FilterCorrCoefL_i (filterCorrCoefL),
  549. .CalModeEn_i (adcCtrl[1]),
  550. .CalModeDone_o (calDone),
  551. .IfFtwL_i (ifFtwL),
  552. .IfFtwH_i (ifFtwH),
  553. .NcoSin_o (ncoSin),
  554. .NcoCos_o (ncoCos),
  555. .Adc1ImT1Data_o (adc1ImT1),
  556. .Adc1ReT1Data_o (adc1ReT1),
  557. .Adc1ImR1Data_o (adc1ImR1),
  558. .Adc1ReR1Data_o (adc1ReR1),
  559. .Adc2ImR2Data_o (adc2ImR2),
  560. .Adc2ReR2Data_o (adc2ReR2),
  561. .Adc2ImT2Data_o (adc2ImT2),
  562. .Adc2ReT2Data_o (adc2ReT2),
  563. .MeasDataRdy_o (measDataRdy),
  564. .EndMeas_o (stopMeas),
  565. .MeasWind_o (measWind),
  566. .MeasEnd_o (measEnd)
  567. );
  568. //--------------------------------------------------------------------------------
  569. // Reg Map With Config Registers
  570. //--------------------------------------------------------------------------------
  571. RegMap
  572. #(
  573. .CmdRegWidth (CmdRegWidth),
  574. .HeaderWidth (HeaderWidth),
  575. .CmdDataRegWith (CmdDataRegWith)
  576. )
  577. RegMapInst
  578. (
  579. .Clk_i (gclk),
  580. .Rst_i (initRst),
  581. .Val_i (cmdDataVal),
  582. .CalDone_i (calDone),
  583. .Data_i (cmdDataReg),
  584. .AnsAddr_i (ansAddr),
  585. .AnsDataReg_o (ansReg),
  586. .OverCtrlReg_i (overCtrl),
  587. .GainCtrlReg_o (gainCtrl),
  588. .GainLowThreshT1Reg_o (gainLowThreshT1),
  589. .GainHighThreshT1Reg_o (gainHighThreshT1),
  590. .GainLowThreshR1Reg_o (gainLowThreshR1),
  591. .GainHighThreshR1Reg_o (gainHighThreshR1),
  592. .GainLowThreshT2Reg_o (gainLowThreshT2),
  593. .GainHighThreshT2Reg_o (gainHighThreshT2),
  594. .GainLowThreshR2Reg_o (gainLowThreshR2),
  595. .GainHighThreshR2Reg_o (gainHighThreshR2),
  596. .OverThreshReg_o (overThresh),
  597. .DitherCtrlReg_o (ditherCtrl),
  598. .MeasCtrlReg_o (measCtrl),
  599. .AdcCtrlReg_o (adcCtrl),
  600. .AdcDirectRd0Reg_o (adcDirectRd0),
  601. .AdcDirectRd1Reg_o (adcDirectRd1),
  602. .IfFtwRegL_o (ifFtwL),
  603. .IfFtwRegH_o (ifFtwH),
  604. .FilterCorrCoefRegL_o (filterCorrCoefL),
  605. .FilterCorrCoefRegH_o (filterCorrCoefH),
  606. .DspTrigInReg_o (dspTrigIn),
  607. .DspTrigOutReg_o (dspTrigOut),
  608. .DspTrigIn1Reg_o (dspTrigIn1),
  609. .DspTrigIn2Reg_o (dspTrigIn2),
  610. .DspTrigOut1Reg_o (dspTrigOut1),
  611. .DspTrigOut2Reg_o (dspTrigOut2),
  612. .PG1P1DelayReg_o (pG1P1Del),
  613. .PG1P2DelayReg_o (pG1P2Del),
  614. .PG1P3DelayReg_o (pG1P3Del),
  615. .PG1P123DelayReg_o (pG1P123Del),
  616. .PG1P1WidthReg_o (pG1P1Width),
  617. .PG1P2WidthReg_o (pG1P2Width),
  618. .PG1P3WidthReg_o (pG1P3Width),
  619. .PG1P123WidthReg_o (pG1P123Width),
  620. //PG2 Regs
  621. .PG2P1DelayReg_o (pG2P1Del),
  622. .PG2P2DelayReg_o (pG2P2Del),
  623. .PG2P3DelayReg_o (pG2P3Del),
  624. .PG2P123DelayReg_o (pG2P123Del),
  625. .PG2P1WidthReg_o (pG2P1Width),
  626. .PG2P2WidthReg_o (pG2P2Width),
  627. .PG2P3WidthReg_o (pG2P3Width),
  628. .PG2P123WidthReg_o (pG2P123Width),
  629. //PG3 Regs
  630. .PG3P1DelayReg_o (pG3P1Del),
  631. .PG3P2DelayReg_o (pG3P2Del),
  632. .PG3P3DelayReg_o (pG3P3Del),
  633. .PG3P123DelayReg_o (pG3P123Del),
  634. .PG3P1WidthReg_o (pG3P1Width),
  635. .PG3P2WidthReg_o (pG3P2Width),
  636. .PG3P3WidthReg_o (pG3P3Width),
  637. .PG3P123WidthReg_o (pG3P123Width),
  638. //PG4 Regs
  639. .PG4P1DelayReg_o (pG4P1Del),
  640. .PG4P2DelayReg_o (pG4P2Del),
  641. .PG4P3DelayReg_o (pG4P3Del),
  642. .PG4P123DelayReg_o (pG4P123Del),
  643. .PG4P1WidthReg_o (pG4P1Width),
  644. .PG4P2WidthReg_o (pG4P2Width),
  645. .PG4P3WidthReg_o (pG4P3Width),
  646. .PG4P123WidthReg_o (pG4P123Width),
  647. //PG5 Regs
  648. .PG5P1DelayReg_o (pG5P1Del),
  649. .PG5P2DelayReg_o (pG5P2Del),
  650. .PG5P3DelayReg_o (pG5P3Del),
  651. .PG5P123DelayReg_o (pG5P123Del),
  652. .PG5P1WidthReg_o (pG5P1Width),
  653. .PG5P2WidthReg_o (pG5P2Width),
  654. .PG5P3WidthReg_o (pG5P3Width),
  655. .PG5P123WidthReg_o (pG5P123Width),
  656. //PG6 Regs
  657. .PG6P1DelayReg_o (pG6P1Del),
  658. .PG6P2DelayReg_o (pG6P2Del),
  659. .PG6P3DelayReg_o (pG6P3Del),
  660. .PG6P123DelayReg_o (pG6P123Del),
  661. .PG6P1WidthReg_o (pG6P1Width),
  662. .PG6P2WidthReg_o (pG6P2Width),
  663. .PG6P3WidthReg_o (pG6P3Width),
  664. .PG6P123WidthReg_o (pG6P123Width),
  665. //PG7 Regs
  666. .PG7P1DelayReg_o (pG7P1Del),
  667. .PG7P2DelayReg_o (pG7P2Del),
  668. .PG7P3DelayReg_o (pG7P3Del),
  669. .PG7P123DelayReg_o (pG7P123Del),
  670. .PG7P1WidthReg_o (pG7P1Width),
  671. .PG7P2WidthReg_o (pG7P2Width),
  672. .PG7P3WidthReg_o (pG7P3Width),
  673. .PG7P123WidthReg_o (pG7P123Width),
  674. .MeasNum1Reg_o (measNum1),
  675. .MeasNum2Reg_o (measNum2),
  676. .PgMode0Reg_o (pgMode0),
  677. .PgMode1Reg_o (pgMode1),
  678. .MuxCtrl1Reg_o (muxCtrl1),
  679. .MuxCtrl2Reg_o (muxCtrl2),
  680. .MuxCtrl3Reg_o (muxCtrl3)
  681. );
  682. //--------------------------------------------------------------------------------
  683. // Global FPGA reset generator
  684. //--------------------------------------------------------------------------------
  685. InitRst FpgaInitRst
  686. (
  687. .clk_i (gclk),
  688. .signal_o (initRst)
  689. );
  690. //--------------------------------------------------------------------------------
  691. // ADC overload detection
  692. //--------------------------------------------------------------------------------
  693. genvar i;
  694. generate
  695. for (i=0; i<ChNum; i=i+1) begin :OverControl
  696. OverloadDetect
  697. #(
  698. .ThresholdWidth (ThresholdWidth),
  699. .AdcDataWidth (AdcDataWidth),
  700. .MeasPeriod (MeasPeriod)
  701. )
  702. OverloadDetect
  703. (
  704. .Rst_i (initRst),
  705. .Clk_i (gclk),
  706. .AdcData_i (adcDataBus[i]),
  707. .OverThreshold_i (overThresh),
  708. .Overload_o (overCtrlChannels[i])
  709. );
  710. end
  711. endgenerate
  712. //--------------------------------------------------------------------------------
  713. // Gain Control module
  714. //--------------------------------------------------------------------------------
  715. genvar g;
  716. generate
  717. for (g=0; g<ChNum; g=g+1) begin :GainControl
  718. GainControlWrapper
  719. #(
  720. .AdcDataWidth (AdcDataWidth),
  721. .ThresholdWidth (ThresholdWidth),
  722. .PhIncWidth (PhIncWidth),
  723. .IfNcoOutWidth (NcoWidth),
  724. .MeasPeriod (MeasPeriod)
  725. )
  726. GainControlModule
  727. (
  728. .Rst_i (initRst),
  729. .Clk_i (gclk),
  730. .MeasWind_i (measWind),
  731. .NcoSin_i (ncoSin),
  732. .NcoCos_i (ncoCos),
  733. .AdcData_i (adcDataBus[g]),
  734. // .AdcData_i (AdcData_i),
  735. .GainLowThreshold_i (gainLowThresholdBus[g]),
  736. .GainHighThreshold_i(gainHighThresholdBus[g]),
  737. .GainAutoEn_i (gainCtrl[0]),
  738. .GainManualState_i (gainManual[g]),
  739. .AmpEnNewState_o (ampEnNewStates[g]),
  740. .SensEn_o (sensEn[g])
  741. );
  742. end
  743. endgenerate
  744. //--------------------------------------------------------------------------------
  745. // Dither Gen
  746. //--------------------------------------------------------------------------------
  747. DitherGenv2 DitherGenInst
  748. (
  749. .Rst_i (initRst),
  750. .Clk_i (gclk),
  751. .DitherCmd_i (ditherCtrl),
  752. .DitherCtrlT2R2_o (DitherCtrlCh1_o),
  753. .DitherCtrlT1R1_o (DitherCtrlCh2_o)
  754. );
  755. //--------------------------------------------------------------------------------
  756. // Pulse Meas modules
  757. //--------------------------------------------------------------------------------
  758. //--------------------------------------------------------------------------------
  759. // Pulse Gens
  760. //--------------------------------------------------------------------------------
  761. genvar j;
  762. generate
  763. for (j=0; j<PGenNum; j=j+1) begin :PGen
  764. Mux
  765. #(
  766. .CmdRegWidth (CmdRegWidth),
  767. .PGenNum (PGenNum),
  768. .TrigPortsNum (TrigPortsNum)
  769. )
  770. PulseGenMux
  771. (
  772. .Rst_i (initRst),
  773. .MuxCtrl_i (pgMuxCtrlArray[j]),
  774. .DspTrigOut_i (1'b0),
  775. .DspStartCmd_i (1'b0),
  776. .IntTrig_i (StartMeasEvent_i),
  777. .PulseBus_i (pulseBus),
  778. .ExtPortsBus_i (),
  779. .MuxOut_o (pgMuxedOut[j])
  780. );
  781. PulseGen
  782. #(
  783. .CmdRegWidth (CmdRegWidth)
  784. )
  785. PulseGenerator
  786. (
  787. .Rst_i (initRst|pGensRst),
  788. .Clk_i (gclk),
  789. .EnPulse_i (pgMuxedOut[j]),
  790. .PulsePol_i (pgPulsePolArray[j]),
  791. .EnEdge_i (pgEnEdgeArray[j]),
  792. .Mode_i (pgModeArray[j]),
  793. .P1Del_i (pgP1DelArray[j]),
  794. .P2Del_i (pgP2DelArray[j]),
  795. .P3Del_i (pgP3DelArray[j]),
  796. .P1Width_i (pgP1WidthArray[j]),
  797. .P2Width_i (pgP2WidthArray[j]),
  798. .P3Width_i (pgP3WidthArray[j]),
  799. .Pulse_o (pulseBus[j])
  800. );
  801. end
  802. endgenerate
  803. //--------------------------------------------------------------------------------
  804. // Software Gating
  805. //--------------------------------------------------------------------------------
  806. Mux
  807. #(
  808. .CmdRegWidth (CmdRegWidth),
  809. .PGenNum (PGenNum),
  810. .TrigPortsNum (TrigPortsNum)
  811. )
  812. GatingMux
  813. (
  814. .Rst_i (initRst),
  815. .MuxCtrl_i (muxCtrl2[15:12]),
  816. .DspTrigOut_i (1'b0),
  817. .DspStartCmd_i (1'b0),
  818. .IntTrig_i (1'b0),
  819. .PulseBus_i (pulseBus),
  820. .ExtPortsBus_i (),
  821. .MuxOut_o (gatingPulse)
  822. );
  823. //--------------------------------------------------------------------------------
  824. // Mod Out Muxer
  825. //--------------------------------------------------------------------------------
  826. Mux
  827. #(
  828. .CmdRegWidth (CmdRegWidth),
  829. .PGenNum (PGenNum),
  830. .TrigPortsNum (TrigPortsNum)
  831. )
  832. SampleStrobeMux
  833. (
  834. .Rst_i (initRst),
  835. .MuxCtrl_i (muxCtrl2[19:16]),
  836. .DspTrigOut_i (1'b0),
  837. .DspStartCmd_i (1'b0),
  838. .IntTrig_i (1'b0),
  839. .PulseBus_i (pulseBus),
  840. .ExtPortsBus_i (),
  841. .MuxOut_o (sampleStrobe)
  842. );
  843. //--------------------------------------------------------------------------------
  844. // Debug led
  845. //--------------------------------------------------------------------------------
  846. always @(posedge gclk) begin
  847. if (initRst) begin
  848. testCnt <= 32'b0;
  849. end else if (testCnt != TESTCNTPARAM) begin
  850. testCnt <= testCnt+1;
  851. end else begin
  852. testCnt <= 32'd0;
  853. end
  854. end
  855. always @(posedge gclk) begin
  856. if (initRst) begin
  857. ledReg <= 1'b0;
  858. end else if ((testCnt == TESTCNTPARAM-1)) begin
  859. ledReg <= ~ledReg;
  860. end
  861. end
  862. endmodule