DAC使用的LTC2624的产品,个人感觉时序比较简单,这是个好事情,然后发现网上的资料也少,就贴出来给初学者们一个参考吧,FPGA的电压时3.3V的LVCOMS33的io标准,然后只是搞了一个简单的高电平,电压为1/2的3.3V 所以用万用表便可以拿来验证了。
下面就给代码吧。核心代码是一个计数器式的状态机
module DAC_TEST(
CLK,
SPI_SCK ,
DAC_CLR ,
DAC_CS ,
SPI_MOSI
);
input CLK;
output SPI_SCK;
output DAC_CLR;
output DAC_CS;
output SPI_MOSI;
reg DAC_CLR = 1;
reg DAC_CS;
reg SPI_MOSI;
reg [3:0] DAC_C = 4'b0011;
reg [3:0] DAC_A = 0;
reg [11:0] DAC_V = 12'h800 ;
reg SPI_CLK = 0;
always @ ( posedge CLK ) begin
SPI_CLK <= ~SPI_CLK ;
end
reg [15:0] state_counter = 0;
always @ ( negedge SPI_CLK ) begin
if ( state_counter == 16'd32 )
state_counter <= 0;
else
state_counter <= state_counter + 1'b1 ;
end
/*
reg SPI_SCK_C = 0 ;
always @ ( negedge SPI_CLK ) begin
case ( state_counter )
0: SPI_SCK_C <= 1 ;
32: SPI_SCK_C <= 0 ;
endcase
end*/
always @ ( negedge SPI_CLK ) begin
case ( state_counter )
0 : DAC_CS <= 0 ;
32: DAC_CS <= 1 ;
endcase
end
always @ ( negedge SPI_CLK ) begin
case ( state_counter )
8 : SPI_MOSI <= DAC_C[3] ;
9 : SPI_MOSI <= DAC_C[2] ;
10 : SPI_MOSI <= DAC_C[1] ;
11 : SPI_MOSI <= DAC_C[0] ;
12 : SPI_MOSI <= DAC_A[3] ;
13 : SPI_MOSI <= DAC_A[2] ;
14 : SPI_MOSI <= DAC_A[1] ;
15 : SPI_MOSI <= DAC_A[0] ;
16 : SPI_MOSI <= DAC_V[11] ;
17 : SPI_MOSI <= DAC_V[10] ;
18 : SPI_MOSI <= DAC_V[9] ;
19 : SPI_MOSI <= DAC_V[8] ;
20 : SPI_MOSI <= DAC_V[7] ;
21 : SPI_MOSI <= DAC_V[6] ;
22 : SPI_MOSI <= DAC_V[5] ;
23 : SPI_MOSI <= DAC_V[4] ;
24 : SPI_MOSI <= DAC_V[3] ;
25 : SPI_MOSI <= DAC_V[2] ;
26 : SPI_MOSI <= DAC_V[1] ;
27 : SPI_MOSI <= DAC_V[0] ;
endcase
end
assign SPI_SCK = SPI_CLK ;
endmodule
用户536736 2009-8-5 11:23
用户563816 2009-7-30 23:32
用户563816 2009-7-30 23:18
用户146077 2009-7-30 21:47
tengjingshu_112148725 2009-7-30 14:40