夏老师!!您好!!我刚开始学verilog,这是我写的AD芯片的TCL549的驱动程序,可是一直不好用,请您看看哪里错了?
module ad_convert(
clk, //系统时钟50MH
rst_n, //复位信号
adc_clk, //AD转换时钟
adc_data, //输出的AD数据
adc_cs_n, //AD片选信号
digit_o, //数码管段选信号
cs //数码管位选信号
);
input clk;
input rst_n;
input adc_data;
output adc_clk;
output adc_cs_n;
output [7:0] digit_o;
output [1:0] cs;
reg [4:0] count;
reg clk_64;
always @(posedge clk)
begin
count<=count+1;
if(count==0)
clk_64<=~clk_64;
end
assign adc_clk=clk_64;
integer i;
parameter
ini = 10'b1000000000,
waite = 10'b0100000000,
conver_1 = 10'b0010000000,
conver_2 = 10'b0001000000,
conver_3 = 10'b0000100000,
conver_4 = 10'b0000010000,
conver_5 = 10'b0000001000,
conver_6 = 10'b0000000100,
conver_7 = 10'b0000000010,
conver_8 = 10'b0000000001;
reg [9:0]state,state_next;
reg [2:0] cnt;
reg [1:0] num;
reg adc_cs_n;
initial state_next<=ini;
always @ (posedge clk_64 or negedge rst_n)
begin
if(!rst_n)
state<=ini;
else
begin
state<=state_next;
end
end
reg [7:0] cs_n,digit;
always @ (state)
begin
case(state)
ini : begin
num<=num+1;
adc_cs_n<=0;
if(num==0)
begin
// adc_cs_n<=0;
state_next<=conver_1;
end
end
conver_1 : begin
// adc_cs_n<=0;
digit[7]<=adc_data;
state_next<=conver_2;
end
conver_2 : begin
// adc_cs_n<=0;
digit[6]<=adc_data;
state_next<=conver_3;
end
conver_3 : begin
// adc_cs_n<=0;
digit[5]<=adc_data;
state_next<=conver_4;
end
conver_4 : begin
// adc_cs_n<=0;
digit[4]<=adc_data;
state_next<=conver_5;
end
conver_5 : begin
// adc_cs_n<=0;
digit[3]<=adc_data;
state_next<=conver_6;
end
conver_6 : begin
// adc_cs_n<=0;
digit[2]<=adc_data;
state_next<=conver_7;
end
conver_7 : begin
// adc_cs_n<=0;
digit[1]<=adc_data;
state_next<=conver_8;
end
conver_8 : begin
// adc_cs_n<=0;
digit[0]<=adc_data;
state_next<=waite;
end
waite : begin
cnt<=cnt+1;
adc_cs_n<=1;
if(cnt==0)
begin
state_next<=ini;
end
end
default : state_next<='bx;
endcase
end
nixie_light(0,digit[7:0],cs,digit_o);
endmodule
转换时钟小于17us |