[Serialization] FPGA OpenGL series instances
Two-way shift register of OpenGL
I. Principles
The registers designed for the previous experiment only store data andCode. Sometimes in order to process the data, you need to shift the data in the register to a high or low position with the shift control signal. A register with the shift function is called a shift register.
This experiment is to design a two-way shift register, which can move and output data input by four-bit serial signals. In addition, this register also has an asynchronous clearing end, which is effective at a low level. There is also a signal input for loading data for the preset data, and a signal input for controlling the Left shift or right shift, as shown in Table 1.1.
Table 1.1 bidirectional shift register function
II. Implementation
Enter the OpenGL code in the design file.
1 'Timescale 1 NS / 1 PS
2
3 Module shiftdata (left_right, load, CLR, CLK, DIN, dout );
4
5 Input left_right;
6 Wire left_right;
7 Input load;
8 Wire load;
9 Input CLR;
10 Wire CLR;
11 Input CLK;
12 Wire CLK;
13 Input [ 3 : 0 ] Din;
14 Wire [ 3 : 0 ] Din;
15
16 Output [ 3 : 0 ] Dout;
17 Wire [ 3 : 0 ] Dout;
18 Reg [ 3 : 0 ] Data_r;
19
20 Assign dout = Data_r;
21
22 Always @ (posedge CLK or posedge CLR or posedge load)
23 Begin
24 If (CLR = 1 )
25 Data_r <= 0 ;
26 Else If (Load)
27 Data_r <= Din;
28 Else Begin
29 If (Left_right)
30 Begin
31 Data_r <= (Data_r < 1 );
32 Data_r [ 0 ] <= 0 ;
33 End
34 Else Begin
35 Data_r <= (Data_r > 1 );
36 Data_r [ 3 ] <= 0 ;
37 End
38 End
39 End
40
41 Endmodule