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

Subversion Repositories pit

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 1 to Rev 2
    Reverse comparison

Rev 1 → Rev 2

/pit/trunk/rtl/verilog/pit_regs.v
0,0 → 1,136
////////////////////////////////////////////////////////////////////////////////
//
// WISHBONE revB.2 compliant Programable Interrupt Timer - Control registers
//
// Author: Bob Hayes
// rehayes@opencores.org
//
// Downloaded from: http://www.opencores.org/projects/pit.....
//
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009, Robert Hayes
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the <organization> nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////////////////////////////////////////////////////////////////////////////////
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
 
module pit_regs #(parameter ARST_LVL = 1'b0, // asynchronous reset level
parameter COUNT_SIZE = 16,
parameter NO_PRESCALE = 1'b0,
parameter DWIDTH = 16)
(
output reg [COUNT_SIZE-1:0] mod_value, // Main Counter Modulo Value
output [ 3:0] pit_pre_scl, // PIT Prescaler Value
output reg pit_slave, // PIT Slave Mode
output reg pit_flg_clr, // Clear PIT Rollover Flag
output reg pit_ien, // PIT Interrupt Enable
output reg cnt_sync_o, // PIT Counter Enable
output reg pit_irq_o, // PIT interrupt
input bus_clk, // Control register bus clock
input async_rst_b, // Async reset signal
input sync_reset, // Syncronous reset signal
input pit_flag, // PIT Rollover Flag
input [DWIDTH-1:0] write_bus, // Write Data Bus
input [ 3:0] write_regs, // Write Register strobes
input cnt_flag_o // Counter Rollover Flag
);
 
 
// registers
reg [ 3:0] pit_pre; // Optional register for PIT Prescale Counter modulo
// This register should be removed durning synthesis
// if the "NO_PRESCALE" parameter is set
 
// Wires
wire [15:0] write_data; // Data bus mux for 8 or 16 bit module bus
 
//
// module body
//
assign write_data = (DWIDTH == 8) ? {write_bus[7:0], write_bus[7:0]} : write_bus;
assign pit_pre_scl = NO_PRESCALE ? 4'b0 : pit_pre;
 
// generate wishbone write registers
always @(posedge bus_clk or negedge async_rst_b)
if (!async_rst_b)
begin
pit_slave <= 1'b0;
pit_pre <= 4'b0;
pit_flg_clr <= 1'b0;
pit_ien <= 1'b0;
cnt_sync_o <= 1'b0;
mod_value <= 0;
end
else if (sync_reset)
begin
pit_slave <= 1'b0;
pit_pre <= 4'b0;
pit_flg_clr <= 1'b0;
pit_ien <= 1'b0;
cnt_sync_o <= 1'b0;
mod_value <= 0;
end
else
case (write_regs) // synopsys parallel_case
4'b0011 :
begin
pit_slave <= write_data[15];
pit_pre <= write_data[11:8];
pit_flg_clr <= write_data[2];
pit_ien <= write_data[1];
cnt_sync_o <= write_data[0];
end
4'b0001 :
begin
pit_flg_clr <= write_data[2];
pit_ien <= write_data[1];
cnt_sync_o <= write_data[0];
end
4'b0010 :
begin
pit_slave <= write_data[7];
pit_pre <= write_data[3:0];
end
4'b1100 : mod_value <= write_data;
4'b0100 : mod_value[ 7:0] <= write_data[7:0];
4'b1000 : mod_value[15:8] <= write_data[7:0];
default:
pit_flg_clr <= 1'b0;
endcase
 
// generate interrupt request signals
always @(posedge bus_clk or negedge async_rst_b)
if (!async_rst_b)
pit_irq_o <= 0;
else if (sync_reset)
pit_irq_o <= 0;
else
pit_irq_o <= cnt_flag_o && pit_ien; // interrupt signal is only generated
// when IEN (interrupt enable bit is set)
 
 
endmodule // pit_regs
/pit/trunk/rtl/verilog/pit_wb_bus.v
0,0 → 1,120
////////////////////////////////////////////////////////////////////////////////
//
// WISHBONE revB.2 compliant Programable Interrupt Timer - Bus interface
//
// Author: Bob Hayes
// rehayes@opencores.org
//
// Downloaded from: http://www.opencores.org/projects/pit.....
//
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009, Robert Hayes
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the <organization> nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////////////////////////////////////////////////////////////////////////////////
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
 
module pit_wb_bus #(parameter ARST_LVL = 1'b0, // asynchronous reset level
parameter DWIDTH = 16)
(
// Wishbone Signals
output reg [DWIDTH-1:0] wb_dat_o, // databus output
output reg wb_ack_o, // bus cycle acknowledge output
input wb_clk_i, // master clock input
input wb_rst_i, // synchronous active high reset
input arst_i, // asynchronous reset
input [ 2:0] wb_adr_i, // lower address bits
input [DWIDTH-1:0] wb_dat_i, // databus input
input wb_we_i, // write enable input
input wb_stb_i, // stobe/core select signal
input wb_cyc_i, // valid bus cycle input
input [1:0] wb_sel_i, // Select byte in word bus transaction
// PIT Control Signals
output reg [ 3:0] write_regs, // Decode write control register
output async_rst_b, //
output sync_reset, //
input irq_source, //
input [47:0] read_regs // status register bits
);
 
 
// registers
 
// Wires
wire eight_bit_bus;
 
//
// module body
//
 
// generate internal resets
assign eight_bit_bus = (DWIDTH == 8);
 
assign async_rst_b = arst_i ^ ARST_LVL;
assign sync_reset = wb_rst_i;
 
// generate wishbone signals
wire wb_wacc = wb_cyc_i & wb_stb_i & wb_we_i;
 
// generate acknowledge output signal
always @(posedge wb_clk_i)
wb_ack_o <= wb_cyc_i & wb_stb_i & ~wb_ack_o; // because timing is always honored
 
// assign data read bus -- DAT_O
always @(posedge wb_clk_i)
case ({eight_bit_bus, wb_adr_i}) // synopsys parallel_case
// 8 bit Bus, 8 bit Granularity
4'b1_000: wb_dat_o <= read_regs[ 7: 0]; // 8 bit read address 0
4'b1_001: wb_dat_o <= read_regs[15: 8]; // 8 bit read address 1
4'b1_010: wb_dat_o <= read_regs[23:16]; // 8 bit read address 2
4'b1_011: wb_dat_o <= read_regs[31:24]; // 8 bit read address 3
4'b1_100: wb_dat_o <= read_regs[39:32]; // 8 bit read address 4
4'b1_101: wb_dat_o <= read_regs[47:40]; // 8 bit read address 5
// 16 bit Bus, 16 bit Granularity
4'b0_000: wb_dat_o <= read_regs[15: 0]; // 16 bit read access address 0
4'b0_001: wb_dat_o <= read_regs[31:16];
4'b0_010: wb_dat_o <= read_regs[47:32];
endcase
 
// generate wishbone write register strobes -- one hot if 8 bit bus
always @*
begin
write_regs = 0;
if (wb_wacc)
case ({eight_bit_bus, wb_adr_i}) // synopsys parallel_case
// 8 bit Bus, 8 bit Granularity
4'b1_000 : write_regs = 4'b0001;
4'b1_001 : write_regs = 4'b0010;
4'b1_010 : write_regs = 4'b0100;
4'b1_011 : write_regs = 4'b1000;
// 16 bit Bus, 16 bit Granularity
4'b0_000 : write_regs = 4'b0011;
4'b0_001 : write_regs = 4'b1100;
default: ;
endcase
end
 
endmodule // pit_wb_bus
/pit/trunk/rtl/verilog/pit_top.v
0,0 → 1,166
////////////////////////////////////////////////////////////////////////////////
//
// WISHBONE revB.2 compliant Programable Interrupt Timer - Top-level
//
// Author: Bob Hayes
// rehayes@opencores.org
//
// Downloaded from: http://www.opencores.org/projects/pit.....
//
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009, Robert Hayes
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the <organization> nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////////////////////////////////////////////////////////////////////////////////
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
 
module pit_top #(parameter ARST_LVL = 1'b0, // asynchronous reset level
parameter PRE_COUNT_SIZE = 15, // Prescale Counter size
parameter COUNT_SIZE = 16, // Main counter size
parameter DECADE_CNTR = 1'b1, // Prescale rollover decode
parameter NO_PRESCALE = 1'b0, // Remove prescale function
parameter DWIDTH = 16) // Data bus width
(
// Wishbone Signals
output [DWIDTH-1:0] wb_dat_o, // databus output
output wb_ack_o, // bus cycle acknowledge output
input wb_clk_i, // master clock input
input wb_rst_i, // synchronous active high reset
input arst_i, // asynchronous reset
input [2:0] wb_adr_i, // lower address bits
input [DWIDTH-1:0] wb_dat_i, // databus input
input wb_we_i, // write enable input
input wb_stb_i, // stobe/core select signal
input wb_cyc_i, // valid bus cycle input
input [1:0] wb_sel_i, // Select byte in word bus transaction
// PIT IO Signals
output pit_o, // PIT output pulse
output pit_irq_o, // PIT interrupt request signal output
output cnt_flag_o, // PIT Flag Out
output cnt_sync_o, // PIT Master Enable for Slave PIT's
input ext_sync_i // Counter enable from Master PIT
);
wire [COUNT_SIZE-1:0] mod_value; // Main Counter Modulo
wire [COUNT_SIZE-1:0] cnt_n; // PIT Counter Value
wire async_rst_b; // Asyncronous reset
wire sync_reset; // Syncronous reset
wire [ 3:0] write_regs; // Control register write strobes
wire prescale_out; //
wire pit_flg_clr; // Clear PIT Rollover Status Bit
wire pit_slave; // PIT in Slave Mode, ext_sync_i selected
wire [ 3:0] pit_pre_scl; // Prescaler modulo
wire counter_sync; //
// Wishbone Bus interface
pit_wb_bus #(.ARST_LVL(ARST_LVL),
.DWIDTH(DWIDTH))
wishbone(
.wb_dat_o ( wb_dat_o ),
.wb_ack_o ( wb_ack_o ),
.wb_clk_i ( wb_clk_i ),
.wb_rst_i ( wb_rst_i ),
.arst_i ( arst_i ),
.wb_adr_i ( wb_adr_i ),
.wb_dat_i ( wb_dat_i ),
.wb_we_i ( wb_we_i ),
.wb_stb_i ( wb_stb_i ),
.wb_cyc_i ( wb_cyc_i ),
.wb_sel_i ( wb_sel_i ),
// outputs
.write_regs ( write_regs ),
.sync_reset ( sync_reset ),
// inputs
.async_rst_b ( async_rst_b ),
.irq_source ( cnt_flag_o ),
.read_regs ( // in -- status register bits
{ cnt_n,
mod_value,
{pit_slave, DECADE_CNTR, NO_PRESCALE, 1'b0, pit_pre_scl,
5'b0, cnt_flag_o, pit_ien, cnt_sync_o}
}
)
);
 
// -----------------------------------------------------------------------------
pit_regs #(.ARST_LVL(ARST_LVL),
.COUNT_SIZE(COUNT_SIZE),
.NO_PRESCALE(NO_PRESCALE),
.DWIDTH(DWIDTH))
regs(
// outputs
.mod_value ( mod_value ),
.pit_pre_scl ( pit_pre_scl ),
.pit_slave ( pit_slave ),
.pit_flg_clr ( pit_flg_clr ),
.pit_ien ( pit_ien ),
.cnt_sync_o ( cnt_sync_o ),
.pit_irq_o ( pit_irq_o ),
// inputs
.async_rst_b ( async_rst_b ),
.sync_reset ( sync_reset ),
.bus_clk ( wb_clk_i ),
.write_bus ( wb_dat_i ),
.write_regs ( write_regs ),
.cnt_flag_o ( cnt_flag_o )
);
 
// -----------------------------------------------------------------------------
pit_prescale #(.COUNT_SIZE(PRE_COUNT_SIZE),
.DECADE_CNTR(DECADE_CNTR),
.NO_PRESCALE(NO_PRESCALE))
prescale(
// outputs
.prescale_out ( prescale_out ),
.counter_sync ( counter_sync ),
// inputs
.async_rst_b ( async_rst_b ),
.sync_reset ( sync_reset ),
.bus_clk ( wb_clk_i ),
.cnt_sync_o ( cnt_sync_o ),
.ext_sync_i ( ext_sync_i ),
.pit_slave ( pit_slave ),
.divisor ( pit_pre_scl )
);
 
// -----------------------------------------------------------------------------
pit_count #(.COUNT_SIZE(COUNT_SIZE))
counter(
// outputs
.cnt_n ( cnt_n ),
.cnt_flag_o ( cnt_flag_o ),
.pit_o ( pit_o ),
// inputs
.async_rst_b ( async_rst_b ),
.sync_reset ( sync_reset ),
.bus_clk ( wb_clk_i ),
.counter_sync ( counter_sync ),
.prescale_out ( prescale_out ),
.pit_flg_clr ( pit_flg_clr ),
.mod_value ( mod_value )
);
 
endmodule // pit_top
/pit/trunk/rtl/verilog/pit_count.v
0,0 → 1,95
////////////////////////////////////////////////////////////////////////////////
//
// Programable Interrupt Timer - Main Counter
//
// Author: Bob Hayes
// rehayes@opencores.org
//
// Downloaded from: http://www.opencores.org/projects/pit.....
//
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009, Robert Hayes
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the <organization> nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////////////////////////////////////////////////////////////////////////////////
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
 
module pit_count #(parameter COUNT_SIZE = 16)
(
output reg [COUNT_SIZE-1:0] cnt_n, // Modulo Counter value
output reg cnt_flag_o, // Counter Rollover Flag
output reg pit_o, // PIT output pulse
input async_rst_b, //
input sync_reset, // Syncronous reset signal
input bus_clk, // Reference Clock
input counter_sync, // Syncronous counter enable
input prescale_out, // Increment Counter
input pit_flg_clr, // Clear PIT Rollover Flag
input [COUNT_SIZE-1:0] mod_value // Count Divisor
);
 
// Warning: This counter has no saftynet if the mod_value changes while the counter
// is active. There may need to be an addtional latch register for
// "mod_value" that captures on the falling edge of "counter_sync" or
// when "cnt_n" rolls over to eliminate this problem.
 
 
wire rollover; // Counter has reached the mod_value
wire no_div; // Modulo set for Zero or One
wire clear_counter; // Set counter to initial state
 
assign no_div = (mod_value == 1) || ~|mod_value;
 
assign rollover = ((cnt_n == mod_value) || no_div) && prescale_out;
 
assign clear_counter = !counter_sync;
 
// Div N Counter
always @(posedge bus_clk or negedge async_rst_b)
if ( !async_rst_b )
cnt_n <= 1;
else if ( clear_counter || rollover || no_div)
cnt_n <= 1;
else if ( prescale_out )
cnt_n <= cnt_n + 1;
 
// Counter Rollover Flag and Interrupt
always @(posedge bus_clk or negedge async_rst_b)
if ( !async_rst_b )
cnt_flag_o <= 0;
else if ( clear_counter || pit_flg_clr)
cnt_flag_o <= 0;
else if ( rollover )
cnt_flag_o <= 1;
 
// PIT Output Register
always @(posedge bus_clk or negedge async_rst_b)
if ( !async_rst_b )
pit_o <= 0;
else
pit_o <= rollover && counter_sync && !sync_reset;
 
endmodule // pit_count
 
