-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsid_acc.sv
54 lines (38 loc) · 885 Bytes
/
sid_acc.sv
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
// SID phase accumulator
//
module sid_acc(
input[15:0] freq,
output[23:0] acc,
output[22:0] lfsr,
input test, sync,
input sync_in,
output sync_out,
input clk, clk_en, n_reset
);
bit [23:0] acc_next;
bit [22:0] lfsr_next;
always_ff @(posedge clk, negedge n_reset)
begin
if (!n_reset) begin
acc <= 0;
lfsr <= '1;
end
else if (clk_en) begin
acc <= acc_next;
if (!acc[19] && acc_next[19])
lfsr <= lfsr_next;
end
end
always_comb
begin
acc_next = acc + freq;
lfsr_next = { lfsr[21:0], lfsr[17] ^ lfsr[22] };
if (sync && sync_in)
acc_next = 0;
if (test) begin
acc_next = 0;
lfsr_next = '1;
end
sync_out = !acc[23] && acc_next[23];
end
endmodule