module poissonEncoderWithLFSR(clk, set, next, seed, dataIn, encOut);
parameter NUM_BITS_IN = 12;
parameter NUM_BITS_LFSR = 8;
input clk,set,next;
input [NUM_BITS_LFSR-1:0] seed;
input [NUM_BITS_IN-1:0] dataIn;
output reg encOut;
wire [NUM_BITS_LFSR-1:0] randVal;
wire [NUM_BITS_IN-1:0] zeroPaddedRandVal; // making the randval and dataIn of the same bit length
wire result;
lfsr_8bit lsfr_8bit_0(.clk(clk),.set(set),.next(next),.seed(seed),.randVal(randVal));
assign zeroPaddedRandVal = {{(NUM_BITS_IN-NUM_BITS_LFSR){1'b0}},randVal[NUM_BITS_LFSR-1:0]};
assign result = (dataIn > zeroPaddedRandVal)?1'b1:1'b0;
always@(posedge clk)
begin
if(set) encOut <= 0;
else if(next) encOut <= result;
else encOut <= encOut;
end
endmodule
module lfsr_8bit(clk,set,next,seed,randVal);
input clk,set,next;
input [7:0] seed;
output reg [7:0] randVal;
wire linearFeedback = randVal[7]^randVal[5]^randVal[4]^randVal[3];
always@(posedge clk)
begin
if(set) randVal <= seed;
else if (next) randVal <= {randVal[6:0],linearFeedback};
else randVal <= randVal;
end
endmodule