Debian Codegraph @

examples/gw5a/ovideo.v

raw
1 `default_nettype none
2 /*
3 * This example allows you to generate several OSER10 primitives and then check
4 * them with a logic analyzer. The PCLK, FCLK and Q outputs of the primitives
5 * are connected to the board pins.
6 */
7 module top(input wire clk,
8 input wire rst_i,
9 output wire tlvds_p,
10 output wire tlvds_n,
11 output wire pclk_o,
12 output wire fclk_o);
13
14 wire rst = rst_i ^ `INV_BTN;
15 wire oser_out;
16 TLVDS_OBUF diff_buf(
17 .O(tlvds_p),
18 .OB(tlvds_n),
19 .I(oser_out)
20 );
21
22 OVIDEO os(
23 .D0(1'b1),
24 .D1(1'b0),
25 .D2(1'b1),
26 .D3(1'b0),
27 .D4(1'b1),
28 .D5(1'b0),
29 .D6(1'b1),
30 .FCLK(fclk_w),
31 .PCLK(pclk_w),
32 .RESET(1'b0),
33 .Q(oser_out)
34 );
35 defparam os.GSREN = "false";
36 defparam os.LSREN = "true";
37
38 wire clk_w;
39 wire pclk_w;
40 wire fclk_w;
41
42 assign pclk_o = pclk_w;
43 assign fclk_o = fclk_w;
44
45 // div by 3.5
46 reg [6:0]cnt_r;
47 reg ps0_r;
48 reg ps3_r;
49 reg ps4_r;
50 always @(posedge fclk_w) begin
51 if (!rst) begin
52 cnt_r[6:0] <= 7'b000_0001;
53 end else begin
54 cnt_r[6:0] <= {cnt_r[5:0], cnt_r[6]};
55 end
56 end
57
58 always @(negedge fclk_w) begin
59 if (!rst) begin
60 ps0_r <= 1'b0;
61 ps3_r <= 1'b0;
62 ps4_r <= 1'b0;
63 end else begin
64 ps0_r <= cnt_r[0];
65 ps3_r <= cnt_r[3];
66 ps4_r <= cnt_r[4];
67 end
68 end
69 assign pclk_w = (ps0_r | cnt_r[0] | cnt_r[1]) | (ps3_r | ps4_r | cnt_r[4]);
70
71 // slow
72 reg [24:0] ctr_q;
73 wire [24:0] ctr_d;
74 wire tick_w;
75
76 // Sequential code (flip-flop)
77 always @(posedge clk)
78 ctr_q <= ctr_d;
79
80 // Combinational code (boolean logic)
81 assign ctr_d = ctr_q + 1'b1;
82 assign tick_w = ctr_q[24];
83
84 assign fclk_w = tick_w;
85 endmodule