EmbDev.net

Forum: FPGA, VHDL & Verilog Double Data Rate Serializer verilog


von Atalin (Guest)


Rate this post
0 useful
not useful
Hi! I want to write the code for a serializer which works both on rising 
edge and falling edge of the clock. The idea is to write two registers, 
one for the even bits and the other one for the odd bits, and then a MUX 
which send out the data. Moreover, I have a control signal called LOAD: 
when LOAD is high, I want to load the data into the two registers. The 
problem is that the even bits are not loaded into the register and I do 
not know why because I wrote the same piece of code both for the odd 
bits and the even ones. Can anyone help me? Thank you very much! The 
code is hereinafter.


module serializer (data_in, send, clk, load, rst, data_out);

input wire [11:0] data_in;
input wire send, clk, load, rst;

output reg data_out;

reg [7:0] temp_data_out_even;
reg [7:0] temp_data_out_odd;

integer i;
integer j;

always @ (posedge clk) 
begin
  if (rst) begin
    data_out <= 1'b0;
    temp_data_out_odd <= 8'b00000000;
  end
  else if (load) begin
    temp_data_out_odd <= 8'b11000000;
    for(i=0; i<6; i=i+1)
      temp_data_out_odd[5-i] <= data_in[11-i*2];
  end
  else if (send) begin
    data_out <= temp_data_out_odd[7];
    temp_data_out_odd <= {temp_data_out_odd[6:0], 1'b0};  // Shifting phase
  end
end

always @ (negedge clk) 
begin
  if (rst) begin
    data_out <= 1'b0;
    temp_data_out_even <= 8'b00000000;
  end
  else if (load) begin
    temp_data_out_even <= 8'b00000000;
    for(j=0; j<6; j=j+1)
      temp_data_out_even[5-j] <= data_in[10-i*2];
  end
  else if (send) begin
    data_out <= temp_data_out_even[7];
    temp_data_out_even <= {temp_data_out_even[6:0], 1'b0};  // Shifting phase
  end
end

endmodule //end module serializer

The testbench is the following
`include "serializer.v"
`timescale 1ns / 1ps

module serializer_tb();
// Declare inputs as regs and outputs as wires
reg [11:0] data_in;
reg send, clk, load, rst;
wire data_out;
reg [11:0] reg_sipo;
reg check;
integer i;


// Initialize all variables
initial begin          
  clk = 1;       // initial value of clock
  rst = 1;       // initial value of reset
  load = 0;
  send = 0;
  #15 rst = 0;   // De-assert the reset

  forever begin
    foreach(data_in[j]) data_in[j] = $urandom;
    #13 load = 1;
    #20 load = 0;
    #5 send = 1;
    #20          //header
    for(i=0; i<12; i=i+1) begin
      #5 reg_sipo[11-i] <= data_out;
      end
    #10 send = 0;
    if(reg_sipo == data_in) check = 0;
    else check = 1;
  end
end

// Clock generator
always begin
  #5 clk = ~clk; // Toggle clock every 5 ns - 100 MHz
end

// Connect DUT to test bench
serializer U_serializer (data_in, send, clk, load, rst, data_out);

endmodule

von Alexx (Guest)


Rate this post
0 useful
not useful
I am not really a verilog user but can you write on a signal from two 
different processes? in VHDL you cannot.

von -gb- (Guest)


Rate this post
0 useful
not useful
You should could use a DDR IO Primitive from the FPGA Vendor. Like ODDR2 
from Xilinx.

But ... no, not write from two processses, but read.

Registers A for rising edge and B for falling edge. And some logic which 
provides new data for BOTH registers.

So the logic (with whatever clock) provides new data for both registers. 
And sets a data valid signal.
With rising edge logic, the data valid signal is detected and the 
provided data is written to reg A.
With falling edge logic, the data valid signal is detected and the 
provided data is written to reg B.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig