版主: 51FPGA |
只为吸引你
![]()
最后登陆时间:2011-10-09 20:36:15 |
之前在这问过几个问题,都得到解答了,很感谢这里朋友,虽然素未谋面。呵呵,
我在使3E开发板里的AD,写了个程序。但是总也调不出来。我自己觉得可能是时序方面没没理解好。把程序贴上,希望大家帮我看下,哪里有问题,让我能调出AD来,谢谢了/ module adc(clk,reset,spi_miso,amp_cs,amp_shdn,spi_mosi,ad_conv,spi_sck,x); input clk,reset; input spi_miso; //AD变换后输出的数据 output amp_cs,amp_shdn,ad_conv,spi_sck; output spi_mosi; //8位可编程增益 output x; reg spi_mosi; reg amp_cs,ad_conv,amp_shdn; reg [1:0]counter1; always@(posedge clk or posedge reset) begin if(reset) begin counter1<=2'd0; end else begin if(counter1==2'd2) begin counter1<=2'd0; end else begin counter1<=counter1+1; end end end reg spi_sck; always@(posedge clk or posedge reset) begin if(reset) spi_sck<=1'b0; else begin if(counter1==2'd2) spi_sck<=1'b1; else spi_sck<=1'b0; end end reg [9:0]delay_count; reg [9:0]num_count; parameter state1 =6'b000001; parameter state2 =6'b000010; parameter state3 =6'b000011; parameter state4 =6'b000100; parameter state5 =6'b000101; parameter state6 =6'b000110; parameter state7 =6'b000111; parameter state8 =6'b001000; parameter state9 =6'b001001; parameter state10=6'b001010; parameter state11=6'b001011; parameter state12=6'b001100; parameter state13=6'b001101; parameter state14=6'b001110; reg[5:0]state; //状态信号 reg state_change; //状态改变信号 always@(posedge clk or posedge reset) if(reset) begin state_change<=1'b0; delay_count<=1'b0; end else if(delay_count==num_count-1) begin state_change<=1'b1; delay_count<=1'b0; end else begin state_change<=1'b0; delay_count<=delay_count+1'b1; end reg[13:0]data1; reg[3:0]count2; reg[13:0]rcv_data; always@(posedge state_change or posedge reset) if(reset) begin state<=state1; num_count<=10'd4; data1<=14'd0; count2<=4'd0; rcv_data<=14'b0111_1111_1111_11; end else case(state) state1:begin state<=state2; num_count<=10'd2; amp_cs<=1'b1; amp_shdn<=1'b1; ad_conv<=1'b1; end state2:begin state<=state3; num_count<=10'd60; amp_cs<=1'b0; amp_shdn<=1'b0; ad_conv<=1'b1; end state3:begin //spi-mosi八位增益 state<=state4; num_count<=10'd5; spi_mosi<=1'h0; ad_conv<=1'b1; end state4:begin state<=state5; num_count<=10'd5; spi_mosi<=1'h0; ad_conv<=1'b1; end state5:begin state<=state6; num_count<=10'd5; spi_mosi<=1'h0; ad_conv<=1'b1; end state6:begin state<=state7; num_count<=10'd5; spi_mosi<=1'h1; ad_conv<=1'b1; end state7:begin state<=state8; num_count<=10'd5; spi_mosi<=1'h0; ad_conv<=1'b1; end state8:begin state<=state9; num_count<=10'd5; spi_mosi<=1'h0; ad_conv<=1'b1; end state9:begin state<=state10; num_count<=10'd5; spi_mosi<=1'h0; ad_conv<=1'b1; end state10:begin state<=state11; num_count<=10'd5; spi_mosi<=1'h1; ad_conv<=1'b1; end //spi-mosi八位增益 state11:begin state<=state12; num_count<=10'd4; amp_cs<=1'b1; amp_shdn<=1'b1; ad_conv<=1'b0; end state12:begin state<=state13; num_count<=10'd202; if(count2==13) begin rcv_data<=data1; count2<=4'd0; end else begin data1<={spi_miso,data1[13:1]}; count2<=count2+1; end end state13:begin state<=state14; num_count<=10'd2; ad_conv<=1'b1; amp_cs<=1'b1; amp_shdn<=1'b1; end state14:begin state<=state11; num_count<=10'd4; end default:begin state<=state1; num_count<=10'd4; end endcase reg x; always@(posedge clk or posedge reset) begin if(reset) x<=1'b0; else x<=rcv_data[13]; end endmodule 我只用了rcv_data[13];,其他的没有使用。 关键词:sparten 使用 问题 听说 标题 很长 re |
![]() 改变自己。 |
|
jackwang
![]()
最后登陆时间:2015-01-29 08:45:11 |
请耐心等待~~~
|
![]() http://t.sina.com.cn/dolphinjetta。 |
|
只为吸引你
![]()
最后登陆时间:2011-10-09 20:36:15 |
呵呵,jack船长,我觉得使用这个开发板的人挺多的啊。为神马还是木有人帮我解答啊。。。。。
![]() |
![]() 改变自己。 |
|
Jason_Zhang
![]()
最后登陆时间:2015-01-20 09:30:43 |
又没有人是24小时泡论坛的,你那么迟发的,大家都休息了嘛。早上又这么早,呵呵 |
![]() My Email : zldpublic@gmail.com。 |
|
Jason_Zhang
![]()
最后登陆时间:2015-01-20 09:30:43 |
简单看了一下。现在手头没有Sparten 3E的板,没法帮你验证。 1. 状态机的写法不好,可参考“三段式”写法,我以前发过,论坛上有; |
![]() My Email : zldpublic@gmail.com。 |
|
只为吸引你
![]()
最后登陆时间:2011-10-09 20:36:15 |
恩,恩,我确实是想连续输出spi_miso,输出14个数,放到rcv_data中。你一说我才发现这确实写错了,呵呵。你
另外我也觉得状态机挺乱的。但是我这的一本书上有这样的程序,我就照葫芦画瓢了。呵呵,其他的写法我都不知道,真是知之甚少啊。 谢谢你哈,我先看你的写法去。呵呵 |
![]() 改变自己。 |
|
只为吸引你
![]()
最后登陆时间:2011-10-09 20:36:15 |
Jason_Zhang的原帖 简单看了一下。现在手头没有Sparten 3E的板,没法帮你验证。 1. 状态机的写法不好,可参考“三段式”写法,我以前发过,论坛上有; 恩,恩,我确实是想连续输出spi_miso,输出14个数,放到rcv_data中。你一说我才发现这确实写错了,呵呵。你 另外我也觉得状态机挺乱的。但是我这的一本书上有这样的程序,我就照葫芦画瓢了。呵呵,其他的写法我都不知道,真是知之甚少啊。 谢谢你哈,我先看你的写法去。呵呵 |
![]() 改变自己。 |
|
Jason_Zhang
![]()
最后登陆时间:2015-01-20 09:30:43 |
状态机的写法可以参考
http://forum.eepw.com.cn/thread/152907/1 |
![]() My Email : zldpublic@gmail.com。 |
|
只为吸引你
![]()
最后登陆时间:2011-10-09 20:36:15 |
看了,学习中···· |
![]() 改变自己。 |
|
Jason_Zhang
![]()
最后登陆时间:2015-01-20 09:30:43 |
|
![]() My Email : zldpublic@gmail.com。 |
|
共10条 1/1 1 |