Debian Codegraph @

examples/oser10.v

raw
1 `default_nettype none
2 /*
3 * This example allows you to generate OSER10 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 oser_out,
10 output wire pclk_o,
11 output wire fclk_o);
12
13 wire rst = rst_i ^ `INV_BTN;
14 OSER10 os(
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 .FCLK(fclk_w),
26 .PCLK(pclk_w),
27 .RESET(1'b0),
28 .Q(oser_out)
29 );
30 defparam os.GSREN = "false";
31 defparam os.LSREN = "true";
32
33 wire clk_w;
34 wire pclk_w;
35 wire fclk_w;
36
37 assign pclk_o = pclk_w;
38 assign fclk_o = fclk_w;
39
40 reg [2:0] count;
41 wire clkA;
42 reg clkB;
43 always @(posedge fclk_w) begin
44 if (!rst) begin
45 count <= 0;
46 end else begin
47 if (count == 3'd4) begin
48 count <= 0;
49 end else begin
50 count <= count+1;
51 end
52 end
53 end
54 assign clkA = count[1];
55
56 always@(negedge fclk_w) begin
57 clkB <= clkA;
58 end
59 assign pclk_w = clkA | clkB;
60
61 // slow
62 reg [24:0] ctr_q;
63 wire [24:0] ctr_d;
64 wire tick_w;
65
66 // Sequential code (flip-flop)
67 always @(posedge clk)
68 ctr_q <= ctr_d;
69
70 // Combinational code (boolean logic)
71 assign ctr_d = ctr_q + 1'b1;
72 assign tick_w = ctr_q[24];
73
74 assign fclk_w = tick_w;
75 endmodule