In Verilog, I can find two system functions to read data from text file. One is $readmemb/$readmemh
, other is $fscanf
. I am confused between what is difference of the two. Can I simply always use $readmemb
and forget about $fscanf
?
My understanding is $readmemb
is used to initialize memory but that way it can initialize any variable. For example, I have text file with stream of 0s and 1s and I want to read it and store it and then feed them serially into shift register 1 bit every clock.
reg [63:0] seq_input;
$readmemb("pattern.in", seq_input);
I think think this will put streams of zero and one into seq_input
at one go and then I can use delay to feed bits from this to DUT.
Why would I use $fscanf
and what would be the difference?