x393  1.0
FPGAcodeforElphelNC393camera
varlen_encode393.v
Go to the documentation of this file.
1 
44 //used the other edge of the clk2x
45 
47  input clk, // twice frequency - uses negedge inside
48  input en, // will enable registers. 0 - freeze at once
49  input start, // (not faster than each other cycle)
50  input [11:0] d, // 12-bit signed
51  output reg [3:0] l, // [3:0] code length
52  output reg [3:0] l_late,// delayed l (sync to q)
53  output reg [10:0] q); // [10:0]code
54 
55  reg [11:0] d1;
56  reg [10:0] q0;
57  reg [2:0] cycles;
58 
59  wire this0 = |d1[ 3:0];
60  wire this1 = |d1[ 7:4];
61  wire this2 = |d1[10:8];
62  wire [1:0] codel0 = {|d1[ 3: 2],d1[ 3] || (d1[ 1] & ~d1[ 2])};
63  wire [1:0] codel1 = {|d1[ 7: 6],d1[ 7] || (d1[ 5] & ~d1[ 6])};
64  wire [1:0] codel2 = {|d1[ 10], (d1[ 9] & ~d1[10])};
65  wire [3:0] codel = this2? {2'b10,codel2[1:0]} :
66  (this1? {2'b01, codel1[1:0]} :
67  (this0 ? {2'b00,codel0[1:0]} : 4'b1111)); // after +1 will be 0;
68 
69  always @ (negedge clk) if (en) begin
70  cycles[2:0] <= {cycles[1:0],start};
71  end
72 
73  always @ (negedge clk) if (en && start) begin
74  d1[ 11] <= d[11];
75  d1[10:0] <= d[11]?-d[10:0]:d[10:0];
76  end
77 
78  always @ (negedge clk) if (en & cycles[0]) begin
79  q0[10:0] <= d1[11]?~d1[10:0]:d1[10:0];
80  l <= codel[3:0]+1; // needed only ASAP, valid only 2 cycles after start
81  end
82 
83  always @ (negedge clk) if (en & cycles[2]) begin
84  q[10:0] <= q0[10:0];
85  l_late[3:0] <= l[3:0];
86  end
87 
88 endmodule
reg [10:0] 3098q
reg [3:0] 3097l_late