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

Subversion Repositories pit

[/] [pit/] [trunk/] [rtl/] [verilog/] [pit_count.v] - Blame information for rev 23

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

Line No. Rev Author Line
1 2 rehayes
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  Programable Interrupt Timer - Main Counter
4
//
5
//  Author: Bob Hayes
6
//          rehayes@opencores.org
7
//
8
//  Downloaded from: http://www.opencores.org/projects/pit.....
9
//
10
////////////////////////////////////////////////////////////////////////////////
11
// Copyright (c) 2009, Robert Hayes
12
//
13
// All rights reserved.
14
//
15
// Redistribution and use in source and binary forms, with or without
16
// modification, are permitted provided that the following conditions are met:
17
//     * Redistributions of source code must retain the above copyright
18
//       notice, this list of conditions and the following disclaimer.
19
//     * Redistributions in binary form must reproduce the above copyright
20
//       notice, this list of conditions and the following disclaimer in the
21
//       documentation and/or other materials provided with the distribution.
22
//     * Neither the name of the <organization> nor the
23
//       names of its contributors may be used to endorse or promote products
24
//       derived from this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
30
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
////////////////////////////////////////////////////////////////////////////////
37
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
38
 
39
module pit_count #(parameter COUNT_SIZE = 16)
40
  (
41
  output reg [COUNT_SIZE-1:0] cnt_n,         // Modulo Counter value
42
  output reg                  cnt_flag_o,    // Counter Rollover Flag
43
  output reg                  pit_o,         // PIT output pulse
44
  input                       async_rst_b,   //
45
  input                       sync_reset,    // Syncronous reset signal
46
  input                       bus_clk,       // Reference Clock
47
  input                       counter_sync,  // Syncronous counter enable
48
  input                       prescale_out,  // Increment Counter
49
  input                       pit_flg_clr,   // Clear PIT Rollover Flag
50
  input      [COUNT_SIZE-1:0] mod_value      // Count Divisor
51
  );
52
 
53
// Warning: This counter has no saftynet if the mod_value changes while the counter
54
//           is active. There may need to be an addtional latch register for
55
//           "mod_value" that captures on the falling edge of "counter_sync" or
56
//           when "cnt_n" rolls over to eliminate this problem.
57
 
58
 
59
wire rollover;      // Counter has reached the mod_value
60
wire no_div;        // Modulo set for Zero or One
61
wire clear_counter; // Set counter to initial state
62
 
63
assign no_div = (mod_value == 1) || ~|mod_value;
64
 
65
assign rollover = ((cnt_n == mod_value) || no_div) && prescale_out;
66
 
67
assign clear_counter = !counter_sync;
68
 
69
//  Div N Counter
70
always @(posedge bus_clk or negedge async_rst_b)
71
  if ( !async_rst_b )
72
    cnt_n  <= 1;
73
  else if ( clear_counter || rollover || no_div)
74
    cnt_n  <= 1;
75
  else if ( prescale_out )
76
    cnt_n  <= cnt_n + 1;
77
 
78
//  Counter Rollover Flag and Interrupt
79
always @(posedge bus_clk or negedge async_rst_b)
80
  if ( !async_rst_b )
81
    cnt_flag_o <= 0;
82
  else if ( clear_counter || pit_flg_clr)
83
    cnt_flag_o <= 0;
84
  else if ( rollover )
85
    cnt_flag_o <= 1;
86
 
87
//  PIT Output Register
88
always @(posedge bus_clk or negedge async_rst_b)
89
  if ( !async_rst_b )
90
    pit_o <= 0;
91
  else
92
    pit_o <= rollover && counter_sync && !sync_reset;
93
 
94
endmodule  // pit_count
95
 

powered by: WebSVN 2.1.0

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