Debian Codegraph @

examples/oser16.v

raw
1 `default_nettype none
2 /*
3 * This example allows you to generate OSER16 primitive and then check
4 * it 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 io16,
10 output wire pclk_o,
11 output wire fclk_o);
12
13 wire rst = rst_i ^ `INV_BTN;
14 OSER16 oser(
15 .D0(1'b0),
16 .D1(1'b1),
17 .D2(1'b0),
18 .D3(1'b1),
19 .D4(1'b0),
20 .D5(1'b1),
21 .D6(1'b0),
22 .D7(1'b1),
23 .D8(1'b0),
24 .D9(1'b1),
25 .D10(1'b0),
26 .D11(1'b1),
27 .D12(1'b0),
28 .D13(1'b1),
29 .D14(1'b0),
30 .D15(1'b1),
31 .FCLK(fclk_w),
32 .PCLK(pclk_o),
33 .RESET(1'b0),
34 .Q(io16)
35 );
36 defparam oser.GSREN = "false";
37 defparam oser.LSREN = "true";
38
39 wire clk_w;
40 wire pclk_w;
41 wire fclk_w;
42
43 assign pclk_o = pclk_w;
44 assign fclk_o = fclk_w;
45
46 reg [2:0]pclk_r;
47 wire fclk_w;
48
49 always @(posedge fclk_w) begin
50 if (!rst) begin
51 pclk_r <= 3'b00;
52 end else begin
53 pclk_r <= pclk_r + 3'b01;
54 end
55 end
56 assign pclk_w = pclk_r[2];
57
58 // slow
59 reg [24:0] ctr_q;
60 wire [24:0] ctr_d;
61 wire tick_w;
62
63 // Sequential code (flip-flop)
64 always @(posedge clk)
65 ctr_q <= ctr_d;
66
67 // Combinational code (boolean logic)
68 assign ctr_d = ctr_q + 1'b1;
69 assign tick_w = ctr_q[24];
70
71 assign fclk_w = tick_w;
72 endmodule