2022年ADDA等一些芯片的verilog程序[参 .pdf





《2022年ADDA等一些芯片的verilog程序[参 .pdf》由会员分享,可在线阅读,更多相关《2022年ADDA等一些芯片的verilog程序[参 .pdf(20页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、/* AD0809 module v1.0 work up to 5M sample = 25us 40khz for normal clk = 2.5M sample = 30us 33khz */ module ad0809( clkin, adclk, eoc, st, ale, datain, oe, dataout ); input clkin; input eoc; input 7:0datain; output st; output ale; output oe; output adclk; output 7:0dataout; reg adclk; reg 7:0dataout
2、; reg st; reg oe; reg ale; /frequence divider for AD parameter Div_adclk = 8d9;/(9+1)*2=20 adclk=2.5M parameter Div_clk_state = 4d4;/(4+1)*2=10 clk_state=5M 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 20 页 - - - - - - - - - reg 8:0div_cnt_ad;/frequence div c
3、nt reg 3:0div_cnt_state; reg clk_state; always(negedge clkin)begin if(div_cnt_ad != Div_adclk) div_cnt_ad = div_cnt_ad + 1b1; else begin div_cnt_ad = 0; adclk = adclk; end if(div_cnt_state != Div_clk_state) div_cnt_state = div_cnt_state + 1b1; else begin div_cnt_state = 0; clk_state = clk_state; end
4、 end /*AD convert*/ reg 3:0state; reg 7:0delay; initial begin state = 4d0; end always(negedge clk_state)begin case(state) 4d0:begin /clear all st = 1b0; oe = 1b0; ale = 1b0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 20 页 - - - - - - - - - delay = 8h00; sta
5、te = 4d1; end 4d1:begin /ale latch ale = 1b1; state = 4d2; end 4d2:begin /st rasing st = 1b1; state = 4d3; end 4d3:begin /ale falling ale = 1b0; state = 4d4; end 4d4:begin /st falling st = 1b0; state = 4d5; end 4d5:begin/eoc delay after st; 8clock+2us = 26stata_clk delay = delay + 1b1; if(delay = 8d
6、26) state = 4d6; else state = 4d5; end 4d6:begin /test eoc(convete finished); if(eoc) state = 4d7; else state = 4d6; end 4d7:begin /out enable oe = 1b1; state = 4d8; end 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 20 页 - - - - - - - - - 4d8:begin /take data
7、dataout = datain; state = 4d9; end 4d9:begin /out unable; return oe = 1b0; state = 4d0; end default: state = 4d0; endcase end endmodule /* clk = 5Mhz T = 0.2us the distance = 0.2 * 1000_000 * data *340m/s */ module chao (clk, start ,reset, trig, echo,data,success,time_out); input clk,start,reset,ech
8、o; output trig,data,success,time_out; reg trig,time_out,success; reg 31:0data; reg 3:0state; parameter Prepare = 4d1; parameter Delay_trig = 4d2; parameter Echo_raising = 4d3; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 20 页 - - - - - - - - - parameter Echo_
9、falling = 4d4; parameter Time_out = 4d5; parameter Success = 4d6; reg 7:0dely; /60*0.2=12us reg 31:0timer; /if timer is bigger than 0 x1e848 (far than 4.0 m),time out always(negedge clk or negedge reset)begin if(!reset)begin state = Prepare; end else begin case(state) Prepare:begin timer = 32h0000_0
10、000; trig = 1b0; /success = 1b0; /time_out = 1b0; if(!start)begin trig = 1b1;/trig the device dely = 8b0000_0000; state = Delay_trig; end else begin state = Prepare; end end Delay_trig:begin /delay 12us dely = dely + 1b1; if(dely != 8d60)begin /60 state = Delay_trig; 名师资料总结 - - -精品资料欢迎下载 - - - - - -
11、 - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 20 页 - - - - - - - - - end else begin trig = 1b0; /end of trig state = Echo_raising; end end Echo_raising:begin /wait for echo rassing timer = timer + 1b1; if(echo)begin timer = 32d0;state = Echo_falling; end else begin state = 32d2250)begin/450u
12、s timer = 32d0; state = Prepare; end else begin if(echo)begin timer = 32d0;state = Echo_falling; end else begin state = Echo_raising; end end*/ end Echo_falling:begin /wait for echo falling or timeouttimer = 32d120000)begin /out of 10m state = Time_out; end else begin if(!echo)begin data = timer;sta
13、te = Success;end else begin state = Echo_falling; end end end 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 20 页 - - - - - - - - - Time_out:begin time_out = time_out; state = Prepare; end Success:begin success = success; state = Prepare; end default:begin stat
14、e = Prepare; end endcase end/end of if end endmodule /* clk = 5Mhz T = 0.2us the distance = 0.2 * 1000_000 * data *340m/s */ module chao (clk, start ,reset, trig, echo,data,success,time_out); input clk,start,reset,echo; output trig,data,success,time_out; reg trig,time_out,success; reg 31:0data; reg
15、3:0state; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 20 页 - - - - - - - - - parameter Prepare = 4d1; parameter Delay_trig = 4d2; parameter Echo_raising = 4d3; parameter Echo_falling = 4d4; parameter Time_out = 4d5; parameter Success = 4d6; reg 7:0dely; /60*
16、0.2=12us reg 31:0timer; /if timer is bigger than 0 x1e848 (far than 4.0 m),time out always(negedge clk or negedge reset)begin if(!reset)begin state = Prepare; end else begin case(state) Prepare:begin timer = 32h0000_0000; trig = 1b0; /success = 1b0; /time_out = 1b0; if(!start)begin trig = 1b1;/trig
17、the device dely = 8b0000_0000; state = Delay_trig; end else begin state = Prepare; end end Delay_trig:begin /delay 12us 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 20 页 - - - - - - - - - dely = dely + 1b1; if(dely != 8d60)begin /60 state = Delay_trig; end el
18、se begin trig = 1b0; /end of trig state = Echo_raising; end end Echo_raising:begin /wait for echo rassing timer = timer + 1b1; if(echo)begin timer = 32d0;state = Echo_falling; end else begin state = 32d2250)begin/450us timer = 32d0; state = Prepare; end else begin if(echo)begin timer = 32d0;state =
19、Echo_falling; end else begin state = Echo_raising; end end*/ end Echo_falling:begin /wait for echo falling or timeouttimer = 32d120000)begin /out of 10m state = Time_out; end else begin if(!echo)begin data = timer;state = Success;end else begin state = Echo_falling; end end end 名师资料总结 - - -精品资料欢迎下载
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年ADDA等一些芯片的verilog程序参 2022 ADDA 一些 芯片 verilog 程序

限制150内