N
Nicholas Kinar
Guest
You have these signals in two separate always blocks.
Synthesis will not work that way. Also your blocks
are using both edges of clk (one edge for each block
that is). So even trying to rewrite this as one block
will require some change to your logic. Do these
signals really need to change on both edges of clk?
What kind of flip-flop did you want Quartus to make
from this code?
HTH,
Gabor
Hello--
Well, I've finally managed to modify my code so that it can be simulated
using Icarus Verilog and also synthesized using Quartus II tools! I did
exactly as you suggested, gabor - the signals do not need to change on
both edges of clk, so I re-wrote the code to contain a block that is
only triggered on the negedge of clk. So thank you so much for your
suggestions!
Using Icarus and Gtkwave, I've validated that there are changes in the
signals.
However, after synthesizing the code and loading it to my hardware,
nothing useful appears to happen when I attempt to load the DAC with a
control word.
I've used Signaltap II Logic Analyzer to examine what is happening - and
it appears that sdin_dac, fsync_dac, reset_lw, and sclk_dac remain
jammed at zero. There appears to be no activity!
I suspect that this may be due to the fact that something is being
optimized away by the synthesis tools. What could be the issue with
this code?
The modified code of the module is listed below:
// Module to update the DAC via SPI
module dac( rst,
clk,
load_word,
msb_data,
lsb_data,
sdin_dac,
fsync_dac,
reset_lw,
sclk_dac);
input rst; // used to ensure state on startup
input clk;
input [7:0] load_word;
input [7:0] msb_data;
input [7:0] lsb_data;
output sdin_dac;
output fsync_dac;
output reset_lw;
output sclk_dac;
reg sdin_dac;
reg fsync_dac;
reg reset_lw;
reg [15:0] data;
reg [4:0] count;
// clock is continuous
assign sclk_dac = clk;
always @(negedge clk) begin
if (rst) begin
sdin_dac <= 1'b0;
fsync_dac <= 1'b0;
reset_lw <= 1'b0;
count <= 5'b0;
end
else begin
if ( (count < 16) && (load_word == 8'b1) )
count <= count + 1'b1;
if (count == 16) count <= 5'b0;
if (load_word == 1'b0) begin
sdin_dac <= 1'b0;
fsync_dac <= 1'b0;
reset_lw <= 1'b0;
count <= 5'b0;
end
if (load_word == 8'b1) begin
// CS is set high
if(count == 5'b0) begin
sdin_dac <= 1'b0;
fsync_dac <= 1'b1;
data <= {msb_data, lsb_data};
end
// shift out the data
if( (count < 16) && (count >= 1))
sdin_dac <= data[15 - count];
// logic should go back to zero again
if(count == 16) begin
sdin_dac <= 1'b0;
fsync_dac <= 1'b0;
reset_lw <= 1'b1;
end
// change reset_lw back again to zero
if (load_word == 1'b0) reset_lw <= 1'b0;
end // end of load_word
end // if else block
end // clk always
endmodule