Skip to content

Commit

Permalink
fixed the ready_for_next_byte bug in sd writing
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchgu committed Dec 1, 2015
1 parent 6013c45 commit 4378441
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
Binary file modified Nexys4Guitar/bin/nexys4_guitar.bit
Binary file not shown.
12 changes: 9 additions & 3 deletions Nexys4Guitar/src/hdl/histogram_saver.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

module histogram_saver(
input clk,
input reset,
input start,
input [3:0] slot,
output reg [9:0] vaddr,
Expand All @@ -44,8 +45,10 @@ module histogram_saver(
reg [1:0] save_state = STANDBY;
reg next_half = MSHALF;
reg [1:0] sector = 2'b00;
reg last_ready;

always @(posedge clk) begin
last_ready <= sd_ready_for_next_byte;
case (save_state)
STANDBY: begin
saving <= 0;
Expand All @@ -61,8 +64,8 @@ module histogram_saver(
if (sd_ready) begin
save_state <= START;
sd_wr <= 1;
sd_din <= vdata[15:8];
next_half <= LSHALF;
sd_din <= 8'hFF;
next_half <= MSHALF;
end
end
START: begin
Expand All @@ -82,7 +85,7 @@ module histogram_saver(
save_state <= INIT;
end
end
else if(sd_ready_for_next_byte) begin
else if(sd_ready_for_next_byte & ~last_ready) begin
if (next_half == LSHALF) begin
sd_din <= vdata[7:0];
next_half <= MSHALF;
Expand All @@ -96,6 +99,9 @@ module histogram_saver(
end
default: save_state <= STANDBY;
endcase
if (reset) begin
save_state <= STANDBY;
end
end

endmodule
13 changes: 8 additions & 5 deletions Nexys4Guitar/src/hdl/nexys4_guitar.v
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ module nexys4_guitar (
.gain(hist_gain),
.pixel(hist_pixel));

wire sd_cs, sd_mosi, sd_miso, sd_sclk, sd_wr, sd_ready_for_next_byte, sd_ready;
wire sd_cs, sd_mosi, sd_miso, sd_sclk, sd_wr, sd_ready_for_next_byte, sd_ready, sd_reset;
wire [7:0] sd_din;
wire [31:0] sd_address;
sd_controller sdc(
Expand All @@ -244,7 +244,7 @@ module nexys4_guitar (
.din(sd_din), // Data input for WRITE operation.
.ready_for_next_byte(sd_ready_for_next_byte), // A new byte should be presented on [din].

.reset(0), // Resets controller on assertion.
.reset(sd_reset), // Resets controller on assertion.
.ready(sd_ready), // HIGH if the SD card is ready for a read or write operation.
.address(sd_address), // Memory address for read/write operation. This MUST
// be a multiple of 512 bytes, due to SD sectoring.
Expand All @@ -255,10 +255,11 @@ module nexys4_guitar (
reg old_center_button = 0;
always @(posedge clk_25mhz) old_center_button <= center_button;
assign save_start = center_button & ~old_center_button;
wire saving;
wire saver_reset, saving;
wire [3:0] save_slot;
histogram_saver hsaver(
.clk(clk_25mhz),
.reset(saver_reset),
.start(save_start),
.slot(save_slot),
.vaddr(save_addr),
Expand Down Expand Up @@ -310,8 +311,8 @@ module nexys4_guitar (

// Debounce down btn
wire down_button_noisy, down_button;
debounce down_button_debouncer(
.clock(clk_104mhz),
debounce #(.DELAY(250000)) down_button_debouncer(
.clock(clk_25mhz),
.reset(reset_debounce),
.noisy(down_button_noisy),
.clean(down_button));
Expand Down Expand Up @@ -364,6 +365,8 @@ module nexys4_guitar (
assign SD_SCK = sd_sclk;
assign SD_DAT[2:1] = 2'b11;
assign SD_RESET = 0;
assign sd_reset = down_button;
assign saver_reset = down_button;

// HISTOGRAM SAVER INTERFACE
assign save_slot = SW[7:4];
Expand Down
12 changes: 4 additions & 8 deletions Nexys4Guitar/src/test/process_fft_tb_func_synth.wcfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</db_ref>
</db_ref_list>
<zoom_setting>
<ZoomStartTime time="0fs"></ZoomStartTime>
<ZoomEndTime time="120000000001fs"></ZoomEndTime>
<Cursor1Time time="120000000000fs"></Cursor1Time>
<ZoomStartTime time="4942433334fs"></ZoomStartTime>
<ZoomEndTime time="5615433335fs"></ZoomEndTime>
<Cursor1Time time="4822433000fs"></Cursor1Time>
</zoom_setting>
<WVObjectSize size="12" />
<WVObjectSize size="11" />
<wvobject db_ref_id="1" fp_name="/histogram_saver_tb/clk" type="logic">
<obj_property name="ElementShortName">clk</obj_property>
<obj_property name="ObjectShortName">clk</obj_property>
Expand Down Expand Up @@ -62,8 +62,4 @@
<obj_property name="ElementShortName">next_half</obj_property>
<obj_property name="ObjectShortName">next_half</obj_property>
</wvobject>
<wvobject db_ref_id="1" fp_name="/histogram_saver_tb/sd_ready_for_next_byte" type="logic">
<obj_property name="ElementShortName">sd_ready_for_next_byte</obj_property>
<obj_property name="ObjectShortName">sd_ready_for_next_byte</obj_property>
</wvobject>
</wave_config>

0 comments on commit 4378441

Please sign in to comment.