Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 58.52 KB | None | 0 0
  1.  
  2.  
  3. module DE1_SoC_Computer (
  4.     ////////////////////////////////////
  5.     // FPGA Pins
  6.     ////////////////////////////////////
  7.  
  8.     // Clock pins
  9.     CLOCK_50,
  10.     CLOCK2_50,
  11.     CLOCK3_50,
  12.     CLOCK4_50,
  13.  
  14.     // ADC
  15.     ADC_CS_N,
  16.     ADC_DIN,
  17.     ADC_DOUT,
  18.     ADC_SCLK,
  19.  
  20.     // Audio
  21.     AUD_ADCDAT,
  22.     AUD_ADCLRCK,
  23.     AUD_BCLK,
  24.     AUD_DACDAT,
  25.     AUD_DACLRCK,
  26.     AUD_XCK,
  27.  
  28.     // SDRAM
  29.     DRAM_ADDR,
  30.     DRAM_BA,
  31.     DRAM_CAS_N,
  32.     DRAM_CKE,
  33.     DRAM_CLK,
  34.     DRAM_CS_N,
  35.     DRAM_DQ,
  36.     DRAM_LDQM,
  37.     DRAM_RAS_N,
  38.     DRAM_UDQM,
  39.     DRAM_WE_N,
  40.  
  41.     // I2C Bus for Configuration of the Audio and Video-In Chips
  42.     FPGA_I2C_SCLK,
  43.     FPGA_I2C_SDAT,
  44.  
  45.     // 40-Pin Headers
  46.     GPIO_0,
  47.     GPIO_1,
  48.    
  49.     // Seven Segment Displays
  50.     HEX0,
  51.     HEX1,
  52.     HEX2,
  53.     HEX3,
  54.     HEX4,
  55.     HEX5,
  56.  
  57.     // IR
  58.     IRDA_RXD,
  59.     IRDA_TXD,
  60.  
  61.     // Pushbuttons
  62.     KEY,
  63.  
  64.     // LEDs
  65.     LEDR,
  66.  
  67.     // PS2 Ports
  68.     PS2_CLK,
  69.     PS2_DAT,
  70.    
  71.     PS2_CLK2,
  72.     PS2_DAT2,
  73.  
  74.     // Slider Switches
  75.     SW,
  76.  
  77.     // Video-In
  78.     TD_CLK27,
  79.     TD_DATA,
  80.     TD_HS,
  81.     TD_RESET_N,
  82.     TD_VS,
  83.  
  84.     // VGA
  85.     VGA_B,
  86.     VGA_BLANK_N,
  87.     VGA_CLK,
  88.     VGA_G,
  89.     VGA_HS,
  90.     VGA_R,
  91.     VGA_SYNC_N,
  92.     VGA_VS,
  93.  
  94.     ////////////////////////////////////
  95.     // HPS Pins
  96.     ////////////////////////////////////
  97.    
  98.     // DDR3 SDRAM
  99.     HPS_DDR3_ADDR,
  100.     HPS_DDR3_BA,
  101.     HPS_DDR3_CAS_N,
  102.     HPS_DDR3_CKE,
  103.     HPS_DDR3_CK_N,
  104.     HPS_DDR3_CK_P,
  105.     HPS_DDR3_CS_N,
  106.     HPS_DDR3_DM,
  107.     HPS_DDR3_DQ,
  108.     HPS_DDR3_DQS_N,
  109.     HPS_DDR3_DQS_P,
  110.     HPS_DDR3_ODT,
  111.     HPS_DDR3_RAS_N,
  112.     HPS_DDR3_RESET_N,
  113.     HPS_DDR3_RZQ,
  114.     HPS_DDR3_WE_N,
  115.  
  116.     // Ethernet
  117.     HPS_ENET_GTX_CLK,
  118.     HPS_ENET_INT_N,
  119.     HPS_ENET_MDC,
  120.     HPS_ENET_MDIO,
  121.     HPS_ENET_RX_CLK,
  122.     HPS_ENET_RX_DATA,
  123.     HPS_ENET_RX_DV,
  124.     HPS_ENET_TX_DATA,
  125.     HPS_ENET_TX_EN,
  126.  
  127.     // Flash
  128.     HPS_FLASH_DATA,
  129.     HPS_FLASH_DCLK,
  130.     HPS_FLASH_NCSO,
  131.  
  132.     // Accelerometer
  133.     HPS_GSENSOR_INT,
  134.        
  135.     // General Purpose I/O
  136.     HPS_GPIO,
  137.        
  138.     // I2C
  139.     HPS_I2C_CONTROL,
  140.     HPS_I2C1_SCLK,
  141.     HPS_I2C1_SDAT,
  142.     HPS_I2C2_SCLK,
  143.     HPS_I2C2_SDAT,
  144.  
  145.     // Pushbutton
  146.     HPS_KEY,
  147.  
  148.     // LED
  149.     HPS_LED,
  150.        
  151.     // SD Card
  152.     HPS_SD_CLK,
  153.     HPS_SD_CMD,
  154.     HPS_SD_DATA,
  155.  
  156.     // SPI
  157.     HPS_SPIM_CLK,
  158.     HPS_SPIM_MISO,
  159.     HPS_SPIM_MOSI,
  160.     HPS_SPIM_SS,
  161.  
  162.     // UART
  163.     HPS_UART_RX,
  164.     HPS_UART_TX,
  165.  
  166.     // USB
  167.     HPS_CONV_USB_N,
  168.     HPS_USB_CLKOUT,
  169.     HPS_USB_DATA,
  170.     HPS_USB_DIR,
  171.     HPS_USB_NXT,
  172.     HPS_USB_STP
  173. );
  174.  
  175. //=======================================================
  176. //  PARAMETER declarations
  177. //=======================================================
  178.  
  179.  
  180. //=======================================================
  181. //  PORT declarations
  182. //=======================================================
  183.  
  184. ////////////////////////////////////
  185. // FPGA Pins
  186. ////////////////////////////////////
  187.  
  188. // Clock pins
  189. input                       CLOCK_50;
  190. input                       CLOCK2_50;
  191. input                       CLOCK3_50;
  192. input                       CLOCK4_50;
  193.  
  194. // ADC
  195. inout                       ADC_CS_N;
  196. output                  ADC_DIN;
  197. input                       ADC_DOUT;
  198. output                  ADC_SCLK;
  199.  
  200. // Audio
  201. input                       AUD_ADCDAT;
  202. inout                       AUD_ADCLRCK;
  203. inout                       AUD_BCLK;
  204. output                  AUD_DACDAT;
  205. inout                       AUD_DACLRCK;
  206. output                  AUD_XCK;
  207.  
  208. // SDRAM
  209. output      [12: 0] DRAM_ADDR;
  210. output      [ 1: 0] DRAM_BA;
  211. output                  DRAM_CAS_N;
  212. output                  DRAM_CKE;
  213. output                  DRAM_CLK;
  214. output                  DRAM_CS_N;
  215. inout           [15: 0] DRAM_DQ;
  216. output                  DRAM_LDQM;
  217. output                  DRAM_RAS_N;
  218. output                  DRAM_UDQM;
  219. output                  DRAM_WE_N;
  220.  
  221. // I2C Bus for Configuration of the Audio and Video-In Chips
  222. output                  FPGA_I2C_SCLK;
  223. inout                       FPGA_I2C_SDAT;
  224.  
  225. // 40-pin headers
  226. inout           [35: 0] GPIO_0;
  227. inout           [35: 0] GPIO_1;
  228.  
  229. // Seven Segment Displays
  230. output      [ 6: 0] HEX0;
  231. output      [ 6: 0] HEX1;
  232. output      [ 6: 0] HEX2;
  233. output      [ 6: 0] HEX3;
  234. output      [ 6: 0] HEX4;
  235. output      [ 6: 0] HEX5;
  236.  
  237. // IR
  238. input                       IRDA_RXD;
  239. output                  IRDA_TXD;
  240.  
  241. // Pushbuttons
  242. input           [ 3: 0] KEY;
  243.  
  244. // LEDs
  245. output      [ 9: 0] LEDR;
  246.  
  247. // PS2 Ports
  248. inout                       PS2_CLK;
  249. inout                       PS2_DAT;
  250.  
  251. inout                       PS2_CLK2;
  252. inout                       PS2_DAT2;
  253.  
  254. // Slider Switches
  255. input           [ 9: 0] SW;
  256.  
  257. // Video-In
  258. input                       TD_CLK27;
  259. input           [ 7: 0] TD_DATA;
  260. input                       TD_HS;
  261. output                  TD_RESET_N;
  262. input                       TD_VS;
  263.  
  264. // VGA
  265. output      [ 7: 0] VGA_B;
  266. output                  VGA_BLANK_N;
  267. output                  VGA_CLK;
  268. output      [ 7: 0] VGA_G;
  269. output                  VGA_HS;
  270. output      [ 7: 0] VGA_R;
  271. output                  VGA_SYNC_N;
  272. output                  VGA_VS;
  273.  
  274.  
  275.  
  276. ////////////////////////////////////
  277. // HPS Pins
  278. ////////////////////////////////////
  279.    
  280. // DDR3 SDRAM
  281. output      [14: 0] HPS_DDR3_ADDR;
  282. output      [ 2: 0]  HPS_DDR3_BA;
  283. output                  HPS_DDR3_CAS_N;
  284. output                  HPS_DDR3_CKE;
  285. output                  HPS_DDR3_CK_N;
  286. output                  HPS_DDR3_CK_P;
  287. output                  HPS_DDR3_CS_N;
  288. output      [ 3: 0] HPS_DDR3_DM;
  289. inout           [31: 0] HPS_DDR3_DQ;
  290. inout           [ 3: 0] HPS_DDR3_DQS_N;
  291. inout           [ 3: 0] HPS_DDR3_DQS_P;
  292. output                  HPS_DDR3_ODT;
  293. output                  HPS_DDR3_RAS_N;
  294. output                  HPS_DDR3_RESET_N;
  295. input                       HPS_DDR3_RZQ;
  296. output                  HPS_DDR3_WE_N;
  297.  
  298. // Ethernet
  299. output                  HPS_ENET_GTX_CLK;
  300. inout                       HPS_ENET_INT_N;
  301. output                  HPS_ENET_MDC;
  302. inout                       HPS_ENET_MDIO;
  303. input                       HPS_ENET_RX_CLK;
  304. input           [ 3: 0] HPS_ENET_RX_DATA;
  305. input                       HPS_ENET_RX_DV;
  306. output      [ 3: 0] HPS_ENET_TX_DATA;
  307. output                  HPS_ENET_TX_EN;
  308.  
  309. // Flash
  310. inout           [ 3: 0] HPS_FLASH_DATA;
  311. output                  HPS_FLASH_DCLK;
  312. output                  HPS_FLASH_NCSO;
  313.  
  314. // Accelerometer
  315. inout                       HPS_GSENSOR_INT;
  316.  
  317. // General Purpose I/O
  318. inout           [ 1: 0] HPS_GPIO;
  319.  
  320. // I2C
  321. inout                       HPS_I2C_CONTROL;
  322. inout                       HPS_I2C1_SCLK;
  323. inout                       HPS_I2C1_SDAT;
  324. inout                       HPS_I2C2_SCLK;
  325. inout                       HPS_I2C2_SDAT;
  326.  
  327. // Pushbutton
  328. inout                       HPS_KEY;
  329.  
  330. // LED
  331. inout                       HPS_LED;
  332.  
  333. // SD Card
  334. output                  HPS_SD_CLK;
  335. inout                       HPS_SD_CMD;
  336. inout           [ 3: 0] HPS_SD_DATA;
  337.  
  338. // SPI
  339. output                  HPS_SPIM_CLK;
  340. input                       HPS_SPIM_MISO;
  341. output                  HPS_SPIM_MOSI;
  342. inout                       HPS_SPIM_SS;
  343.  
  344. // UART
  345. input                       HPS_UART_RX;
  346. output                  HPS_UART_TX;
  347.  
  348. // USB
  349. inout                       HPS_CONV_USB_N;
  350. input                       HPS_USB_CLKOUT;
  351. inout           [ 7: 0] HPS_USB_DATA;
  352. input                       HPS_USB_DIR;
  353. input                       HPS_USB_NXT;
  354. output                  HPS_USB_STP;
  355.  
  356. //=======================================================
  357. //  REG/WIRE declarations
  358. //=======================================================
  359.  
  360. HexDigit Digit0(HEX0, mid_out[3:0]);
  361. HexDigit Digit1(HEX1, mid_out[7:4]);
  362. HexDigit Digit2(HEX2, mid_out[11:8]);
  363. HexDigit Digit3(HEX3, mid_out[15:12]);
  364. HexDigit Digit4(HEX4, {2'b0,mid_out[17:16]});
  365.  
  366. //=======================================================
  367. // Bus controller for AVALON bus-master
  368. //=======================================================
  369. // computes DDS for sine wave and fills audio FIFO
  370.  
  371. reg [31:0] bus_addr ; // Avalon address
  372. // see
  373. // ftp://ftp.altera.com/up/pub/Altera_Material/15.1/University_Program_IP_Cores/Audio_Video/Audio.pdf
  374. // for addresses
  375. wire [31:0] audio_base_address = 32'h00003040 ;  // Avalon address
  376. wire [31:0] audio_fifo_address = 32'h00003044 ;  // Avalon address +4 offset
  377. wire [31:0] audio_left_address = 32'h00003048 ;  // Avalon address +8
  378. wire [31:0] audio_right_address = 32'h0000304c ;  // Avalon address +12
  379. reg [3:0] bus_byte_enable ; // four bit byte read/write mask
  380. reg bus_read  ;       // high when requesting data
  381. reg bus_write ;      //  high when writing data
  382. reg [31:0] bus_write_data ; //  data to send to Avalog bus
  383. wire bus_ack  ;       //  Avalon bus raises this when done
  384. wire [31:0] bus_read_data ; // data from Avalon bus
  385. reg [30:0] timer ;
  386. reg [3:0] state ;
  387. wire state_clock ;
  388.  
  389. // current free words in audio interface
  390. reg [7:0] fifo_space ;
  391.  
  392. //Stuff we added
  393. reg start; //control signal for columns to calculate 1 time step
  394. wire signed[17:0]  mid_out; //output of the middle node of the drum, the sound
  395.  
  396. always @(posedge CLOCK_50) begin //CLOCK_50
  397.  
  398.     // reset state machine and read/write controls
  399.     if (~KEY[0]) begin
  400.         state <= 0 ;
  401.         bus_read <= 0 ; // set to one if a read opeation from bus
  402.         bus_write <= 0 ; // set to one if a write operation to bus
  403.         timer <= 0;
  404.         start <= 0;
  405.     end
  406.     else begin
  407.         // timer just for deubgging
  408.         timer <= timer + 1;
  409.     end
  410.    
  411.     // set up read FIFO available space
  412.     if (state==4'd0) begin
  413.         bus_addr <= audio_fifo_address ;
  414.         bus_read <= 1'b1 ;
  415.         bus_byte_enable <= 4'b1111;
  416.         state <= 4'd1 ; // wait for read ACK
  417.     end
  418.    
  419.     // wait for read ACK and read the fifo available
  420.     // bus ACK is high when data is available
  421.     if (state==4'd1 && bus_ack==1) begin
  422.         state <= 4'd2 ; //4'd2
  423.         // FIFO space is in high byte
  424.         fifo_space <= (bus_read_data>>24) ;
  425.         // end the read
  426.         bus_read <= 1'b0 ;
  427.     end
  428.    
  429.     // When there is room in the FIFO
  430.     // -- set start high to begin computation of next time step
  431.     // -- start write to fifo for each channel
  432.     // -- first the left channel
  433.     if (state==4'd2 && fifo_space>8'd2) begin //
  434.         state <= 4'd3; 
  435.         start <= 1'b1;
  436.         bus_write_data <= (mid_out << 14) ;
  437.         bus_addr <= audio_left_address ;
  438.         bus_byte_enable <= 4'b1111;
  439.         bus_write <= 1'b1 ;
  440.     end
  441.     // if no space, try again later
  442.     else if (state==4'd2 && fifo_space<=8'd2) begin
  443.         state <= 4'b0 ;
  444.     end
  445.    
  446.     // detect bus-transaction-complete ACK
  447.     // for left channel write
  448.     // You MUST do this check
  449.     if (state==4'd3 && bus_ack==1) begin
  450.         state <= 4'd4 ;
  451.         bus_write <= 0;
  452.         start <= 1'b0;
  453.     end
  454.    
  455.     // -- now the right channel
  456.     if (state==4'd4) begin //
  457.         state <= 4'd5; 
  458.         bus_addr <= audio_right_address ;
  459.         bus_write <= 1'b1 ;
  460.     end
  461.    
  462.     // detect bus-transaction-complete ACK
  463.     // for right channel write
  464.     // You MUST do this check
  465.     if (state==4'd5 && bus_ack==1) begin
  466.         state <= 4'd0 ;
  467.         bus_write <= 0;
  468.     end
  469.    
  470. end // always @(posedge state_clock)
  471.  
  472. maker m(.CLOCK_50(CLOCK_50),
  473.           .reset(KEY[0]),
  474.           .start(start),
  475.           .sound(mid_out),
  476.           .sw(SW[9:0]));
  477. //=======================================================
  478. //  Structural coding
  479. //=======================================================
  480.  
  481.  
  482. Computer_System The_System (
  483.     ////////////////////////////////////
  484.     // FPGA Side
  485.     ////////////////////////////////////
  486.  
  487.     // Global signals
  488.     .system_pll_ref_clk_clk                 (CLOCK_50),
  489.     .system_pll_ref_reset_reset         (1'b0),
  490.     .sdram_clk_clk                              (state_clock),
  491.  
  492.     // AV Config
  493.     .av_config_SCLK                         (FPGA_I2C_SCLK),
  494.     .av_config_SDAT                         (FPGA_I2C_SDAT),
  495.  
  496.     // Audio Subsystem
  497.     .audio_pll_ref_clk_clk                  (CLOCK3_50),
  498.     .audio_pll_ref_reset_reset              (1'b0),
  499.     .audio_clk_clk                              (AUD_XCK),
  500.     .audio_ADCDAT                               (AUD_ADCDAT),
  501.     .audio_ADCLRCK                              (AUD_ADCLRCK),
  502.     .audio_BCLK                                 (AUD_BCLK),
  503.     .audio_DACDAT                               (AUD_DACDAT),
  504.     .audio_DACLRCK                              (AUD_DACLRCK),
  505.  
  506.     // bus-master state machine interface
  507.     .bus_master_audio_external_interface_address     (bus_addr),    
  508.     .bus_master_audio_external_interface_byte_enable (bus_byte_enable),
  509.     .bus_master_audio_external_interface_read        (bus_read),        
  510.     .bus_master_audio_external_interface_write       (bus_write),      
  511.     .bus_master_audio_external_interface_write_data  (bus_write_data),  
  512.     .bus_master_audio_external_interface_acknowledge (bus_ack),                                  
  513.     .bus_master_audio_external_interface_read_data   (bus_read_data),  
  514.    
  515.    
  516.     ////////////////////////////////////
  517.     // HPS Side
  518.     ////////////////////////////////////
  519.     // DDR3 SDRAM
  520.     .memory_mem_a           (HPS_DDR3_ADDR),
  521.     .memory_mem_ba          (HPS_DDR3_BA),
  522.     .memory_mem_ck          (HPS_DDR3_CK_P),
  523.     .memory_mem_ck_n        (HPS_DDR3_CK_N),
  524.     .memory_mem_cke     (HPS_DDR3_CKE),
  525.     .memory_mem_cs_n        (HPS_DDR3_CS_N),
  526.     .memory_mem_ras_n       (HPS_DDR3_RAS_N),
  527.     .memory_mem_cas_n       (HPS_DDR3_CAS_N),
  528.     .memory_mem_we_n        (HPS_DDR3_WE_N),
  529.     .memory_mem_reset_n (HPS_DDR3_RESET_N),
  530.     .memory_mem_dq          (HPS_DDR3_DQ),
  531.     .memory_mem_dqs     (HPS_DDR3_DQS_P),
  532.     .memory_mem_dqs_n       (HPS_DDR3_DQS_N),
  533.     .memory_mem_odt     (HPS_DDR3_ODT),
  534.     .memory_mem_dm          (HPS_DDR3_DM),
  535.     .memory_oct_rzqin       (HPS_DDR3_RZQ),
  536.          
  537.     // Ethernet
  538.     .hps_io_hps_io_gpio_inst_GPIO35 (HPS_ENET_INT_N),
  539.     .hps_io_hps_io_emac1_inst_TX_CLK    (HPS_ENET_GTX_CLK),
  540.     .hps_io_hps_io_emac1_inst_TXD0  (HPS_ENET_TX_DATA[0]),
  541.     .hps_io_hps_io_emac1_inst_TXD1  (HPS_ENET_TX_DATA[1]),
  542.     .hps_io_hps_io_emac1_inst_TXD2  (HPS_ENET_TX_DATA[2]),
  543.     .hps_io_hps_io_emac1_inst_TXD3  (HPS_ENET_TX_DATA[3]),
  544.     .hps_io_hps_io_emac1_inst_RXD0  (HPS_ENET_RX_DATA[0]),
  545.     .hps_io_hps_io_emac1_inst_MDIO  (HPS_ENET_MDIO),
  546.     .hps_io_hps_io_emac1_inst_MDC       (HPS_ENET_MDC),
  547.     .hps_io_hps_io_emac1_inst_RX_CTL    (HPS_ENET_RX_DV),
  548.     .hps_io_hps_io_emac1_inst_TX_CTL    (HPS_ENET_TX_EN),
  549.     .hps_io_hps_io_emac1_inst_RX_CLK    (HPS_ENET_RX_CLK),
  550.     .hps_io_hps_io_emac1_inst_RXD1  (HPS_ENET_RX_DATA[1]),
  551.     .hps_io_hps_io_emac1_inst_RXD2  (HPS_ENET_RX_DATA[2]),
  552.     .hps_io_hps_io_emac1_inst_RXD3  (HPS_ENET_RX_DATA[3]),
  553.  
  554.     // Flash
  555.     .hps_io_hps_io_qspi_inst_IO0    (HPS_FLASH_DATA[0]),
  556.     .hps_io_hps_io_qspi_inst_IO1    (HPS_FLASH_DATA[1]),
  557.     .hps_io_hps_io_qspi_inst_IO2    (HPS_FLASH_DATA[2]),
  558.     .hps_io_hps_io_qspi_inst_IO3    (HPS_FLASH_DATA[3]),
  559.     .hps_io_hps_io_qspi_inst_SS0    (HPS_FLASH_NCSO),
  560.     .hps_io_hps_io_qspi_inst_CLK    (HPS_FLASH_DCLK),
  561.  
  562.     // Accelerometer
  563.     .hps_io_hps_io_gpio_inst_GPIO61 (HPS_GSENSOR_INT),
  564.  
  565.     //.adc_sclk                        (ADC_SCLK),
  566.     //.adc_cs_n                        (ADC_CS_N),
  567.     //.adc_dout                        (ADC_DOUT),
  568.     //.adc_din                         (ADC_DIN),
  569.  
  570.     // General Purpose I/O
  571.     .hps_io_hps_io_gpio_inst_GPIO40 (HPS_GPIO[0]),
  572.     .hps_io_hps_io_gpio_inst_GPIO41 (HPS_GPIO[1]),
  573.  
  574.     // I2C
  575.     .hps_io_hps_io_gpio_inst_GPIO48 (HPS_I2C_CONTROL),
  576.     .hps_io_hps_io_i2c0_inst_SDA        (HPS_I2C1_SDAT),
  577.     .hps_io_hps_io_i2c0_inst_SCL        (HPS_I2C1_SCLK),
  578.     .hps_io_hps_io_i2c1_inst_SDA        (HPS_I2C2_SDAT),
  579.     .hps_io_hps_io_i2c1_inst_SCL        (HPS_I2C2_SCLK),
  580.  
  581.     // Pushbutton
  582.     .hps_io_hps_io_gpio_inst_GPIO54 (HPS_KEY),
  583.  
  584.     // LED
  585.     .hps_io_hps_io_gpio_inst_GPIO53 (HPS_LED),
  586.  
  587.     // SD Card
  588.     .hps_io_hps_io_sdio_inst_CMD    (HPS_SD_CMD),
  589.     .hps_io_hps_io_sdio_inst_D0 (HPS_SD_DATA[0]),
  590.     .hps_io_hps_io_sdio_inst_D1 (HPS_SD_DATA[1]),
  591.     .hps_io_hps_io_sdio_inst_CLK    (HPS_SD_CLK),
  592.     .hps_io_hps_io_sdio_inst_D2 (HPS_SD_DATA[2]),
  593.     .hps_io_hps_io_sdio_inst_D3 (HPS_SD_DATA[3]),
  594.  
  595.     // SPI
  596.     .hps_io_hps_io_spim1_inst_CLK       (HPS_SPIM_CLK),
  597.     .hps_io_hps_io_spim1_inst_MOSI  (HPS_SPIM_MOSI),
  598.     .hps_io_hps_io_spim1_inst_MISO  (HPS_SPIM_MISO),
  599.     .hps_io_hps_io_spim1_inst_SS0       (HPS_SPIM_SS),
  600.  
  601.     // UART
  602.     .hps_io_hps_io_uart0_inst_RX    (HPS_UART_RX),
  603.     .hps_io_hps_io_uart0_inst_TX    (HPS_UART_TX),
  604.  
  605.     // USB
  606.     .hps_io_hps_io_gpio_inst_GPIO09 (HPS_CONV_USB_N),
  607.     .hps_io_hps_io_usb1_inst_D0     (HPS_USB_DATA[0]),
  608.     .hps_io_hps_io_usb1_inst_D1     (HPS_USB_DATA[1]),
  609.     .hps_io_hps_io_usb1_inst_D2     (HPS_USB_DATA[2]),
  610.     .hps_io_hps_io_usb1_inst_D3     (HPS_USB_DATA[3]),
  611.     .hps_io_hps_io_usb1_inst_D4     (HPS_USB_DATA[4]),
  612.     .hps_io_hps_io_usb1_inst_D5     (HPS_USB_DATA[5]),
  613.     .hps_io_hps_io_usb1_inst_D6     (HPS_USB_DATA[6]),
  614.     .hps_io_hps_io_usb1_inst_D7     (HPS_USB_DATA[7]),
  615.     .hps_io_hps_io_usb1_inst_CLK        (HPS_USB_CLKOUT),
  616.     .hps_io_hps_io_usb1_inst_STP        (HPS_USB_STP),
  617.     .hps_io_hps_io_usb1_inst_DIR        (HPS_USB_DIR),
  618.     .hps_io_hps_io_usb1_inst_NXT        (HPS_USB_NXT)
  619. );
  620.  
  621.  
  622. endmodule
  623.  
  624. //module that generates the columns and connections between them
  625. //provides clock, reset, and start to the column modules and reads output of middle node from middle column
  626. module maker(
  627.     input CLOCK_50, reset, start,
  628.     input [9:0] sw,
  629.     output [17:0] sound
  630. );
  631.     parameter n = 170; // number of columns
  632.     parameter column_size = 500; // number of rows
  633.  
  634. //set various parameters of the wave equation using the switches on the FPGA
  635.     wire[1:0] gain; // left shift by gain in rho equation
  636.     assign gain = sw[8:7];
  637.     wire [17:0] rho0; //right shift rho0 by switch 4
  638.     assign rho0 = (18'h0_8000 >> sw[4]);
  639.     parameter rho_max = 18'h0_fae1; //about 0.49
  640.     wire [4:0] etadt; //damping factor, default of a right shift by 12
  641.     assign etadt = sw[0] ? (5'd8 + sw[3:1]) : 12;
  642.     wire signed [17:0] u_shift, u_sq, rho_plus, rho;
  643.    
  644.     //global rho calculation
  645.     //wires[(n-1)>>].sound gives the middle row of the middle column -- the center of the drum
  646.     assign u_shift = (wires[(n-1)>>1].sound >>> gain);
  647.     signed_mult u_squared(u_sq, u_shift, u_shift);
  648.     assign rho_plus = u_sq + rho0;
  649.     assign rho = (rho_plus > rho_max) ? rho_max : rho_plus;
  650.    
  651.     assign sound = wires[(n-1)>>1].sound; // get sound from middle node
  652.     genvar i;
  653.     reg [8:0] row = 0; //will be constantly incremented while the reset button is held, used for writing initial values
  654.     generate
  655.         for(i = 0; i < n; i = i+1) begin : wires
  656.             wire [4:0] etadts; //damping factor input
  657.             wire signed [17:0] wout, sound, rhos; //wout is position of node in current row, passed to neighboring columns
  658.             wire signed [17:0] iminus, iplus; //input from neighboring columns
  659.             reg [8:0] curr_wradd_init, prev_wradd_init; //initial values
  660.             reg [17:0] curr_in_init, prev_in_init; //initial values
  661.             wire [8:0] column_size; //input of column size into columns
  662.         end //for
  663.         for(i = 0; i < n; i = i+1) begin : columns
  664.             //attach to neighboring column or 0 if on an edge
  665.             if (i == 0)
  666.                 assign wires[i].iminus = 18'h0;
  667.             else
  668.                 assign wires[i].iminus = wires[i-1].wout;
  669.             if (i == n-1)
  670.                 assign wires[i].iplus = 18'h0;
  671.             else
  672.                 assign wires[i].iplus = wires[i+1].wout;
  673.            
  674.             //inputs for calculations  
  675.             assign wires[i].rhos = rho;
  676.             assign wires[i].etadts = etadt;
  677.             assign wires[i].column_size = column_size;
  678.            
  679.             column ccc(.CLOCK_50(CLOCK_50),
  680.                         .reset(reset),
  681.                         .start(start),
  682.                         .iminus(wires[i].iminus),
  683.                         .iplus(wires[i].iplus),
  684.                         .curr_wradd_init(wires[i].curr_wradd_init),
  685.                         .prev_wradd_init(wires[i].prev_wradd_init),
  686.                         .curr_in_init(wires[i].curr_in_init),
  687.                         .prev_in_init(wires[i].prev_in_init),
  688.                         .rho(wires[i].rhos),
  689.                         .etadt(wires[i].etadts),
  690.                         .jplus_out(wires[i].wout),
  691.                         .sound(wires[i].sound),
  692.                         .column_size(wires[i].column_size));
  693.         end //for
  694.        
  695.         always @ (posedge CLOCK_50) begin
  696.             //cycle row through all row values to write initial values while reset is held
  697.             if (reset==0) begin
  698.                 if (9'd0 > row || row >= column_size-1) begin
  699.                     row <= 9'd0;
  700.                 end
  701.                 else begin
  702.                     row <= row + 1;
  703.                 end
  704.             end //if
  705.         end //always
  706.         //our initial waveform is a 17x17 gaussian with max magnitude 0.25, in the center of the drum
  707.         //the relevant values were generated by matlab
  708.         //all other nodes are initialized to 0
  709.         for(i=0; i < n; i=i+1) begin : inits
  710.             always @ (posedge CLOCK_50) begin
  711.                 wires[i].curr_wradd_init <= row;
  712.                 wires[i].prev_wradd_init <= row;
  713.                 //initializing nodes not in the center 17x17 to 0
  714.                 if (i < ((n-1)>>1)-8 || i > ((n-1)>>1)+8 || row < ((column_size-1)>>1)-8 || row > ((column_size-1)>>1)+8) begin
  715.                     wires[i].curr_in_init <= 18'h0;
  716.                     wires[i].prev_in_init <= 18'h0;
  717.                 end
  718.                 else begin
  719.                     //case statement assigns values to the center 17x17
  720.                     case(17*(row - (((column_size-1)>>1)-8)) + i - (((n-1)>>1)-8))
  721.                         0: begin
  722.                             wires[i].curr_in_init <= 18'h00000;
  723.                             wires[i].prev_in_init <= 18'h00000;
  724.                         end
  725.                         1: begin
  726.                             wires[i].curr_in_init <= 18'h00000;
  727.                             wires[i].prev_in_init <= 18'h00000;
  728.                         end
  729.                         2: begin
  730.                             wires[i].curr_in_init <= 18'h00001;
  731.                             wires[i].prev_in_init <= 18'h00001;
  732.                         end
  733.                         3: begin
  734.                             wires[i].curr_in_init <= 18'h00004;
  735.                             wires[i].prev_in_init <= 18'h00004;
  736.                         end
  737.                         4: begin
  738.                             wires[i].curr_in_init <= 18'h0000a;
  739.                             wires[i].prev_in_init <= 18'h0000a;
  740.                         end
  741.                         5: begin
  742.                             wires[i].curr_in_init <= 18'h00016;
  743.                             wires[i].prev_in_init <= 18'h00016;
  744.                         end
  745.                         6: begin
  746.                             wires[i].curr_in_init <= 18'h00024;
  747.                             wires[i].prev_in_init <= 18'h00024;
  748.                         end
  749.                         7: begin
  750.                             wires[i].curr_in_init <= 18'h00031;
  751.                             wires[i].prev_in_init <= 18'h00031;
  752.                         end
  753.                         8: begin
  754.                             wires[i].curr_in_init <= 18'h00036;
  755.                             wires[i].prev_in_init <= 18'h00036;
  756.                         end
  757.                         9: begin
  758.                             wires[i].curr_in_init <= 18'h00031;
  759.                             wires[i].prev_in_init <= 18'h00031;
  760.                         end
  761.                         10: begin
  762.                             wires[i].curr_in_init <= 18'h00024;
  763.                             wires[i].prev_in_init <= 18'h00024;
  764.                         end
  765.                         11: begin
  766.                             wires[i].curr_in_init <= 18'h00016;
  767.                             wires[i].prev_in_init <= 18'h00016;
  768.                         end
  769.                         12: begin
  770.                             wires[i].curr_in_init <= 18'h0000a;
  771.                             wires[i].prev_in_init <= 18'h0000a;
  772.                         end
  773.                         13: begin
  774.                             wires[i].curr_in_init <= 18'h00004;
  775.                             wires[i].prev_in_init <= 18'h00004;
  776.                         end
  777.                         14: begin
  778.                             wires[i].curr_in_init <= 18'h00001;
  779.                             wires[i].prev_in_init <= 18'h00001;
  780.                         end
  781.                         15: begin
  782.                             wires[i].curr_in_init <= 18'h00000;
  783.                             wires[i].prev_in_init <= 18'h00000;
  784.                         end
  785.                         16: begin
  786.                             wires[i].curr_in_init <= 18'h00000;
  787.                             wires[i].prev_in_init <= 18'h00000;
  788.                         end
  789.                         17: begin
  790.                             wires[i].curr_in_init <= 18'h00000;
  791.                             wires[i].prev_in_init <= 18'h00000;
  792.                         end
  793.                         18: begin
  794.                             wires[i].curr_in_init <= 18'h00001;
  795.                             wires[i].prev_in_init <= 18'h00001;
  796.                         end
  797.                         19: begin
  798.                             wires[i].curr_in_init <= 18'h00006;
  799.                             wires[i].prev_in_init <= 18'h00006;
  800.                         end
  801.                         20: begin
  802.                             wires[i].curr_in_init <= 18'h00014;
  803.                             wires[i].prev_in_init <= 18'h00014;
  804.                         end
  805.                         21: begin
  806.                             wires[i].curr_in_init <= 18'h00031;
  807.                             wires[i].prev_in_init <= 18'h00031;
  808.                         end
  809.                         22: begin
  810.                             wires[i].curr_in_init <= 18'h00063;
  811.                             wires[i].prev_in_init <= 18'h00063;
  812.                         end
  813.                         23: begin
  814.                             wires[i].curr_in_init <= 18'h000a3;
  815.                             wires[i].prev_in_init <= 18'h000a3;
  816.                         end
  817.                         24: begin
  818.                             wires[i].curr_in_init <= 18'h000dc;
  819.                             wires[i].prev_in_init <= 18'h000dc;
  820.                         end
  821.                         25: begin
  822.                             wires[i].curr_in_init <= 18'h000f4;
  823.                             wires[i].prev_in_init <= 18'h000f4;
  824.                         end
  825.                         26: begin
  826.                             wires[i].curr_in_init <= 18'h000dc;
  827.                             wires[i].prev_in_init <= 18'h000dc;
  828.                         end
  829.                         27: begin
  830.                             wires[i].curr_in_init <= 18'h000a3;
  831.                             wires[i].prev_in_init <= 18'h000a3;
  832.                         end
  833.                         28: begin
  834.                             wires[i].curr_in_init <= 18'h00063;
  835.                             wires[i].prev_in_init <= 18'h00063;
  836.                         end
  837.                         29: begin
  838.                             wires[i].curr_in_init <= 18'h00031;
  839.                             wires[i].prev_in_init <= 18'h00031;
  840.                         end
  841.                         30: begin
  842.                             wires[i].curr_in_init <= 18'h00014;
  843.                             wires[i].prev_in_init <= 18'h00014;
  844.                         end
  845.                         31: begin
  846.                             wires[i].curr_in_init <= 18'h00006;
  847.                             wires[i].prev_in_init <= 18'h00006;
  848.                         end
  849.                         32: begin
  850.                             wires[i].curr_in_init <= 18'h00001;
  851.                             wires[i].prev_in_init <= 18'h00001;
  852.                         end
  853.                         33: begin
  854.                             wires[i].curr_in_init <= 18'h00000;
  855.                             wires[i].prev_in_init <= 18'h00000;
  856.                         end
  857.                         34: begin
  858.                             wires[i].curr_in_init <= 18'h00001;
  859.                             wires[i].prev_in_init <= 18'h00001;
  860.                         end
  861.                         35: begin
  862.                             wires[i].curr_in_init <= 18'h00006;
  863.                             wires[i].prev_in_init <= 18'h00006;
  864.                         end
  865.                         36: begin
  866.                             wires[i].curr_in_init <= 18'h00018;
  867.                             wires[i].prev_in_init <= 18'h00018;
  868.                         end
  869.                         37: begin
  870.                             wires[i].curr_in_init <= 18'h00049;
  871.                             wires[i].prev_in_init <= 18'h00049;
  872.                         end
  873.                         38: begin
  874.                             wires[i].curr_in_init <= 18'h000b4;
  875.                             wires[i].prev_in_init <= 18'h000b4;
  876.                         end
  877.                         39: begin
  878.                             wires[i].curr_in_init <= 18'h0016c;
  879.                             wires[i].prev_in_init <= 18'h0016c;
  880.                         end
  881.                         40: begin
  882.                             wires[i].curr_in_init <= 18'h00258;
  883.                             wires[i].prev_in_init <= 18'h00258;
  884.                         end
  885.                         41: begin
  886.                             wires[i].curr_in_init <= 18'h0032a;
  887.                             wires[i].prev_in_init <= 18'h0032a;
  888.                         end
  889.                         42: begin
  890.                             wires[i].curr_in_init <= 18'h0037f;
  891.                             wires[i].prev_in_init <= 18'h0037f;
  892.                         end
  893.                         43: begin
  894.                             wires[i].curr_in_init <= 18'h0032a;
  895.                             wires[i].prev_in_init <= 18'h0032a;
  896.                         end
  897.                         44: begin
  898.                             wires[i].curr_in_init <= 18'h00258;
  899.                             wires[i].prev_in_init <= 18'h00258;
  900.                         end
  901.                         45: begin
  902.                             wires[i].curr_in_init <= 18'h0016c;
  903.                             wires[i].prev_in_init <= 18'h0016c;
  904.                         end
  905.                         46: begin
  906.                             wires[i].curr_in_init <= 18'h000b4;
  907.                             wires[i].prev_in_init <= 18'h000b4;
  908.                         end
  909.                         47: begin
  910.                             wires[i].curr_in_init <= 18'h00049;
  911.                             wires[i].prev_in_init <= 18'h00049;
  912.                         end
  913.                         48: begin
  914.                             wires[i].curr_in_init <= 18'h00018;
  915.                             wires[i].prev_in_init <= 18'h00018;
  916.                         end
  917.                         49: begin
  918.                             wires[i].curr_in_init <= 18'h00006;
  919.                             wires[i].prev_in_init <= 18'h00006;
  920.                         end
  921.                         50: begin
  922.                             wires[i].curr_in_init <= 18'h00001;
  923.                             wires[i].prev_in_init <= 18'h00001;
  924.                         end
  925.                         51: begin
  926.                             wires[i].curr_in_init <= 18'h00004;
  927.                             wires[i].prev_in_init <= 18'h00004;
  928.                         end
  929.                         52: begin
  930.                             wires[i].curr_in_init <= 18'h00014;
  931.                             wires[i].prev_in_init <= 18'h00014;
  932.                         end
  933.                         53: begin
  934.                             wires[i].curr_in_init <= 18'h00049;
  935.                             wires[i].prev_in_init <= 18'h00049;
  936.                         end
  937.                         54: begin
  938.                             wires[i].curr_in_init <= 18'h000dc;
  939.                             wires[i].prev_in_init <= 18'h000dc;
  940.                         end
  941.                         55: begin
  942.                             wires[i].curr_in_init <= 18'h0021f;
  943.                             wires[i].prev_in_init <= 18'h0021f;
  944.                         end
  945.                         56: begin
  946.                             wires[i].curr_in_init <= 18'h00445;
  947.                             wires[i].prev_in_init <= 18'h00445;
  948.                         end
  949.                         57: begin
  950.                             wires[i].curr_in_init <= 18'h0070a;
  951.                             wires[i].prev_in_init <= 18'h0070a;
  952.                         end
  953.                         58: begin
  954.                             wires[i].curr_in_init <= 18'h00981;
  955.                             wires[i].prev_in_init <= 18'h00981;
  956.                         end
  957.                         59: begin
  958.                             wires[i].curr_in_init <= 18'h00a81;
  959.                             wires[i].prev_in_init <= 18'h00a81;
  960.                         end
  961.                         60: begin
  962.                             wires[i].curr_in_init <= 18'h00981;
  963.                             wires[i].prev_in_init <= 18'h00981;
  964.                         end
  965.                         61: begin
  966.                             wires[i].curr_in_init <= 18'h0070a;
  967.                             wires[i].prev_in_init <= 18'h0070a;
  968.                         end
  969.                         62: begin
  970.                             wires[i].curr_in_init <= 18'h00445;
  971.                             wires[i].prev_in_init <= 18'h00445;
  972.                         end
  973.                         63: begin
  974.                             wires[i].curr_in_init <= 18'h0021f;
  975.                             wires[i].prev_in_init <= 18'h0021f;
  976.                         end
  977.                         64: begin
  978.                             wires[i].curr_in_init <= 18'h000dc;
  979.                             wires[i].prev_in_init <= 18'h000dc;
  980.                         end
  981.                         65: begin
  982.                             wires[i].curr_in_init <= 18'h00049;
  983.                             wires[i].prev_in_init <= 18'h00049;
  984.                         end
  985.                         66: begin
  986.                             wires[i].curr_in_init <= 18'h00014;
  987.                             wires[i].prev_in_init <= 18'h00014;
  988.                         end
  989.                         67: begin
  990.                             wires[i].curr_in_init <= 18'h00004;
  991.                             wires[i].prev_in_init <= 18'h00004;
  992.                         end
  993.                         68: begin
  994.                             wires[i].curr_in_init <= 18'h0000a;
  995.                             wires[i].prev_in_init <= 18'h0000a;
  996.                         end
  997.                         69: begin
  998.                             wires[i].curr_in_init <= 18'h00031;
  999.                             wires[i].prev_in_init <= 18'h00031;
  1000.                         end
  1001.                         70: begin
  1002.                             wires[i].curr_in_init <= 18'h000b4;
  1003.                             wires[i].prev_in_init <= 18'h000b4;
  1004.                         end
  1005.                         71: begin
  1006.                             wires[i].curr_in_init <= 18'h0021f;
  1007.                             wires[i].prev_in_init <= 18'h0021f;
  1008.                         end
  1009.                         72: begin
  1010.                             wires[i].curr_in_init <= 18'h00537;
  1011.                             wires[i].prev_in_init <= 18'h00537;
  1012.                         end
  1013.                         73: begin
  1014.                             wires[i].curr_in_init <= 18'h00a81;
  1015.                             wires[i].prev_in_init <= 18'h00a81;
  1016.                         end
  1017.                         74: begin
  1018.                             wires[i].curr_in_init <= 18'h01152;
  1019.                             wires[i].prev_in_init <= 18'h01152;
  1020.                         end
  1021.                         75: begin
  1022.                             wires[i].curr_in_init <= 18'h01762;
  1023.                             wires[i].prev_in_init <= 18'h01762;
  1024.                         end
  1025.                         76: begin
  1026.                             wires[i].curr_in_init <= 18'h019d7;
  1027.                             wires[i].prev_in_init <= 18'h019d7;
  1028.                         end
  1029.                         77: begin
  1030.                             wires[i].curr_in_init <= 18'h01762;
  1031.                             wires[i].prev_in_init <= 18'h01762;
  1032.                         end
  1033.                         78: begin
  1034.                             wires[i].curr_in_init <= 18'h01152;
  1035.                             wires[i].prev_in_init <= 18'h01152;
  1036.                         end
  1037.                         79: begin
  1038.                             wires[i].curr_in_init <= 18'h00a81;
  1039.                             wires[i].prev_in_init <= 18'h00a81;
  1040.                         end
  1041.                         80: begin
  1042.                             wires[i].curr_in_init <= 18'h00537;
  1043.                             wires[i].prev_in_init <= 18'h00537;
  1044.                         end
  1045.                         81: begin
  1046.                             wires[i].curr_in_init <= 18'h0021f;
  1047.                             wires[i].prev_in_init <= 18'h0021f;
  1048.                         end
  1049.                         82: begin
  1050.                             wires[i].curr_in_init <= 18'h000b4;
  1051.                             wires[i].prev_in_init <= 18'h000b4;
  1052.                         end
  1053.                         83: begin
  1054.                             wires[i].curr_in_init <= 18'h00031;
  1055.                             wires[i].prev_in_init <= 18'h00031;
  1056.                         end
  1057.                         84: begin
  1058.                             wires[i].curr_in_init <= 18'h0000a;
  1059.                             wires[i].prev_in_init <= 18'h0000a;
  1060.                         end
  1061.                         85: begin
  1062.                             wires[i].curr_in_init <= 18'h00016;
  1063.                             wires[i].prev_in_init <= 18'h00016;
  1064.                         end
  1065.                         86: begin
  1066.                             wires[i].curr_in_init <= 18'h00063;
  1067.                             wires[i].prev_in_init <= 18'h00063;
  1068.                         end
  1069.                         87: begin
  1070.                             wires[i].curr_in_init <= 18'h0016c;
  1071.                             wires[i].prev_in_init <= 18'h0016c;
  1072.                         end
  1073.                         88: begin
  1074.                             wires[i].curr_in_init <= 18'h00445;
  1075.                             wires[i].prev_in_init <= 18'h00445;
  1076.                         end
  1077.                         89: begin
  1078.                             wires[i].curr_in_init <= 18'h00a81;
  1079.                             wires[i].prev_in_init <= 18'h00a81;
  1080.                         end
  1081.                         90: begin
  1082.                             wires[i].curr_in_init <= 18'h01528;
  1083.                             wires[i].prev_in_init <= 18'h01528;
  1084.                         end
  1085.                         91: begin
  1086.                             wires[i].curr_in_init <= 18'h022e2;
  1087.                             wires[i].prev_in_init <= 18'h022e2;
  1088.                         end
  1089.                         92: begin
  1090.                             wires[i].curr_in_init <= 18'h02f16;
  1091.                             wires[i].prev_in_init <= 18'h02f16;
  1092.                         end
  1093.                         93: begin
  1094.                             wires[i].curr_in_init <= 18'h0340a;
  1095.                             wires[i].prev_in_init <= 18'h0340a;
  1096.                         end
  1097.                         94: begin
  1098.                             wires[i].curr_in_init <= 18'h02f16;
  1099.                             wires[i].prev_in_init <= 18'h02f16;
  1100.                         end
  1101.                         95: begin
  1102.                             wires[i].curr_in_init <= 18'h022e2;
  1103.                             wires[i].prev_in_init <= 18'h022e2;
  1104.                         end
  1105.                         96: begin
  1106.                             wires[i].curr_in_init <= 18'h01528;
  1107.                             wires[i].prev_in_init <= 18'h01528;
  1108.                         end
  1109.                         97: begin
  1110.                             wires[i].curr_in_init <= 18'h00a81;
  1111.                             wires[i].prev_in_init <= 18'h00a81;
  1112.                         end
  1113.                         98: begin
  1114.                             wires[i].curr_in_init <= 18'h00445;
  1115.                             wires[i].prev_in_init <= 18'h00445;
  1116.                         end
  1117.                         99: begin
  1118.                             wires[i].curr_in_init <= 18'h0016c;
  1119.                             wires[i].prev_in_init <= 18'h0016c;
  1120.                         end
  1121.                         100: begin
  1122.                             wires[i].curr_in_init <= 18'h00063;
  1123.                             wires[i].prev_in_init <= 18'h00063;
  1124.                         end
  1125.                         101: begin
  1126.                             wires[i].curr_in_init <= 18'h00016;
  1127.                             wires[i].prev_in_init <= 18'h00016;
  1128.                         end
  1129.                         102: begin
  1130.                             wires[i].curr_in_init <= 18'h00024;
  1131.                             wires[i].prev_in_init <= 18'h00024;
  1132.                         end
  1133.                         103: begin
  1134.                             wires[i].curr_in_init <= 18'h000a3;
  1135.                             wires[i].prev_in_init <= 18'h000a3;
  1136.                         end
  1137.                         104: begin
  1138.                             wires[i].curr_in_init <= 18'h00258;
  1139.                             wires[i].prev_in_init <= 18'h00258;
  1140.                         end
  1141.                         105: begin
  1142.                             wires[i].curr_in_init <= 18'h0070a;
  1143.                             wires[i].prev_in_init <= 18'h0070a;
  1144.                         end
  1145.                         106: begin
  1146.                             wires[i].curr_in_init <= 18'h01152;
  1147.                             wires[i].prev_in_init <= 18'h01152;
  1148.                         end
  1149.                         107: begin
  1150.                             wires[i].curr_in_init <= 18'h022e2;
  1151.                             wires[i].prev_in_init <= 18'h022e2;
  1152.                         end
  1153.                         108: begin
  1154.                             wires[i].curr_in_init <= 18'h03983;
  1155.                             wires[i].prev_in_init <= 18'h03983;
  1156.                         end
  1157.                         109: begin
  1158.                             wires[i].curr_in_init <= 18'h04da2;
  1159.                             wires[i].prev_in_init <= 18'h04da2;
  1160.                         end
  1161.                         110: begin
  1162.                             wires[i].curr_in_init <= 18'h055cc;
  1163.                             wires[i].prev_in_init <= 18'h055cc;
  1164.                         end
  1165.                         111: begin
  1166.                             wires[i].curr_in_init <= 18'h04da2;
  1167.                             wires[i].prev_in_init <= 18'h04da2;
  1168.                         end
  1169.                         112: begin
  1170.                             wires[i].curr_in_init <= 18'h03983;
  1171.                             wires[i].prev_in_init <= 18'h03983;
  1172.                         end
  1173.                         113: begin
  1174.                             wires[i].curr_in_init <= 18'h022e2;
  1175.                             wires[i].prev_in_init <= 18'h022e2;
  1176.                         end
  1177.                         114: begin
  1178.                             wires[i].curr_in_init <= 18'h01152;
  1179.                             wires[i].prev_in_init <= 18'h01152;
  1180.                         end
  1181.                         115: begin
  1182.                             wires[i].curr_in_init <= 18'h0070a;
  1183.                             wires[i].prev_in_init <= 18'h0070a;
  1184.                         end
  1185.                         116: begin
  1186.                             wires[i].curr_in_init <= 18'h00258;
  1187.                             wires[i].prev_in_init <= 18'h00258;
  1188.                         end
  1189.                         117: begin
  1190.                             wires[i].curr_in_init <= 18'h000a3;
  1191.                             wires[i].prev_in_init <= 18'h000a3;
  1192.                         end
  1193.                         118: begin
  1194.                             wires[i].curr_in_init <= 18'h00024;
  1195.                             wires[i].prev_in_init <= 18'h00024;
  1196.                         end
  1197.                         119: begin
  1198.                             wires[i].curr_in_init <= 18'h00031;
  1199.                             wires[i].prev_in_init <= 18'h00031;
  1200.                         end
  1201.                         120: begin
  1202.                             wires[i].curr_in_init <= 18'h000dc;
  1203.                             wires[i].prev_in_init <= 18'h000dc;
  1204.                         end
  1205.                         121: begin
  1206.                             wires[i].curr_in_init <= 18'h0032a;
  1207.                             wires[i].prev_in_init <= 18'h0032a;
  1208.                         end
  1209.                         122: begin
  1210.                             wires[i].curr_in_init <= 18'h00981;
  1211.                             wires[i].prev_in_init <= 18'h00981;
  1212.                         end
  1213.                         123: begin
  1214.                             wires[i].curr_in_init <= 18'h01762;
  1215.                             wires[i].prev_in_init <= 18'h01762;
  1216.                         end
  1217.                         124: begin
  1218.                             wires[i].curr_in_init <= 18'h02f16;
  1219.                             wires[i].prev_in_init <= 18'h02f16;
  1220.                         end
  1221.                         125: begin
  1222.                             wires[i].curr_in_init <= 18'h04da2;
  1223.                             wires[i].prev_in_init <= 18'h04da2;
  1224.                         end
  1225.                         126: begin
  1226.                             wires[i].curr_in_init <= 18'h068cb;
  1227.                             wires[i].prev_in_init <= 18'h068cb;
  1228.                         end
  1229.                         127: begin
  1230.                             wires[i].curr_in_init <= 18'h073d1;
  1231.                             wires[i].prev_in_init <= 18'h073d1;
  1232.                         end
  1233.                         128: begin
  1234.                             wires[i].curr_in_init <= 18'h068cb;
  1235.                             wires[i].prev_in_init <= 18'h068cb;
  1236.                         end
  1237.                         129: begin
  1238.                             wires[i].curr_in_init <= 18'h04da2;
  1239.                             wires[i].prev_in_init <= 18'h04da2;
  1240.                         end
  1241.                         130: begin
  1242.                             wires[i].curr_in_init <= 18'h02f16;
  1243.                             wires[i].prev_in_init <= 18'h02f16;
  1244.                         end
  1245.                         131: begin
  1246.                             wires[i].curr_in_init <= 18'h01762;
  1247.                             wires[i].prev_in_init <= 18'h01762;
  1248.                         end
  1249.                         132: begin
  1250.                             wires[i].curr_in_init <= 18'h00981;
  1251.                             wires[i].prev_in_init <= 18'h00981;
  1252.                         end
  1253.                         133: begin
  1254.                             wires[i].curr_in_init <= 18'h0032a;
  1255.                             wires[i].prev_in_init <= 18'h0032a;
  1256.                         end
  1257.                         134: begin
  1258.                             wires[i].curr_in_init <= 18'h000dc;
  1259.                             wires[i].prev_in_init <= 18'h000dc;
  1260.                         end
  1261.                         135: begin
  1262.                             wires[i].curr_in_init <= 18'h00031;
  1263.                             wires[i].prev_in_init <= 18'h00031;
  1264.                         end
  1265.                         136: begin
  1266.                             wires[i].curr_in_init <= 18'h00036;
  1267.                             wires[i].prev_in_init <= 18'h00036;
  1268.                         end
  1269.                         137: begin
  1270.                             wires[i].curr_in_init <= 18'h000f4;
  1271.                             wires[i].prev_in_init <= 18'h000f4;
  1272.                         end
  1273.                         138: begin
  1274.                             wires[i].curr_in_init <= 18'h0037f;
  1275.                             wires[i].prev_in_init <= 18'h0037f;
  1276.                         end
  1277.                         139: begin
  1278.                             wires[i].curr_in_init <= 18'h00a81;
  1279.                             wires[i].prev_in_init <= 18'h00a81;
  1280.                         end
  1281.                         140: begin
  1282.                             wires[i].curr_in_init <= 18'h019d7;
  1283.                             wires[i].prev_in_init <= 18'h019d7;
  1284.                         end
  1285.                         141: begin
  1286.                             wires[i].curr_in_init <= 18'h0340a;
  1287.                             wires[i].prev_in_init <= 18'h0340a;
  1288.                         end
  1289.                         142: begin
  1290.                             wires[i].curr_in_init <= 18'h055cc;
  1291.                             wires[i].prev_in_init <= 18'h055cc;
  1292.                         end
  1293.                         143: begin
  1294.                             wires[i].curr_in_init <= 18'h073d1;
  1295.                             wires[i].prev_in_init <= 18'h073d1;
  1296.                         end
  1297.                         144: begin
  1298.                             wires[i].curr_in_init <= 18'h07fff;
  1299.                             wires[i].prev_in_init <= 18'h07fff;
  1300.                         end
  1301.                         145: begin
  1302.                             wires[i].curr_in_init <= 18'h073d1;
  1303.                             wires[i].prev_in_init <= 18'h073d1;
  1304.                         end
  1305.                         146: begin
  1306.                             wires[i].curr_in_init <= 18'h055cc;
  1307.                             wires[i].prev_in_init <= 18'h055cc;
  1308.                         end
  1309.                         147: begin
  1310.                             wires[i].curr_in_init <= 18'h0340a;
  1311.                             wires[i].prev_in_init <= 18'h0340a;
  1312.                         end
  1313.                         148: begin
  1314.                             wires[i].curr_in_init <= 18'h019d7;
  1315.                             wires[i].prev_in_init <= 18'h019d7;
  1316.                         end
  1317.                         149: begin
  1318.                             wires[i].curr_in_init <= 18'h00a81;
  1319.                             wires[i].prev_in_init <= 18'h00a81;
  1320.                         end
  1321.                         150: begin
  1322.                             wires[i].curr_in_init <= 18'h0037f;
  1323.                             wires[i].prev_in_init <= 18'h0037f;
  1324.                         end
  1325.                         151: begin
  1326.                             wires[i].curr_in_init <= 18'h000f4;
  1327.                             wires[i].prev_in_init <= 18'h000f4;
  1328.                         end
  1329.                         152: begin
  1330.                             wires[i].curr_in_init <= 18'h00036;
  1331.                             wires[i].prev_in_init <= 18'h00036;
  1332.                         end
  1333.                         153: begin
  1334.                             wires[i].curr_in_init <= 18'h00031;
  1335.                             wires[i].prev_in_init <= 18'h00031;
  1336.                         end
  1337.                         154: begin
  1338.                             wires[i].curr_in_init <= 18'h000dc;
  1339.                             wires[i].prev_in_init <= 18'h000dc;
  1340.                         end
  1341.                         155: begin
  1342.                             wires[i].curr_in_init <= 18'h0032a;
  1343.                             wires[i].prev_in_init <= 18'h0032a;
  1344.                         end
  1345.                         156: begin
  1346.                             wires[i].curr_in_init <= 18'h00981;
  1347.                             wires[i].prev_in_init <= 18'h00981;
  1348.                         end
  1349.                         157: begin
  1350.                             wires[i].curr_in_init <= 18'h01762;
  1351.                             wires[i].prev_in_init <= 18'h01762;
  1352.                         end
  1353.                         158: begin
  1354.                             wires[i].curr_in_init <= 18'h02f16;
  1355.                             wires[i].prev_in_init <= 18'h02f16;
  1356.                         end
  1357.                         159: begin
  1358.                             wires[i].curr_in_init <= 18'h04da2;
  1359.                             wires[i].prev_in_init <= 18'h04da2;
  1360.                         end
  1361.                         160: begin
  1362.                             wires[i].curr_in_init <= 18'h068cb;
  1363.                             wires[i].prev_in_init <= 18'h068cb;
  1364.                         end
  1365.                         161: begin
  1366.                             wires[i].curr_in_init <= 18'h073d1;
  1367.                             wires[i].prev_in_init <= 18'h073d1;
  1368.                         end
  1369.                         162: begin
  1370.                             wires[i].curr_in_init <= 18'h068cb;
  1371.                             wires[i].prev_in_init <= 18'h068cb;
  1372.                         end
  1373.                         163: begin
  1374.                             wires[i].curr_in_init <= 18'h04da2;
  1375.                             wires[i].prev_in_init <= 18'h04da2;
  1376.                         end
  1377.                         164: begin
  1378.                             wires[i].curr_in_init <= 18'h02f16;
  1379.                             wires[i].prev_in_init <= 18'h02f16;
  1380.                         end
  1381.                         165: begin
  1382.                             wires[i].curr_in_init <= 18'h01762;
  1383.                             wires[i].prev_in_init <= 18'h01762;
  1384.                         end
  1385.                         166: begin
  1386.                             wires[i].curr_in_init <= 18'h00981;
  1387.                             wires[i].prev_in_init <= 18'h00981;
  1388.                         end
  1389.                         167: begin
  1390.                             wires[i].curr_in_init <= 18'h0032a;
  1391.                             wires[i].prev_in_init <= 18'h0032a;
  1392.                         end
  1393.                         168: begin
  1394.                             wires[i].curr_in_init <= 18'h000dc;
  1395.                             wires[i].prev_in_init <= 18'h000dc;
  1396.                         end
  1397.                         169: begin
  1398.                             wires[i].curr_in_init <= 18'h00031;
  1399.                             wires[i].prev_in_init <= 18'h00031;
  1400.                         end
  1401.                         170: begin
  1402.                             wires[i].curr_in_init <= 18'h00024;
  1403.                             wires[i].prev_in_init <= 18'h00024;
  1404.                         end
  1405.                         171: begin
  1406.                             wires[i].curr_in_init <= 18'h000a3;
  1407.                             wires[i].prev_in_init <= 18'h000a3;
  1408.                         end
  1409.                         172: begin
  1410.                             wires[i].curr_in_init <= 18'h00258;
  1411.                             wires[i].prev_in_init <= 18'h00258;
  1412.                         end
  1413.                         173: begin
  1414.                             wires[i].curr_in_init <= 18'h0070a;
  1415.                             wires[i].prev_in_init <= 18'h0070a;
  1416.                         end
  1417.                         174: begin
  1418.                             wires[i].curr_in_init <= 18'h01152;
  1419.                             wires[i].prev_in_init <= 18'h01152;
  1420.                         end
  1421.                         175: begin
  1422.                             wires[i].curr_in_init <= 18'h022e2;
  1423.                             wires[i].prev_in_init <= 18'h022e2;
  1424.                         end
  1425.                         176: begin
  1426.                             wires[i].curr_in_init <= 18'h03983;
  1427.                             wires[i].prev_in_init <= 18'h03983;
  1428.                         end
  1429.                         177: begin
  1430.                             wires[i].curr_in_init <= 18'h04da2;
  1431.                             wires[i].prev_in_init <= 18'h04da2;
  1432.                         end
  1433.                         178: begin
  1434.                             wires[i].curr_in_init <= 18'h055cc;
  1435.                             wires[i].prev_in_init <= 18'h055cc;
  1436.                         end
  1437.                         179: begin
  1438.                             wires[i].curr_in_init <= 18'h04da2;
  1439.                             wires[i].prev_in_init <= 18'h04da2;
  1440.                         end
  1441.                         180: begin
  1442.                             wires[i].curr_in_init <= 18'h03983;
  1443.                             wires[i].prev_in_init <= 18'h03983;
  1444.                         end
  1445.                         181: begin
  1446.                             wires[i].curr_in_init <= 18'h022e2;
  1447.                             wires[i].prev_in_init <= 18'h022e2;
  1448.                         end
  1449.                         182: begin
  1450.                             wires[i].curr_in_init <= 18'h01152;
  1451.                             wires[i].prev_in_init <= 18'h01152;
  1452.                         end
  1453.                         183: begin
  1454.                             wires[i].curr_in_init <= 18'h0070a;
  1455.                             wires[i].prev_in_init <= 18'h0070a;
  1456.                         end
  1457.                         184: begin
  1458.                             wires[i].curr_in_init <= 18'h00258;
  1459.                             wires[i].prev_in_init <= 18'h00258;
  1460.                         end
  1461.                         185: begin
  1462.                             wires[i].curr_in_init <= 18'h000a3;
  1463.                             wires[i].prev_in_init <= 18'h000a3;
  1464.                         end
  1465.                         186: begin
  1466.                             wires[i].curr_in_init <= 18'h00024;
  1467.                             wires[i].prev_in_init <= 18'h00024;
  1468.                         end
  1469.                         187: begin
  1470.                             wires[i].curr_in_init <= 18'h00016;
  1471.                             wires[i].prev_in_init <= 18'h00016;
  1472.                         end
  1473.                         188: begin
  1474.                             wires[i].curr_in_init <= 18'h00063;
  1475.                             wires[i].prev_in_init <= 18'h00063;
  1476.                         end
  1477.                         189: begin
  1478.                             wires[i].curr_in_init <= 18'h0016c;
  1479.                             wires[i].prev_in_init <= 18'h0016c;
  1480.                         end
  1481.                         190: begin
  1482.                             wires[i].curr_in_init <= 18'h00445;
  1483.                             wires[i].prev_in_init <= 18'h00445;
  1484.                         end
  1485.                         191: begin
  1486.                             wires[i].curr_in_init <= 18'h00a81;
  1487.                             wires[i].prev_in_init <= 18'h00a81;
  1488.                         end
  1489.                         192: begin
  1490.                             wires[i].curr_in_init <= 18'h01528;
  1491.                             wires[i].prev_in_init <= 18'h01528;
  1492.                         end
  1493.                         193: begin
  1494.                             wires[i].curr_in_init <= 18'h022e2;
  1495.                             wires[i].prev_in_init <= 18'h022e2;
  1496.                         end
  1497.                         194: begin
  1498.                             wires[i].curr_in_init <= 18'h02f16;
  1499.                             wires[i].prev_in_init <= 18'h02f16;
  1500.                         end
  1501.                         195: begin
  1502.                             wires[i].curr_in_init <= 18'h0340a;
  1503.                             wires[i].prev_in_init <= 18'h0340a;
  1504.                         end
  1505.                         196: begin
  1506.                             wires[i].curr_in_init <= 18'h02f16;
  1507.                             wires[i].prev_in_init <= 18'h02f16;
  1508.                         end
  1509.                         197: begin
  1510.                             wires[i].curr_in_init <= 18'h022e2;
  1511.                             wires[i].prev_in_init <= 18'h022e2;
  1512.                         end
  1513.                         198: begin
  1514.                             wires[i].curr_in_init <= 18'h01528;
  1515.                             wires[i].prev_in_init <= 18'h01528;
  1516.                         end
  1517.                         199: begin
  1518.                             wires[i].curr_in_init <= 18'h00a81;
  1519.                             wires[i].prev_in_init <= 18'h00a81;
  1520.                         end
  1521.                         200: begin
  1522.                             wires[i].curr_in_init <= 18'h00445;
  1523.                             wires[i].prev_in_init <= 18'h00445;
  1524.                         end
  1525.                         201: begin
  1526.                             wires[i].curr_in_init <= 18'h0016c;
  1527.                             wires[i].prev_in_init <= 18'h0016c;
  1528.                         end
  1529.                         202: begin
  1530.                             wires[i].curr_in_init <= 18'h00063;
  1531.                             wires[i].prev_in_init <= 18'h00063;
  1532.                         end
  1533.                         203: begin
  1534.                             wires[i].curr_in_init <= 18'h00016;
  1535.                             wires[i].prev_in_init <= 18'h00016;
  1536.                         end
  1537.                         204: begin
  1538.                             wires[i].curr_in_init <= 18'h0000a;
  1539.                             wires[i].prev_in_init <= 18'h0000a;
  1540.                         end
  1541.                         205: begin
  1542.                             wires[i].curr_in_init <= 18'h00031;
  1543.                             wires[i].prev_in_init <= 18'h00031;
  1544.                         end
  1545.                         206: begin
  1546.                             wires[i].curr_in_init <= 18'h000b4;
  1547.                             wires[i].prev_in_init <= 18'h000b4;
  1548.                         end
  1549.                         207: begin
  1550.                             wires[i].curr_in_init <= 18'h0021f;
  1551.                             wires[i].prev_in_init <= 18'h0021f;
  1552.                         end
  1553.                         208: begin
  1554.                             wires[i].curr_in_init <= 18'h00537;
  1555.                             wires[i].prev_in_init <= 18'h00537;
  1556.                         end
  1557.                         209: begin
  1558.                             wires[i].curr_in_init <= 18'h00a81;
  1559.                             wires[i].prev_in_init <= 18'h00a81;
  1560.                         end
  1561.                         210: begin
  1562.                             wires[i].curr_in_init <= 18'h01152;
  1563.                             wires[i].prev_in_init <= 18'h01152;
  1564.                         end
  1565.                         211: begin
  1566.                             wires[i].curr_in_init <= 18'h01762;
  1567.                             wires[i].prev_in_init <= 18'h01762;
  1568.                         end
  1569.                         212: begin
  1570.                             wires[i].curr_in_init <= 18'h019d7;
  1571.                             wires[i].prev_in_init <= 18'h019d7;
  1572.                         end
  1573.                         213: begin
  1574.                             wires[i].curr_in_init <= 18'h01762;
  1575.                             wires[i].prev_in_init <= 18'h01762;
  1576.                         end
  1577.                         214: begin
  1578.                             wires[i].curr_in_init <= 18'h01152;
  1579.                             wires[i].prev_in_init <= 18'h01152;
  1580.                         end
  1581.                         215: begin
  1582.                             wires[i].curr_in_init <= 18'h00a81;
  1583.                             wires[i].prev_in_init <= 18'h00a81;
  1584.                         end
  1585.                         216: begin
  1586.                             wires[i].curr_in_init <= 18'h00537;
  1587.                             wires[i].prev_in_init <= 18'h00537;
  1588.                         end
  1589.                         217: begin
  1590.                             wires[i].curr_in_init <= 18'h0021f;
  1591.                             wires[i].prev_in_init <= 18'h0021f;
  1592.                         end
  1593.                         218: begin
  1594.                             wires[i].curr_in_init <= 18'h000b4;
  1595.                             wires[i].prev_in_init <= 18'h000b4;
  1596.                         end
  1597.                         219: begin
  1598.                             wires[i].curr_in_init <= 18'h00031;
  1599.                             wires[i].prev_in_init <= 18'h00031;
  1600.                         end
  1601.                         220: begin
  1602.                             wires[i].curr_in_init <= 18'h0000a;
  1603.                             wires[i].prev_in_init <= 18'h0000a;
  1604.                         end
  1605.                         221: begin
  1606.                             wires[i].curr_in_init <= 18'h00004;
  1607.                             wires[i].prev_in_init <= 18'h00004;
  1608.                         end
  1609.                         222: begin
  1610.                             wires[i].curr_in_init <= 18'h00014;
  1611.                             wires[i].prev_in_init <= 18'h00014;
  1612.                         end
  1613.                         223: begin
  1614.                             wires[i].curr_in_init <= 18'h00049;
  1615.                             wires[i].prev_in_init <= 18'h00049;
  1616.                         end
  1617.                         224: begin
  1618.                             wires[i].curr_in_init <= 18'h000dc;
  1619.                             wires[i].prev_in_init <= 18'h000dc;
  1620.                         end
  1621.                         225: begin
  1622.                             wires[i].curr_in_init <= 18'h0021f;
  1623.                             wires[i].prev_in_init <= 18'h0021f;
  1624.                         end
  1625.                         226: begin
  1626.                             wires[i].curr_in_init <= 18'h00445;
  1627.                             wires[i].prev_in_init <= 18'h00445;
  1628.                         end
  1629.                         227: begin
  1630.                             wires[i].curr_in_init <= 18'h0070a;
  1631.                             wires[i].prev_in_init <= 18'h0070a;
  1632.                         end
  1633.                         228: begin
  1634.                             wires[i].curr_in_init <= 18'h00981;
  1635.                             wires[i].prev_in_init <= 18'h00981;
  1636.                         end
  1637.                         229: begin
  1638.                             wires[i].curr_in_init <= 18'h00a81;
  1639.                             wires[i].prev_in_init <= 18'h00a81;
  1640.                         end
  1641.                         230: begin
  1642.                             wires[i].curr_in_init <= 18'h00981;
  1643.                             wires[i].prev_in_init <= 18'h00981;
  1644.                         end
  1645.                         231: begin
  1646.                             wires[i].curr_in_init <= 18'h0070a;
  1647.                             wires[i].prev_in_init <= 18'h0070a;
  1648.                         end
  1649.                         232: begin
  1650.                             wires[i].curr_in_init <= 18'h00445;
  1651.                             wires[i].prev_in_init <= 18'h00445;
  1652.                         end
  1653.                         233: begin
  1654.                             wires[i].curr_in_init <= 18'h0021f;
  1655.                             wires[i].prev_in_init <= 18'h0021f;
  1656.                         end
  1657.                         234: begin
  1658.                             wires[i].curr_in_init <= 18'h000dc;
  1659.                             wires[i].prev_in_init <= 18'h000dc;
  1660.                         end
  1661.                         235: begin
  1662.                             wires[i].curr_in_init <= 18'h00049;
  1663.                             wires[i].prev_in_init <= 18'h00049;
  1664.                         end
  1665.                         236: begin
  1666.                             wires[i].curr_in_init <= 18'h00014;
  1667.                             wires[i].prev_in_init <= 18'h00014;
  1668.                         end
  1669.                         237: begin
  1670.                             wires[i].curr_in_init <= 18'h00004;
  1671.                             wires[i].prev_in_init <= 18'h00004;
  1672.                         end
  1673.                         238: begin
  1674.                             wires[i].curr_in_init <= 18'h00001;
  1675.                             wires[i].prev_in_init <= 18'h00001;
  1676.                         end
  1677.                         239: begin
  1678.                             wires[i].curr_in_init <= 18'h00006;
  1679.                             wires[i].prev_in_init <= 18'h00006;
  1680.                         end
  1681.                         240: begin
  1682.                             wires[i].curr_in_init <= 18'h00018;
  1683.                             wires[i].prev_in_init <= 18'h00018;
  1684.                         end
  1685.                         241: begin
  1686.                             wires[i].curr_in_init <= 18'h00049;
  1687.                             wires[i].prev_in_init <= 18'h00049;
  1688.                         end
  1689.                         242: begin
  1690.                             wires[i].curr_in_init <= 18'h000b4;
  1691.                             wires[i].prev_in_init <= 18'h000b4;
  1692.                         end
  1693.                         243: begin
  1694.                             wires[i].curr_in_init <= 18'h0016c;
  1695.                             wires[i].prev_in_init <= 18'h0016c;
  1696.                         end
  1697.                         244: begin
  1698.                             wires[i].curr_in_init <= 18'h00258;
  1699.                             wires[i].prev_in_init <= 18'h00258;
  1700.                         end
  1701.                         245: begin
  1702.                             wires[i].curr_in_init <= 18'h0032a;
  1703.                             wires[i].prev_in_init <= 18'h0032a;
  1704.                         end
  1705.                         246: begin
  1706.                             wires[i].curr_in_init <= 18'h0037f;
  1707.                             wires[i].prev_in_init <= 18'h0037f;
  1708.                         end
  1709.                         247: begin
  1710.                             wires[i].curr_in_init <= 18'h0032a;
  1711.                             wires[i].prev_in_init <= 18'h0032a;
  1712.                         end
  1713.                         248: begin
  1714.                             wires[i].curr_in_init <= 18'h00258;
  1715.                             wires[i].prev_in_init <= 18'h00258;
  1716.                         end
  1717.                         249: begin
  1718.                             wires[i].curr_in_init <= 18'h0016c;
  1719.                             wires[i].prev_in_init <= 18'h0016c;
  1720.                         end
  1721.                         250: begin
  1722.                             wires[i].curr_in_init <= 18'h000b4;
  1723.                             wires[i].prev_in_init <= 18'h000b4;
  1724.                         end
  1725.                         251: begin
  1726.                             wires[i].curr_in_init <= 18'h00049;
  1727.                             wires[i].prev_in_init <= 18'h00049;
  1728.                         end
  1729.                         252: begin
  1730.                             wires[i].curr_in_init <= 18'h00018;
  1731.                             wires[i].prev_in_init <= 18'h00018;
  1732.                         end
  1733.                         253: begin
  1734.                             wires[i].curr_in_init <= 18'h00006;
  1735.                             wires[i].prev_in_init <= 18'h00006;
  1736.                         end
  1737.                         254: begin
  1738.                             wires[i].curr_in_init <= 18'h00001;
  1739.                             wires[i].prev_in_init <= 18'h00001;
  1740.                         end
  1741.                         255: begin
  1742.                             wires[i].curr_in_init <= 18'h00000;
  1743.                             wires[i].prev_in_init <= 18'h00000;
  1744.                         end
  1745.                         256: begin
  1746.                             wires[i].curr_in_init <= 18'h00001;
  1747.                             wires[i].prev_in_init <= 18'h00001;
  1748.                         end
  1749.                         257: begin
  1750.                             wires[i].curr_in_init <= 18'h00006;
  1751.                             wires[i].prev_in_init <= 18'h00006;
  1752.                         end
  1753.                         258: begin
  1754.                             wires[i].curr_in_init <= 18'h00014;
  1755.                             wires[i].prev_in_init <= 18'h00014;
  1756.                         end
  1757.                         259: begin
  1758.                             wires[i].curr_in_init <= 18'h00031;
  1759.                             wires[i].prev_in_init <= 18'h00031;
  1760.                         end
  1761.                         260: begin
  1762.                             wires[i].curr_in_init <= 18'h00063;
  1763.                             wires[i].prev_in_init <= 18'h00063;
  1764.                         end
  1765.                         261: begin
  1766.                             wires[i].curr_in_init <= 18'h000a3;
  1767.                             wires[i].prev_in_init <= 18'h000a3;
  1768.                         end
  1769.                         262: begin
  1770.                             wires[i].curr_in_init <= 18'h000dc;
  1771.                             wires[i].prev_in_init <= 18'h000dc;
  1772.                         end
  1773.                         263: begin
  1774.                             wires[i].curr_in_init <= 18'h000f4;
  1775.                             wires[i].prev_in_init <= 18'h000f4;
  1776.                         end
  1777.                         264: begin
  1778.                             wires[i].curr_in_init <= 18'h000dc;
  1779.                             wires[i].prev_in_init <= 18'h000dc;
  1780.                         end
  1781.                         265: begin
  1782.                             wires[i].curr_in_init <= 18'h000a3;
  1783.                             wires[i].prev_in_init <= 18'h000a3;
  1784.                         end
  1785.                         266: begin
  1786.                             wires[i].curr_in_init <= 18'h00063;
  1787.                             wires[i].prev_in_init <= 18'h00063;
  1788.                         end
  1789.                         267: begin
  1790.                             wires[i].curr_in_init <= 18'h00031;
  1791.                             wires[i].prev_in_init <= 18'h00031;
  1792.                         end
  1793.                         268: begin
  1794.                             wires[i].curr_in_init <= 18'h00014;
  1795.                             wires[i].prev_in_init <= 18'h00014;
  1796.                         end
  1797.                         269: begin
  1798.                             wires[i].curr_in_init <= 18'h00006;
  1799.                             wires[i].prev_in_init <= 18'h00006;
  1800.                         end
  1801.                         270: begin
  1802.                             wires[i].curr_in_init <= 18'h00001;
  1803.                             wires[i].prev_in_init <= 18'h00001;
  1804.                         end
  1805.                         271: begin
  1806.                             wires[i].curr_in_init <= 18'h00000;
  1807.                             wires[i].prev_in_init <= 18'h00000;
  1808.                         end
  1809.                         272: begin
  1810.                             wires[i].curr_in_init <= 18'h00000;
  1811.                             wires[i].prev_in_init <= 18'h00000;
  1812.                         end
  1813.                         273: begin
  1814.                             wires[i].curr_in_init <= 18'h00000;
  1815.                             wires[i].prev_in_init <= 18'h00000;
  1816.                         end
  1817.                         274: begin
  1818.                             wires[i].curr_in_init <= 18'h00001;
  1819.                             wires[i].prev_in_init <= 18'h00001;
  1820.                         end
  1821.                         275: begin
  1822.                             wires[i].curr_in_init <= 18'h00004;
  1823.                             wires[i].prev_in_init <= 18'h00004;
  1824.                         end
  1825.                         276: begin
  1826.                             wires[i].curr_in_init <= 18'h0000a;
  1827.                             wires[i].prev_in_init <= 18'h0000a;
  1828.                         end
  1829.                         277: begin
  1830.                             wires[i].curr_in_init <= 18'h00016;
  1831.                             wires[i].prev_in_init <= 18'h00016;
  1832.                         end
  1833.                         278: begin
  1834.                             wires[i].curr_in_init <= 18'h00024;
  1835.                             wires[i].prev_in_init <= 18'h00024;
  1836.                         end
  1837.                         279: begin
  1838.                             wires[i].curr_in_init <= 18'h00031;
  1839.                             wires[i].prev_in_init <= 18'h00031;
  1840.                         end
  1841.                         280: begin
  1842.                             wires[i].curr_in_init <= 18'h00036;
  1843.                             wires[i].prev_in_init <= 18'h00036;
  1844.                         end
  1845.                         281: begin
  1846.                             wires[i].curr_in_init <= 18'h00031;
  1847.                             wires[i].prev_in_init <= 18'h00031;
  1848.                         end
  1849.                         282: begin
  1850.                             wires[i].curr_in_init <= 18'h00024;
  1851.                             wires[i].prev_in_init <= 18'h00024;
  1852.                         end
  1853.                         283: begin
  1854.                             wires[i].curr_in_init <= 18'h00016;
  1855.                             wires[i].prev_in_init <= 18'h00016;
  1856.                         end
  1857.                         284: begin
  1858.                             wires[i].curr_in_init <= 18'h0000a;
  1859.                             wires[i].prev_in_init <= 18'h0000a;
  1860.                         end
  1861.                         285: begin
  1862.                             wires[i].curr_in_init <= 18'h00004;
  1863.                             wires[i].prev_in_init <= 18'h00004;
  1864.                         end
  1865.                         286: begin
  1866.                             wires[i].curr_in_init <= 18'h00001;
  1867.                             wires[i].prev_in_init <= 18'h00001;
  1868.                         end
  1869.                         287: begin
  1870.                             wires[i].curr_in_init <= 18'h00000;
  1871.                             wires[i].prev_in_init <= 18'h00000;
  1872.                         end
  1873.                         288: begin
  1874.                             wires[i].curr_in_init <= 18'h00000;
  1875.                             wires[i].prev_in_init <= 18'h00000;
  1876.                         end
  1877.                         default: begin
  1878.                             wires[i].curr_in_init <= 18'h00000;
  1879.                             wires[i].prev_in_init <= 18'h00000;
  1880.                         end
  1881.                     endcase
  1882.                 end //else
  1883.             end //always
  1884.         end //for
  1885.     endgenerate
  1886. endmodule
  1887.  
  1888. //each column module uses a single multiplier to sequentially calculate updates for the entire column
  1889. //the module contains 2 M10K blocks, one storing current values and one storing the values at the previous time step
  1890. //the state machine coordinates the movement of data between the memory blocks, several registers, and neighboring columns
  1891. module column(
  1892.     input CLOCK_50, reset, start,
  1893.     input [8:0] curr_wradd_init, prev_wradd_init,
  1894.     input [17:0] curr_in_init, prev_in_init,
  1895.     input signed [17:0] iminus, iplus, rho,
  1896.     input [4:0] etadt,
  1897.     output signed [17:0] jplus_out, sound,
  1898.     input [8:0] column_size,
  1899. );
  1900.  
  1901.     reg [3:0] state;
  1902.     reg [8:0] row;
  1903.    
  1904.     //inputs and outputs of M10K blocks
  1905.     wire [17:0] curr_out, prev_out;
  1906.     reg [17:0] curr_in, prev_in;
  1907.     reg [8:0] curr_wradd, curr_rdadd, prev_wradd, prev_rdadd;
  1908.     reg curr_wren, curr_rden, prev_wren, prev_rden;
  1909.    
  1910.     //inputs and output of solver module
  1911.     reg [17:0] jminus, pos;
  1912.     wire[17:0] solv_out, jplus;
  1913.     //jplus gets the value of the node in the positive j direction, except it is assigned to 0 at the top edge of the drum
  1914.     assign jplus = (state == 4'd9) ? 18'd0 : curr_out;
  1915.     //the output of the current position, used by neighboring nodes as iminus or iplus
  1916.     assign jplus_out = pos;
  1917.    
  1918.     //sound = value at the middle node when we reach the middle row, otherwise its value does not change during other rows
  1919.     reg[17:0] mid_node;
  1920.     assign sound = mid_node;
  1921.     always @ (posedge CLOCK_50) begin
  1922.         if (reset) begin
  1923.             if (row == (column_size+1)/2)
  1924.                 mid_node <= curr_in;
  1925.             else
  1926.                 mid_node <= mid_node;
  1927.         end
  1928.         else begin
  1929.             mid_node <= 0;
  1930.         end
  1931.     end
  1932.    
  1933.     always @ (posedge CLOCK_50) begin
  1934.         if (reset==0) begin
  1935.             state <= 0;
  1936.             row <= 0;
  1937.             curr_rdadd <= 0;
  1938.             prev_rdadd <= 0;   
  1939.             curr_rden <= 0;
  1940.             prev_rden <= 0;
  1941.             // continuously load initial values into m10k while reset low
  1942.             curr_wren <= 1;
  1943.             prev_wren <= 1;
  1944.             curr_wradd <= curr_wradd_init;
  1945.             prev_wradd <= prev_wradd_init;
  1946.             curr_in <= curr_in_init;
  1947.             prev_in <= prev_in_init;
  1948.  
  1949.         end
  1950.         // stop writing initial values when reset is released
  1951.         if (state==4'd0 && reset==1) begin
  1952.             state <= 4'd1;
  1953.             row <= 9'd0;
  1954.             curr_wren <= 0;
  1955.             prev_wren <= 0;
  1956.             curr_wradd <= 9'd0;
  1957.             prev_wradd <= 9'd0;
  1958.         end
  1959.        
  1960.         //wait in state 1 for start signal from the top level module
  1961.         if (state==4'd1 && start==0 && reset==1) begin
  1962.             state <= 4'd1;
  1963.             curr_wren <= 0;
  1964.             prev_wren <= 0;
  1965.         end
  1966.         //states 1-4 are building up the pipeline, beginning with longer latency read requests and then moving and writing values
  1967.         if (state==4'd1 && start==1 && reset==1) begin
  1968.             state <= 4'd2;
  1969.             curr_wren <= 0;
  1970.             prev_wren <= 0;
  1971.             curr_rdadd <= 9'd0;
  1972.             curr_rden <= 1;
  1973.         end
  1974.         if (state==4'd2 && reset==1) begin
  1975.             state <= 4'd3;
  1976.             curr_wren <= 0;
  1977.             prev_wren <= 0;
  1978.             curr_rdadd <= 9'd1;
  1979.             prev_rdadd <= 9'd0;
  1980.             prev_rden <= 1;
  1981.         end
  1982.         if (state==4'd3 && reset==1) begin
  1983.             state <= 4'd4;
  1984.             curr_rdadd <= 9'd2;
  1985.             prev_rdadd <= 9'd1;
  1986.         end
  1987.         if (state==4'd4 && reset==1) begin
  1988.             state <= 4'd5;
  1989.             curr_rdadd <= 9'd3;
  1990.             prev_rdadd <= 9'd2;
  1991.             pos <= jplus;
  1992.             jminus <= 18'd0;
  1993.         end
  1994.         //state 5 is when the pipeline is completely full, and we remain here until we near the top edge
  1995.         if (state==4'd5 && reset==1) begin
  1996.             if (row < column_size-4)
  1997.                 state <= 4'd5;
  1998.             else
  1999.                 state <= 4'd6;
  2000.             curr_rdadd <= row+9'd4;
  2001.             prev_rdadd <= row+9'd3;
  2002.             jminus <= pos;
  2003.             pos <= jplus;
  2004.             curr_wradd <= row;
  2005.             prev_wradd <= row;
  2006.             curr_wren <= 1;
  2007.             prev_wren <= 1;
  2008.             curr_in <= solv_out;
  2009.             prev_in <= pos;
  2010.             row <= row+9'd1;
  2011.         end
  2012.         //state 6-9 empty the pipeline and then we return to state 1 to wait for the next start signal
  2013.         if (state==4'd6 && reset==1) begin
  2014.             state <= 4'd7;
  2015.             curr_rdadd <= 9'd0;
  2016.             curr_rden <= 0;
  2017.             prev_rdadd <= row+9'd3;
  2018.             jminus <= pos;
  2019.             pos <= jplus;
  2020.             curr_wradd <= row;
  2021.             prev_wradd <= row;
  2022.             curr_in <= solv_out;
  2023.             prev_in <= pos;
  2024.             row <= row+9'd1;
  2025.         end
  2026.         if (state==4'd7 && reset==1) begin //row = column_size-3 at start of state
  2027.             state <= 4'd8;
  2028.             prev_rdadd <= 9'd0;
  2029.             prev_rden <= 0;
  2030.             jminus <= pos;
  2031.             pos <= jplus;
  2032.             curr_wradd <= row;
  2033.             prev_wradd <= row;
  2034.             curr_in <= solv_out;
  2035.             prev_in <= pos;
  2036.             row <= row+9'd1;
  2037.         end
  2038.         if (state==4'd8 && reset==1) begin //row = column_size-2 at start of state
  2039.             state <= 4'd9;         
  2040.             jminus <= pos;
  2041.             pos <= 18'd0;
  2042.             curr_wradd <= row;
  2043.             prev_wradd <= row;
  2044.             curr_in <= solv_out;
  2045.             prev_in <= pos;
  2046.             row <= row+9'd1;
  2047.         end
  2048.         if (state==4'd9 && reset==1) begin //row = last row at start of state
  2049.             state <= 4'd1;
  2050.             curr_wradd <= row;
  2051.             prev_wradd <= row;
  2052.             curr_in <= solv_out;
  2053.             prev_in <= pos;
  2054.             row <= 9'd0;
  2055.         end
  2056.        
  2057.    
  2058.     end
  2059.    
  2060.     IPM10K curr(.q(curr_out),
  2061.                  .data(curr_in),
  2062.                  .wraddress(curr_wradd),
  2063.                  .rdaddress(curr_rdadd),
  2064.                  .wren(curr_wren),
  2065.                  .rden(curr_rden),
  2066.                  .clock(CLOCK_50));
  2067.                
  2068.     IPM10K prev(.q(prev_out),
  2069.                  .data(prev_in),
  2070.                  .wraddress(prev_wradd),
  2071.                  .rdaddress(prev_rdadd),
  2072.                  .wren(prev_wren),
  2073.                  .rden(prev_rden),
  2074.                  .clock(CLOCK_50));
  2075.                
  2076.     solver s(.iminus(iminus),
  2077.                 .iplus(iplus),
  2078.                 .jminus(jminus),
  2079.                 .jplus(jplus),
  2080.                 .pos(pos),
  2081.                 .posOld(prev_out),
  2082.                 .rho(rho),
  2083.                 .etadt(etadt),
  2084.                 .out(solv_out));
  2085. endmodule
  2086.  
  2087. //there is one solver module contained inside each column module
  2088. //the column feeds the solver inputs according to its state machine, and the solver combinationally finds the output
  2089. module solver(
  2090.     input signed[17:0] iminus, iplus, jminus, jplus, pos, posOld, rho,
  2091.     input [4:0] etadt,
  2092.     output signed[17:0] out);
  2093.    
  2094. //=======================================================
  2095. //  REG/WIRE declarations
  2096. //=======================================================
  2097.  
  2098.     wire signed [17:0] tempim, tempip, tempjm, tempjp, tempsum,
  2099.                temprho, tempold, tempbig;
  2100.  
  2101. //=======================================================
  2102. //  Structural coding
  2103. //=======================================================
  2104.    
  2105.     //we split up the overall calculation into chunks to minimize the chances of overflow occurring
  2106.     assign tempim = iminus - pos;
  2107.     assign tempip = iplus - pos;
  2108.     assign tempjm = jminus - pos;
  2109.     assign tempjp = jplus - pos;
  2110.     assign tempsum = tempim + tempip + tempjm + tempjp;
  2111.     signed_mult rhoMult(temprho, tempsum, rho);
  2112.     assign tempold = pos - posOld + (posOld >>> etadt);
  2113.     assign tempbig = temprho + pos + tempold;
  2114.     assign out = tempbig - (tempbig >>> etadt);
  2115.  
  2116. endmodule
  2117.  
  2118. // the 1.17 signed fixed point multiplier
  2119. module signed_mult (out, a, b);
  2120.     output      [17:0]  out;
  2121.     input   signed  [17:0]  a;
  2122.     input   signed  [17:0]  b;
  2123.    
  2124.     wire    signed  [17:0]  out;
  2125.     wire    signed  [35:0]  mult_out;
  2126.  
  2127.     assign mult_out = a * b;
  2128.     assign out = {mult_out[35], mult_out[33:17]};
  2129.  
  2130. endmodule
  2131.  
  2132. //////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement