OpenCores
URL https://opencores.org/ocsvn/mcs-4/mcs-4/trunk

Subversion Repositories mcs-4

[/] [mcs-4/] [trunk/] [rtl/] [verilog/] [i4003/] [i4003.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 rrpollack
`timescale 1ns / 1ps
2
`default_nettype none
3
////////////////////////////////////////////////////////////////////////
4
//
5
// MCS-4 i4003 Shift Register
6
//
7
// This module emulates the Intel 4003 shift register chip.
8
//
9
// This file is part of the MCS-4 project hosted at OpenCores:
10
//      http://www.opencores.org/cores/mcs-4/
11
//
12
// Copyright © 2021 by Reece Pollack <rrpollack@opencores.org>
13
//
14
// These materials are provided under the Creative Commons
15
// "Attribution-NonCommercial-ShareAlike" (CC BY-NC-SA) Public License.
16
// They are NOT "public domain", and are protected by copyright.
17
//
18
// This work based on materials provided by Intel Corporation and
19
// others under the same license. See the file doc/License for
20
// details of this license.
21
//
22
////////////////////////////////////////////////////////////////////////
23
 
24
module i4003 #(
25
    parameter SYSCLK_TCY = 20       // System clock period in nanoseconds
26
    ) (
27
    input  wire         sysclk,
28
    input  wire         cp,
29
    input  wire         serial_in,
30
    input  wire         enable,
31
    output wire [9:0]   parallel_out,
32
    output reg          serial_out
33
    );
34
 
35
    initial begin
36
        serial_out = 1'b0;
37
    end
38
 
39
    localparam  LATCH_DELAY_NS = 250;
40
    localparam  LATCH_DELAY_CY = nstocy(LATCH_DELAY_NS);
41
 
42
    localparam  W = clog2(LATCH_DELAY_CY);
43
 
44
    reg          cp_delayed = 1'b0;
45
    reg  [W-1:0] cp_delay = 0;
46
    wire         cp_edge = (cp_delay == LATCH_DELAY_CY[W-1:0]);
47
    always @(posedge sysclk) begin
48
        if (cp == cp_delayed) begin
49
            cp_delay <= 0;
50
        end
51
        else begin
52
            if (cp_edge) begin
53
                cp_delay <= 0;
54
                cp_delayed <= cp;
55
            end
56
            else begin
57
                cp_delay <= cp_delay + 1'b1;
58
            end
59
        end
60
    end
61
 
62
    reg  [9:0]  shifter = 10'h000;
63
    always @(posedge sysclk) begin
64
        if (cp_edge & cp) begin
65
            shifter <= {shifter[8:0], serial_in};
66
        end
67
    end
68
    assign parallel_out = enable ? shifter : 10'h000;
69
 
70
    always @(posedge sysclk) begin
71
        if (cp_edge & ~cp) begin
72
            serial_out <= shifter[9];
73
        end
74
    end
75
 
76
 
77
`include "../common/functions.vh"
78
 
79
endmodule

powered by: WebSVN 2.1.0

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