G
Gareth Owen
Guest
Hi,
I'm new to Verilog, coming from a software background. Here's the problem I'm trying to solve
I have two synchronous clocks, one running at 100Mhz and one at 50MHz.
I have a source of 8bit values, generated on the 100MHz clock.
I want to produce a stream of 16bit values synced with the 50MHz clocks,
containing sequential values. So I wrote some naive code and simulated it.
Under cver (GPL version) it does sort of what I expect.
output: XXFF 0302 0504 0706 0807
Under Icarus Verilog it really doesn't:
output: 01XX 0101 0303 0505
Can anyone
a) point out what I'm misunderstanding about this.
b) give me some pointers about how much of the behaviour of "simultaneous events" and synchronous clocks I can rely on w.r.t. synthesis (Xilinx Vivado) and physical systems with clock jitter etc.
// Cut here. Hopefully google news won't mess this up too much...
`timescale 1ns / 100ps
module data_merge(byte_in,
byte_clk,
word_out,
word_clk);
input [7:0] byte_in;
input byte_clk,word_clk;
output [15:0] word_out;
reg [15:0] word_out;
reg [7:0] MSB;
reg [7:0] LSB;
reg next_is_MSB;
initial
next_is_MSB = 1;
always @(posedge byte_clk)
begin
if(next_is_MSB)
MSB = byte_in;
else
LSB = byte_in;
next_is_MSB = ~next_is_MSB;
end
always @(posedge word_clk)
begin
word_out[15:8] = MSB;
word_out[7:0] = LSB;
end
endmodule
module data_merge_tb();
reg clk_100;
reg clk_50;
reg [7:0] byte;
wire [15:0] word;
always
#5 clk_100 = ~clk_100;
always
#10 clk_50 = ~clk_50;
always @(posedge clk_100)
byte = byte + 1;
always
#10000 $finish;
data_merge dm(.byte_clk(clk_100),
.word_clk(clk_50),
.byte_in(byte),
.word_out(word)
);
initial
begin
// $dumpfile("output.vcd");
// $dumpvars(0,data_merge_tb);
byte = 0;
clk_100 = 1;
clk_50 = 1;
end
endmodule
I'm new to Verilog, coming from a software background. Here's the problem I'm trying to solve
I have two synchronous clocks, one running at 100Mhz and one at 50MHz.
I have a source of 8bit values, generated on the 100MHz clock.
I want to produce a stream of 16bit values synced with the 50MHz clocks,
containing sequential values. So I wrote some naive code and simulated it.
Under cver (GPL version) it does sort of what I expect.
output: XXFF 0302 0504 0706 0807
Under Icarus Verilog it really doesn't:
output: 01XX 0101 0303 0505
Can anyone
a) point out what I'm misunderstanding about this.
b) give me some pointers about how much of the behaviour of "simultaneous events" and synchronous clocks I can rely on w.r.t. synthesis (Xilinx Vivado) and physical systems with clock jitter etc.
// Cut here. Hopefully google news won't mess this up too much...
`timescale 1ns / 100ps
module data_merge(byte_in,
byte_clk,
word_out,
word_clk);
input [7:0] byte_in;
input byte_clk,word_clk;
output [15:0] word_out;
reg [15:0] word_out;
reg [7:0] MSB;
reg [7:0] LSB;
reg next_is_MSB;
initial
next_is_MSB = 1;
always @(posedge byte_clk)
begin
if(next_is_MSB)
MSB = byte_in;
else
LSB = byte_in;
next_is_MSB = ~next_is_MSB;
end
always @(posedge word_clk)
begin
word_out[15:8] = MSB;
word_out[7:0] = LSB;
end
endmodule
module data_merge_tb();
reg clk_100;
reg clk_50;
reg [7:0] byte;
wire [15:0] word;
always
#5 clk_100 = ~clk_100;
always
#10 clk_50 = ~clk_50;
always @(posedge clk_100)
byte = byte + 1;
always
#10000 $finish;
data_merge dm(.byte_clk(clk_100),
.word_clk(clk_50),
.byte_in(byte),
.word_out(word)
);
initial
begin
// $dumpfile("output.vcd");
// $dumpvars(0,data_merge_tb);
byte = 0;
clk_100 = 1;
clk_50 = 1;
end
endmodule