-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshifter.v
49 lines (45 loc) · 851 Bytes
/
shifter.v
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
// Module for shifting frequency. Output DONE signal when done.
// By Chris Li, Grayson Smith, and Carey Zhang.
`timescale 1ns / 1ps
module shifter(Clk, Reset, Start,/*whatever inputs needed*/ Done);
// Inputs
input Clk, Reset;
input Start;
// Outputs
output reg Done;
// Locals
reg [2:0] count;
localparam TERMINAL = 3'b111;
reg state; // 0 = idle, 1 = counting
localparam IDLE=1'b0, COUNTING=1'b1;
// Implementation logic
// Just counting
always @(posedge Clk, posedge Reset)
begin
if (Reset)
begin
count <= 0;
state <= IDLE;
Done <= 0;
end
else
case (state)
IDLE:
begin
if (Start)
state<=COUNTING;
Done <= 0;
count <= 0;
end
COUNTING:
begin
if (count == TERMINAL)
begin
Done <= 1;
state <= IDLE;
end
count <= count+1;
end
endcase
end
endmodule