ecasha
Junior Member level 2
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 module trai1enc( din ,clk ,reset ,dout ); output [2:0] dout ; wire [2:0] dout ; input [3:0] din ; input clk ; wire clk ; input reset ; wire reset ; reg [2:0]s; initial s=0; assign din[0]=1; assign din[1]=0; assign din[2]=0; assign din[3]=1; genvar i; for (i=0;i<=3;i=i+1) begin if (i==0)begin //i=0 always @ (posedge (clk)) begin if (reset) s <= 0; else begin s[2] <= din[0]; s[1] <= s[2]; s[0] <= s[1]; end end assign dout = s; end else if (i==1)begin //i=1 always @ (posedge (clk)) begin if (reset) s <= 0; else begin s[2] <= din[1]; s[1] <= s[2]; s[0] <= s[1]; end end assign dout = s; end else if (i==2)begin //i=2 always @ (posedge (clk)) begin if (reset) s <= 0; else begin s[2] <= din[2]; s[1] <= s[2]; s[0] <= s[1]; end end assign dout = s; end else begin always @ (posedge (clk)) begin //i=3 if (reset) s <= 0; else begin s[2] <= din[3]; s[1] <= s[2]; s[0] <= s[1]; end end assign dout = s; end end endmodule
I want to give the input in code itself.I dont want to use testbench to give different serial inputs. I n above code i have used for loop but index is not incrementing how to write the code?please suggest me
Last edited by a moderator: