kapaa
Newbie level 4
Hello, The following code is compiled and is working in parallel, Please help me to make these code work sequentially, i.e after stage1 counter should reset itself and starts from 0 for the stage2. The following codes has Module1- stage1 and module2-stage2.
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 module stage1( input Clk, //50 Hz clock input x0, input reset, output reg y0,y1,y2,y3,y5,y7,y10,y15, output reg stage1_done ); reg [15:0] counter = 0; parameter F = 50; always@ (posedge Clk or posedge reset) if(reset) begin counter <= 0; {y0,y1,y2,y3,y5,y7,y10,y15} <= 8'b00000000; stage1_done <= 0; end else begin if(x0 == 1) begin if(counter == 18*F) stage1_done <= 1; else begin counter <= counter + 1; stage1_done <= 0; end if(counter >= 1*F && counter < 10*F) y0 <= 1; else y0 <= 0; if(counter >= 1*F && counter < 17*F) y1 <= 1; else y1 <= 0; if(counter >= 1*F && counter < 9*F) y2 <= 1; else y2 <= 0; if(counter >= 11*F && counter < 16*F) y3 <= 1; else y3 <= 0; if(counter >= 1*F && counter < 18*F) y5 <= 1; else y5 <= 0; if(counter >= 1*F && counter < 5*F) y7 <= 1; else y7 <= 0; if(counter >= 1*F && counter < 5*F) y10 <= 1; else y10 <= 0; if((counter >= 2*F && counter < 9*F) || (counter >= 13*F && counter < 7*F)) y15 <= 1; else y15 <= 0; end end endmodule module stage2( input x0, input Clk, //50 Hz clock input reset, output reg y1,y3,y5, output reg stage2_done ); reg [15:0] counter = 0; parameter F = 50; always@ (posedge Clk or posedge reset) if(reset) begin counter <= 0; {y1,y3,y5} <= 3'b000; stage2_done <= 0; end else begin if(x0 == 1) begin if(counter == 8*F) stage2_done <= 1; else begin counter <= counter + 1; stage2_done <= 0; end if(counter >= 1*F && counter < 8*F) y1 <= 1; else y1 <= 0; if(counter >= 1*F && counter < 8*F) y3 <= 1; else y3 <= 0; if(counter >= 1*F && counter < 8*F) y5 <= 1; else y5 <= 0; end end endmodule
Last edited by a moderator: