论坛元老
- 积分
- 4467
- 金钱
- 4467
- 注册时间
- 2013-6-27
- 在线时间
- 565 小时
|
1金钱
AdSram模块
Clk 使用CPLD时钟60MHz
Rst_n 控制模块采集开启及关闭
Freq 接单片机PWM控制Ad采集速度
外接2片2048*16 SRAM
output reg SramCs0,
output reg SramCs1,
output reg SramRd,
output reg SramWd,
output reg[20:0] SramA,
接2片AD9238双通道12AD,总共4路AD输入通道
output reg AdClk,
output reg AdA,
output reg AdB,
DoneFlag 采集完成标记,通知单片机中断
问题:使用单片机PWM接Freq,只有偶尔能采集?接CPLD的60MHz分频的信号,可以正常采集。
求为什么会出现这个想象,是代码哪里设计有什么问,望朋友帮忙看下。
[mw_shl_code=applescript,true]module AdSram(
input Clk,
input Rst_n,
input Freq,
output reg AdClk,
output reg AdA,
output reg AdB,
output reg SramCs0,
output reg SramCs1,
output reg SramRd,
output reg SramWd,
output reg[20:0] SramA,
output reg DoneFlag);
//`define S_MAX_NUM 20'hFFFFF
`define S_MAX_NUM 5
parameter WAIT = 0;
parameter DONE = 1;
parameter ADA1RD = 2;
parameter ADA1WR = 3;
parameter ADB1RD = 4;
parameter ADB1WR = 5;
parameter ADA2RD = 6;
parameter ADA2WR = 7;
parameter ADB2RD = 8;
parameter ADB2WR = 9;
parameter IDLE = 10;
parameter WAITF1 = 11;
reg [3:0] state_c,state_n;
wire IDLE_WAIT;
wire WAIT_ADA1RD;
wire ADA1RD_ADA1WR;
wire ADA1WR_ADB1RD;
wire ADB1RD_ADB1WR;
wire ADB1WR_ADA2RD;
wire ADA2RD_ADA2WR;
wire ADA2WR_ADB2RD;
wire ADB2RD_ADB2WR;
wire ADB2WR_WAITF1;
wire WAITF1_WAIT;
wire WAIT_DONE;
// Input Freq Sync
reg freq,freq0;
always @(posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
freq <= 1'b1;
freq0 <= 1'b1;
end
else begin
freq0 <= Freq;
freq <= freq0;
end
end
reg [3:0] setp_cnt;
always @(posedge Clk or negedge Rst_n)begin
if(Rst_n==1'b0)begin
setp_cnt <= 0;
end
else begin
case(state_c)
ADA1RD,ADA1WR,ADA2RD,ADA2WR,ADB1RD,ADB1WR,ADB2RD,ADB2WR:
setp_cnt <= setp_cnt + 1;
default:
setp_cnt <= 0;
endcase
end
end
reg [19:0] AddCnt;
always @(posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
AddCnt <= 0;
end
else begin
case(state_c)
DONE:
AddCnt <= 0;
default:begin
if(setp_cnt == 7)
AddCnt <= AddCnt + 1;
end
endcase
end
end
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
state_c <= IDLE;
end
else begin
state_c <= state_n;
end
end
always @(*)begin
case(state_c)
IDLE:
begin
if(IDLE_WAIT)begin
state_n = WAIT;
end
else begin
state_n = state_c;
end
end
WAIT:
begin
if(WAIT_ADA1RD)begin
state_n = ADA1RD;
end
else if(WAIT_DONE)begin
state_n = DONE;
end
else begin
state_n = state_c;
end
end
DONE:
begin
state_n = state_c;
end
ADA1RD:
begin
if(ADA1RD_ADA1WR)begin
state_n = ADA1WR;
end
else begin
state_n = state_c;
end
end
ADA1WR:
begin
if(ADA1WR_ADB1RD)begin
state_n = ADB1RD;
end
else begin
state_n = state_c;
end
end
ADB1RD:
begin
if(ADB1RD_ADB1WR)begin
state_n = ADB1WR;
end
else begin
state_n = state_c;
end
end
ADB1WR:
begin
if(ADB1WR_ADA2RD)begin
state_n = ADA2RD;
end
else begin
state_n = state_c;
end
end
ADA2RD:
begin
if(ADA2RD_ADA2WR)begin
state_n = ADA2WR;
end
else begin
state_n = state_c;
end
end
ADA2WR:
begin
if(ADA2WR_ADB2RD)begin
state_n = ADB2RD;
end
else begin
state_n = state_c;
end
end
ADB2RD:
begin
if(ADB2RD_ADB2WR)begin
state_n = ADB2WR;
end
else begin
state_n = state_c;
end
end
ADB2WR:
begin
if(ADB2WR_WAITF1)begin
state_n = WAITF1;
end
else begin
state_n = state_c;
end
end
WAITF1:
begin
if(WAITF1_WAIT)begin
state_n = WAIT;
end
else begin
state_n = state_c;
end
end
default:begin
state_n = IDLE;
end
endcase
end
assign IDLE_WAIT = (state_c == IDLE) && (Rst_n == 1);
assign WAIT_DONE = (state_c == WAIT) && (AddCnt == `S_MAX_NUM);
assign WAIT_ADA1RD = (state_c == WAIT) && (freq == 0) && (AddCnt < `S_MAX_NUM);
assign ADA1RD_ADA1WR = (state_c == ADA1RD) && (setp_cnt == 0);
assign ADA1WR_ADB1RD = (state_c == ADA1WR) && (setp_cnt == 1);
assign ADB1RD_ADB1WR = (state_c == ADB1RD) && (setp_cnt == 2);
assign ADB1WR_ADA2RD = (state_c == ADB1WR) && (setp_cnt == 3);
assign ADA2RD_ADA2WR = (state_c == ADA2RD) && (setp_cnt == 4);
assign ADA2WR_ADB2RD = (state_c == ADA2WR) && (setp_cnt == 5);
assign ADB2RD_ADB2WR = (state_c == ADB2RD) && (setp_cnt == 6);
assign ADB2WR_WAITF1 = (state_c == ADB2WR) && (setp_cnt == 7);
assign WAITF1_WAIT = (state_c == WAITF1) && (freq == 1);
// AD Output
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
AdClk <= 1'b0;
end
else begin
case(state_c)
ADA1RD,ADA1WR,ADB1RD,ADB1WR:
AdClk <= 1'b1;
default:
AdClk <= 1'b0;
endcase
end
end
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
AdA <= 1'b1;
end
else begin
case(state_c)
ADA1RD,ADA1WR,ADA2RD,ADA2WR:
AdA <= 1'b0;
default:
AdA <= 1'b1;
endcase
end
end
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
AdB <= 1'b1;
end
else begin
case(state_c)
ADB1RD,ADB1WR,ADB2RD,ADB2WR:
AdB <= 1'b0;
default:
AdB <= 1'b1;
endcase
end
end
// Sram Out
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
SramCs0 <= 1'bz;
end
else begin
case(state_c)
ADA1RD,ADA1WR,ADB1RD,ADB1WR:
SramCs0 <= 1'b0;
default:
SramCs0 <= 1'b1;
endcase
end
end
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
SramCs1 <= 1'bz;
end
else begin
case(state_c)
ADA2RD,ADA2WR,ADB2RD,ADB2WR:
SramCs1 <= 1'b0;
default:
SramCs1 <= 1'b1;
endcase
end
end
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
SramRd <= 1'bz;
end
else begin
SramRd <= 1'b1;
end
end
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
SramWd <= 1'bz;
end
else begin
case(state_c)
ADA1RD,ADA2RD,ADB1RD,ADB2RD:
SramWd <= 1'b0;
default:
SramWd <= 1'b1;
endcase
end
end
//Sram A[19:0]
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
SramA[19:0] <= 20'bz;
end
else begin
//if(state_c == WAIT)begin
SramA[19:0] <= AddCnt[19:0];
//end
end
end
//Sram A[20]
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
SramA[20] <= 1'bz;
end
else begin
case(state_c)
ADA1RD,ADA1WR,ADA2RD,ADA2WR:
SramA[20] <= 1'b0;
default:
SramA[20] <= 1'b1;
endcase
end
end
// DoneFlag
always @ (posedge Clk or negedge Rst_n)begin
if(Rst_n == 1'b0)begin
DoneFlag <= 1'b0;
end
else begin
case(state_c)
DONE:
DoneFlag <= 1'b1;
default:
DoneFlag <= 1'b0;
endcase
end
end
endmodule[/mw_shl_code]
|
|