direction and start stop now working
This commit is contained in:
+2
-2
@@ -34,10 +34,10 @@ always@(posedge clk) begin
|
|||||||
if (r_adder >= max )begin
|
if (r_adder >= max )begin
|
||||||
r_adder <= 0;
|
r_adder <= 0;
|
||||||
if (direction) begin
|
if (direction) begin
|
||||||
r_counter <= r_counter + 1;
|
r_counter <= r_counter - 1;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
r_counter <= r_counter - 1;
|
r_counter <= r_counter + 1;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
|
|||||||
+10
-12
@@ -16,17 +16,15 @@
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
module flip_flop (
|
module flip_flop (
|
||||||
input clk,
|
input start,
|
||||||
input rst,
|
output out);
|
||||||
input t,
|
|
||||||
output reg q);
|
reg r_out = 1'b0;
|
||||||
|
|
||||||
|
always@(posedge start) begin
|
||||||
|
r_out <= ~r_out;
|
||||||
|
end
|
||||||
|
|
||||||
|
assign out = r_out;
|
||||||
|
|
||||||
always @ (posedge clk) begin
|
|
||||||
if (!rst)
|
|
||||||
q <= 0;
|
|
||||||
else if (t)
|
|
||||||
q <= ~q;
|
|
||||||
else
|
|
||||||
q <= q;
|
|
||||||
end
|
|
||||||
endmodule
|
endmodule
|
||||||
+14
-8
@@ -6,7 +6,7 @@
|
|||||||
//
|
//
|
||||||
// Detailed module description:
|
// Detailed module description:
|
||||||
//
|
//
|
||||||
// This is SR latch for swoching
|
// This is SR latch for swiching
|
||||||
// between UP or DOWN counting
|
// between UP or DOWN counting
|
||||||
//
|
//
|
||||||
// Revision:
|
// Revision:
|
||||||
@@ -16,13 +16,19 @@
|
|||||||
//
|
//
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
module sr_latch(
|
module sr_latch(
|
||||||
input wire S, R, C,
|
input wire clk, up, down,
|
||||||
output reg Q, notQ
|
output wire out
|
||||||
);
|
);
|
||||||
|
|
||||||
always@(S, R, C, Q, notQ)
|
reg r_out = 1'b0;
|
||||||
if(C) begin
|
|
||||||
Q <= (~R & Q) | S;
|
always@(posedge clk) begin
|
||||||
Q <= (~S & Q) | R;
|
case ({up,down})
|
||||||
end
|
2'b01 : r_out <= 0;
|
||||||
|
2'b10 : r_out <= 1;
|
||||||
|
default : r_out <= r_out;
|
||||||
|
endcase
|
||||||
|
end
|
||||||
|
assign out = r_out;
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ counter counter(
|
|||||||
.clk(clk16Hz),
|
.clk(clk16Hz),
|
||||||
.reset(w_reset),
|
.reset(w_reset),
|
||||||
.direction(w_direction),
|
.direction(w_direction),
|
||||||
.enable(1'b1),
|
.enable(w_enable),
|
||||||
.max(sw),
|
.max(sw),
|
||||||
.counter(w_counter)
|
.counter(w_counter)
|
||||||
);
|
);
|
||||||
@@ -96,28 +96,17 @@ debounce_switch debounce_start(
|
|||||||
.o_switch(w_start)
|
.o_switch(w_start)
|
||||||
);
|
);
|
||||||
|
|
||||||
// flip_flop flip_flop(
|
sr_latch up_down_latch(
|
||||||
// .clk(clk),
|
.clk(clk),
|
||||||
// .rst(1'b1),
|
.up(~w_up),
|
||||||
// .t(w_start),
|
.down(~w_down),
|
||||||
// .q(w_enable)
|
.out(w_direction)
|
||||||
// );
|
|
||||||
|
|
||||||
sr_latch sr_latch(
|
|
||||||
.C(clk),
|
|
||||||
.S(~w_up),
|
|
||||||
.R(~w_down),
|
|
||||||
.Q(w_direction),
|
|
||||||
.notQ()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// sr_latch start_latch(
|
flip_flop start_stop_flipflop(
|
||||||
// .C(clk),
|
.start(w_start),
|
||||||
// .S(~w_start),
|
.out(w_enable)
|
||||||
// .R(~w_start&w_enable),
|
);
|
||||||
// .Q(w_enable),
|
|
||||||
// .notQ()
|
|
||||||
// );
|
|
||||||
|
|
||||||
bin_7segment bin_7segment(
|
bin_7segment bin_7segment(
|
||||||
.clk(clk1kHz), // clock working with 10kHz
|
.clk(clk1kHz), // clock working with 10kHz
|
||||||
|
|||||||
Reference in New Issue
Block a user