1 |
29 |
robfinch |
// ============================================================================
|
2 |
|
|
// __
|
3 |
|
|
// \\__/ o\ (C) 2006-2020 Robert Finch, Waterloo
|
4 |
|
|
// \ __ / All rights reserved.
|
5 |
|
|
// \/_// robfinch<remove>@finitron.ca
|
6 |
|
|
// ||
|
7 |
|
|
//
|
8 |
|
|
//
|
9 |
|
|
// ParallelToSerial.v
|
10 |
|
|
// Parallel to serial data converter (shift register).
|
11 |
|
|
//
|
12 |
|
|
// BSD 3-Clause License
|
13 |
|
|
// Redistribution and use in source and binary forms, with or without
|
14 |
|
|
// modification, are permitted provided that the following conditions are met:
|
15 |
|
|
//
|
16 |
|
|
// 1. Redistributions of source code must retain the above copyright notice, this
|
17 |
|
|
// list of conditions and the following disclaimer.
|
18 |
|
|
//
|
19 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
20 |
|
|
// this list of conditions and the following disclaimer in the documentation
|
21 |
|
|
// and/or other materials provided with the distribution.
|
22 |
|
|
//
|
23 |
|
|
// 3. Neither the name of the copyright holder nor the names of its
|
24 |
|
|
// contributors may be used to endorse or promote products derived from
|
25 |
|
|
// this software without specific prior written permission.
|
26 |
|
|
//
|
27 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
28 |
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
29 |
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
30 |
|
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
31 |
|
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
32 |
|
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
33 |
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
34 |
|
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
35 |
|
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
36 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
37 |
|
|
//
|
38 |
|
|
// ============================================================================
|
39 |
|
|
//
|
40 |
|
|
module ParallelToSerial(rst, clk, ce, ld, a, qin, d, qh);
|
41 |
|
|
localparam WID=64;
|
42 |
|
|
input rst; // reset
|
43 |
|
|
input clk; // clock
|
44 |
|
|
input ce; // clock enable
|
45 |
|
|
input ld; // load
|
46 |
|
|
input [2:0] a; // bits 3-5 of the font width
|
47 |
|
|
input qin; // serial shifting input
|
48 |
|
|
input [WID-1:0] d; // data to load
|
49 |
|
|
output reg qh; // serial output
|
50 |
3 |
robfinch |
|
51 |
29 |
robfinch |
reg [WID-1:0] q;
|
52 |
3 |
robfinch |
|
53 |
29 |
robfinch |
always @(posedge clk)
|
54 |
|
|
if (rst)
|
55 |
|
|
q <= {WID{1'b0}};
|
56 |
|
|
else if (ce) begin
|
57 |
|
|
if (ld)
|
58 |
|
|
q <= d;
|
59 |
|
|
else
|
60 |
|
|
q <= {q[WID-2:0],qin};
|
61 |
|
|
end
|
62 |
3 |
robfinch |
|
63 |
29 |
robfinch |
always @(posedge clk)
|
64 |
|
|
if (ce)
|
65 |
|
|
casez(a)
|
66 |
|
|
3'b1??: qh <= q[63];
|
67 |
|
|
// 3'b110: qh <= q[55];
|
68 |
|
|
// 3'b101: qh <= q[47];
|
69 |
|
|
// 3'b100: qh <= q[39];
|
70 |
|
|
3'b01?: qh <= q[31];
|
71 |
|
|
// 3'b010: qh <= q[23];
|
72 |
|
|
3'b001: qh <= q[15];
|
73 |
|
|
3'b000: qh <= q[ 7];
|
74 |
|
|
endcase
|
75 |
3 |
robfinch |
|
76 |
|
|
endmodule
|