//Convolutional Encoder for UMTS
//K = 9
//rate = 1/2
//
//Created by: Warrior Group
//
`resetall
//
module conv_encoder2 (out0, out1, in_out, clk ,reset) ;

input clk, reset ;
output out0, out1, in_out ;

reg [7:0] tmp ;
reg tmp1, tmp2;
reg [26:0]count ;
reg clk_out ;
reg [6:0]data ;
reg [2:0]data_count ;
reg data_buf ;

//Clock generator
always @(posedge clk)
begin
  if (!reset)
    begin
      count = 27'b0 ;
      clk_out = 1'b0 ;
    end
  else
    begin
      if (count <27'd60000000)
        begin
       clk_out = 1'b1 ;
        end
      else if (count >= 27'd60000000)
         clk_out = 1'b0 ;
      else if (count == 27'd120000001)
        begin
         count = 27'b0 ;
       end
      count = count + 27'b1 ;
    end
end
//
//Main Process for conv_Encoder
always @(posedge clk_out)
begin
  if (!reset)
    begin
      tmp = 8'b0;
      data_buf = 1'b0 ;
      data = 7'b0010110 ;
      data_count = 3'b0 ;
    end
  else 
    begin
      data_buf = data[data_count] ;
      data_count = data_count + 3'b1 ; 
      tmp1 = data_buf ^ tmp[1] ^ tmp[2] ^ tmp[3] ^ tmp[7] ;
      tmp2 = data_buf ^ tmp[0] ^ tmp[1] ^ tmp[2] ^ tmp[4]^ tmp[6] ^ tmp[7] ;
      tmp =  { tmp[6:0], data_buf };
    end
end 
assign out0 =  tmp1 ;
assign out1 =  tmp2 ;
assign in_out = data_buf ;

endmodule