/pit/trunk/rtl/verilog/pit_prescale.v
0,0 → 1,126
////////////////////////////////////////////////////////////////////////////////
//
// Programable Interrupt Timer - Prescale Counter
//
// Author: Bob Hayes
// rehayes@opencores.org
//
// Downloaded from: http://www.opencores.org/projects/pit.....
//
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009, Robert Hayes
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the <organization> nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////////////////////////////////////////////////////////////////////////////////
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
 
module pit_prescale #(parameter COUNT_SIZE = 15,
parameter DECADE_CNTR = 1,
parameter NO_PRESCALE = 0)
(
output prescale_out, //
output counter_sync, //
input async_rst_b, //
input sync_reset, // Syncronous reset signal
input bus_clk, // Reference Clock
input cnt_sync_o, // Syncronous counter enable
input ext_sync_i, // Enable from external PIT
input pit_slave, // PIT Slave Mode
input [3:0] divisor // Count Divisor
);
// Warning: This counter has no safety net if the divisor changes while the
// counter is active. There may need to be an addtional latch
// register for"divisor" that captures on the falling edge of
// "cnt_sync_o" or when "cnt_n" rolls over to eliminate this problem.
 
reg [COUNT_SIZE-1:0] cnt_n; // Div N counter
reg [COUNT_SIZE-1:0] end_count; // Psudo register for decoding
 
wire div_1; //
wire rollover; //
 
// This was going to be a "generate" block but iverilog does't support that
// command so we'll just have to trust the compiler to simplify the logic based
// on the setting of the constant "DECADE_CNTR"
always @*
if ( DECADE_CNTR )
case (divisor)
0: end_count = 1;
1: end_count = 2;
2: end_count = 4;
3: end_count = 8;
4: end_count = 10;
5: end_count = 100;
6: end_count = 1_000;
7: end_count = 10_000;
8: end_count = 20_000;
default: end_count = 20_000;
endcase
else
case (divisor)
0: end_count = 1;
1: end_count = 2;
2: end_count = 4;
3: end_count = 8;
4: end_count = 16;
5: end_count = 32;
6: end_count = 64;
7: end_count = 128;
8: end_count = 256;
9: end_count = 512;
10: end_count = 1024;
11: end_count = 2048;
12: end_count = 4096;
13: end_count = 8192;
14: end_count = 16384;
15: end_count = 32768;
endcase
 
assign counter_sync = pit_slave ? ext_sync_i : cnt_sync_o;
 
assign div_1 = (end_count == 1);
 
assign rollover = NO_PRESCALE || (cnt_n == end_count);
 
assign prescale_out = (pit_slave && div_1 && ext_sync_i) || rollover;
 
// Div N Counter
// If the "NO_PRESCALE" parameter is set the compiler should hopefully strip
// these counter bits when the module is compiled because the only place the
// register outputs go to drive a signal "rollover" that is already a constant.
always @(posedge bus_clk or negedge async_rst_b)
if ( !async_rst_b )
cnt_n <= 1;
else if ( !counter_sync || rollover)
cnt_n <= 1;
// else if ( rollover )
// cnt_n <= 1;
else
cnt_n <= cnt_n + 1;
 
 
endmodule // pit_prescale
 
/pit/trunk/doc/src/PIT_specs.pdf Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
pit/trunk/doc/src/PIT_specs.pdf Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: pit/trunk/doc/src/PIT_Structure.ppt =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: pit/trunk/doc/src/PIT_Structure.ppt =================================================================== --- pit/trunk/doc/src/PIT_Structure.ppt (nonexistent) +++ pit/trunk/doc/src/PIT_Structure.ppt (revision 2)
pit/trunk/doc/src/PIT_Structure.ppt Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: pit/trunk/doc/PIT_specs.doc =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: pit/trunk/doc/PIT_specs.doc =================================================================== --- pit/trunk/doc/PIT_specs.doc (nonexistent) +++ pit/trunk/doc/PIT_specs.doc (revision 2)
pit/trunk/doc/PIT_specs.doc Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property

powered by: WebSVN 2.1.0

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