OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [peripherals/] [tb/] [counter/] [tb.v] - Blame information for rev 9

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sinclairrf
/*******************************************************************************
2
 *
3
 * Copyright 2013, Sinclair R.F., Inc.
4
 *
5
 * Test bench for counter peripheral.
6
 *
7
 ******************************************************************************/
8
 
9
`timescale 1ns/1ps
10
 
11
module tb;
12
 
13
// 100 MHz clock
14
reg s_clk = 1'b1;
15
always @ (s_clk)
16
  s_clk <= #5 ~s_clk;
17
 
18
reg s_rst = 1'b1;
19
initial begin
20
  repeat (5) @ (posedge s_clk);
21
  s_rst = 1'b0;
22
end
23
 
24
reg [15:0] s_count = 16'd0;
25
always @ (posedge s_clk)
26
  s_count <= s_count + 16'd1;
27
 
28
wire [15:0] s_count_gray = { 1'b0, s_count[1+:15] } ^ s_count;
29
 
30
integer i_n_ones, ix;
31
always @ (s_count_gray) begin
32
  i_n_ones = 0;
33
  for (ix=0; ix<16; ix=ix+1)
34
    if (s_count_gray[ix])
35
      i_n_ones = i_n_ones + 1;
36
end
37
 
38
reg s_strobe = 1'b0;
39
always @ (posedge s_clk)
40
  s_strobe <= (5 <= i_n_ones) && (i_n_ones <= 7);
41
 
42
reg [15:0] s_strobe_count = 16'd0;
43
always @ (posedge s_clk)
44
  if (s_strobe)
45
    s_strobe_count <= s_strobe_count + 1'd1;
46
 
47
wire     [15:0] s_diag;
48
wire            s_diag_wr;
49
wire            s_done;
50
tb_counter uut(
51
  // synchronous reset and processor clock
52
  .i_rst                (s_rst),
53
  .i_clk                (s_clk),
54
  // narrow counter
55
  .i_strobe_narrow      (s_strobe),
56
  // wide counter
57
  .i_strobe_wide        (s_strobe),
58
  // diagnostic output
59
  .o_diag_msb           (s_diag[8+:8]),
60
  .o_diag_lsb           (s_diag[0+:8]),
61
  .o_diag_wr            (s_diag_wr),
62
  // termination signal
63
  .o_done               (s_done)
64
);
65
 
66
always @ (posedge s_clk) begin
67
  if (s_diag_wr)
68
    $display("0x%04H 0x%04H", s_strobe_count, s_diag);
69
end
70
 
71
always @ (posedge s_clk)
72
  if (s_done)
73
    $finish;
74
 
75
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.