AD0804和FPGA写得流水灯,流水灯没有变化。
时间:10-02
整理:3721RD
点击:
最近按照特权同学很早的文章程序写了一个,可是用示波器感觉输出 CS,RD,WR都没有变化。将AD0804数据输出口直接接流水灯,流水灯也没有变化。
module AD(clk,rst_n,cs_n,rd_n,wr_n,LED_Out);
input clk;
input rst_n;
// input intr_n;
output cs_n,rd_n,wr_n;
output [1:0]LED_Out;
/***********************************************/
reg[1:0] idle,start,start_wait,convert,current_state,next_state;
reg[15:0] delay;
reg cs_n,rd_n,wr_n;
// reg[7:0] data_reg;
// reg read_flag;
always @ (posedge clk or negedge rst_n) begin
if(!rst_n)
begin
current_state <= 0;
delay <= 0;
// data_reg <= 0;
end
else begin
case(current_state)
idle: begin
if(delay<10)
begin delay <= delay+16'd1; end
else begin
current_state <= next_state;
delay <= 0; end
end
start: begin
current_state <= next_state;
end
start_wait: begin
current_state <= next_state;
end
convert: begin
if(delay<2) begin
delay <= delay+16'd1; end
else begin
// data_reg <= data;
current_state <= next_state;
delay <= 0; end
end
default: ;
endcase
end
end
// always @ (current_state or intr_n or rst_n) begin
always @ (current_state or rst_n) begin
if(!rst_n) begin
idle <= 0;
start <= 1;
start_wait <= 2;
convert <= 3;
// read_flag <= 0;
end
else begin
case (current_state)
idle: begin
cs_n <= 1;
wr_n <= 1;
rd_n <= 1;
// read_flag <= 0;
next_state <= start; end
start: begin
cs_n <= 0;
wr_n <= 0;
rd_n <= 1;
// read_flag <= 0;
next_state <= start_wait; end
start_wait: begin
wr_n <= 1;
cs_n <= 1;
rd_n <= 1;
// read_flag <= 0;
// if(!intr_n) next_state <= convert;
// else
next_state <= start_wait;
end
convert: begin
cs_n <= 0;
rd_n <= 0;
wr_n <= 1;
// read_flag <= 1;
next_state <= idle; end
default: next_state <= idle;
endcase
end
end
/************************************** */
wire LED0_Out;
led0_module U3
(
.clk( clk ),
.rst_n( rst_n ),
.LED_Out( LED0_Out )
);
/*********************************/
wire LED1_Out;
led1_module U4
(
.clk( clk ),
.rst_n( rst_n ),
.LED_Out( LED1_Out )
);
/*********************************/
assign LED_Out = { LED0_Out, LED1_Out};
endmodule
module AD(clk,rst_n,cs_n,rd_n,wr_n,LED_Out);
input clk;
input rst_n;
// input intr_n;
output cs_n,rd_n,wr_n;
output [1:0]LED_Out;
/***********************************************/
reg[1:0] idle,start,start_wait,convert,current_state,next_state;
reg[15:0] delay;
reg cs_n,rd_n,wr_n;
// reg[7:0] data_reg;
// reg read_flag;
always @ (posedge clk or negedge rst_n) begin
if(!rst_n)
begin
current_state <= 0;
delay <= 0;
// data_reg <= 0;
end
else begin
case(current_state)
idle: begin
if(delay<10)
begin delay <= delay+16'd1; end
else begin
current_state <= next_state;
delay <= 0; end
end
start: begin
current_state <= next_state;
end
start_wait: begin
current_state <= next_state;
end
convert: begin
if(delay<2) begin
delay <= delay+16'd1; end
else begin
// data_reg <= data;
current_state <= next_state;
delay <= 0; end
end
default: ;
endcase
end
end
// always @ (current_state or intr_n or rst_n) begin
always @ (current_state or rst_n) begin
if(!rst_n) begin
idle <= 0;
start <= 1;
start_wait <= 2;
convert <= 3;
// read_flag <= 0;
end
else begin
case (current_state)
idle: begin
cs_n <= 1;
wr_n <= 1;
rd_n <= 1;
// read_flag <= 0;
next_state <= start; end
start: begin
cs_n <= 0;
wr_n <= 0;
rd_n <= 1;
// read_flag <= 0;
next_state <= start_wait; end
start_wait: begin
wr_n <= 1;
cs_n <= 1;
rd_n <= 1;
// read_flag <= 0;
// if(!intr_n) next_state <= convert;
// else
next_state <= start_wait;
end
convert: begin
cs_n <= 0;
rd_n <= 0;
wr_n <= 1;
// read_flag <= 1;
next_state <= idle; end
default: next_state <= idle;
endcase
end
end
/************************************** */
wire LED0_Out;
led0_module U3
(
.clk( clk ),
.rst_n( rst_n ),
.LED_Out( LED0_Out )
);
/*********************************/
wire LED1_Out;
led1_module U4
(
.clk( clk ),
.rst_n( rst_n ),
.LED_Out( LED1_Out )
);
/*********************************/
assign LED_Out = { LED0_Out, LED1_Out};
endmodule