always @(posedge clk) begin if(shift_ena) begin q_temp <= {q_temp[2:0],data}; end elseif(count_ena) begin if(q_temp == 4'd0) begin q_temp <= 4'd15; end elsebegin q_temp <= q_temp - 1'b1; end end end
always @(*) begin if(num <= 16'd1000) begin already_count = 4'd0; end elseif(num > 16'd1000 && num <= 16'd2000) begin already_count = 4'd1; end elseif(num > 16'd2000 && num <= 16'd3000) begin already_count = 4'd2; end elseif(num > 16'd3000 && num <= 16'd4000) begin already_count = 4'd3; end elseif(num > 16'd4000 && num <= 16'd5000) begin already_count = 4'd4; end elseif(num > 16'd5000 && num <= 16'd6000) begin already_count = 4'd5; end elseif(num > 16'd6000 && num <= 16'd7000) begin already_count = 4'd6; end elseif(num > 16'd7000 && num <= 16'd8000) begin already_count = 4'd7; end elseif(num > 16'd8000 && num <= 16'd9000) begin already_count = 4'd8; end elseif(num > 16'd9000 && num <= 16'd10000) begin already_count = 4'd9; end elseif(num > 16'd10000 && num <= 16'd11000) begin already_count = 4'd10; end elseif(num > 16'd11000 && num <= 16'd12000) begin already_count = 4'd11; end elseif(num > 16'd12000 && num <= 16'd13000) begin already_count = 4'd12; end elseif(num > 16'd13000 && num <= 16'd14000) begin already_count = 4'd13; end elseif(num > 16'd14000 && num <= 16'd15000) begin already_count = 4'd14; end elsebegin already_count = 4'd15; end end
always @(posedge clk) begin if(reset) begin num <= 16'd0; end elseif(next_state == Done) begin num <= 16'd0; end elseif(next_state == Count_1000) begin num <= num + 16'd1; end end
always @(*) begin case(current_state) IDLE: next_state = data ? S1 : IDLE; S1: next_state = data ? S2 : IDLE; S2: next_state = data ? S2 : S3; S3: next_state = data ? C0 : IDLE; C0:begin next_state = C1; delay[3] = data; end C1:begin next_state = C2; delay[2] = data; end C2:begin next_state = C3; delay[1] = data; end C3:begin next_state = Count_1000; delay[0] = data; end Count_1000: next_state = count_state ? Done : Count_1000; Done: next_state = ack ? IDLE : Done; default: next_state = IDLE; endcase end
always @(posedge clk) begin if(reset) begin current_state <= IDLE; end elsebegin current_state <= next_state; end end
// You may use these parameters to access state bits using e.g., state[B2] instead of state[6]. parameter S=0, S1=1, S11=2, S110=3, B0=4, B1=5, B2=6, B3=7, Count=8, Wait=9;