-
Notifications
You must be signed in to change notification settings - Fork 0
/
A1.m
48 lines (38 loc) · 1.34 KB
/
A1.m
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
module top
(
input CLK, // CLK
input i_PhotoResistor, // PIN 14
output o_PRBSToLaser, // pin 15
output o_Shift_0, // pin 20
output o_Shift_1, // pin 19
output o_Shift_2, // pin 18
output o_Shift_3, // pin 17
output o_TestLED, // pin 13
);
// drive USB pull-up resistor to '0' to disable USB
assign USBPU = 0;
wire w_xor;
reg [15:0] r_Shift = 16'b1000000000000000;
// Clock reduction - 16MHz/2097152 = 7.63Hz - 21 bits = 2097152
reg [23:0] r_ReduceCLK = 24'b000000000000000000000000;
reg [23:0] r_ClkLimit = 24'b000000000000001111101000; // 2097152
always @(posedge CLK)
begin
if (r_ReduceCLK < r_ClkLimit)
r_ReduceCLK <= r_ReduceCLK + 1;
else if (r_ReduceCLK >= r_ClkLimit)
r_ReduceCLK <= 24'b000000000000000000000000;
end
always @(posedge r_ReduceCLK < 1)
begin
r_Shift <= r_Shift << 1;
r_Shift[0] <= w_xor; // FIX THIS, NOT UPDATING FAST ENOUGH
end
assign w_xor = r_Shift[10] ^ ((r_Shift[13] ^ r_Shift[15]) ^ r_Shift[11]);
assign o_PRBSToLaser = w_xor;
assign o_Shift_0 = r_Shift[0];
assign o_Shift_1 = r_Shift[1];
assign o_Shift_2 = r_Shift[2];
assign o_Shift_3 = r_Shift[3];
assign o_TestLED = ~i_PhotoResistor;
endmodule