① FPGA採集多路溫度,買了一塊FPGA開發板,晶元EP1C3T144C8.溫度感測器用DS18B20,Verilog編程怎麼寫,求助
第一個文件:ds18b20.v
`timescale 1ns / 1ps
mole ds18b20 (
clk, chipselect, read_n, //input
readdata, //output
dio ); //inout
input clk, chipselect, read_n;
output [15:0] readdata;
inout dio;
reg [31:0] ro=32'hbecc44cc;
reg [15:0] ri;
reg [15:0] pout;
reg [ 5:0] count;
reg [12:0] cnt;
reg dout;
wire clk781_25khz;
assign clk781_25khz=count[5];
always @(posedge clk) count<=count+1'b1;
always @(posedge clk781_25khz) cnt<=cnt+1'b1;
always @(posedge cnt[12]) pout<=ri;
assign readdata=(chipselect & ~read_n)? pout : 16'b0;
reg reset,lo, hi,rd;
always @(posedge cnt[0]) reset<=cnt[12]|cnt[10]|cnt[9];
always @(posedge cnt[0]) lo <=|cnt[5:1] | ~cnt[10];
always @(posedge cnt[0]) hi <=&cnt[5:1] | ~cnt[10];
always @(posedge cnt[0]) rd <=cnt[3]|cnt[4]|cnt[5]|~cnt[10]|cnt[11]|~cnt[12];
always @(negedge lo or posedge cnt[12])
if (cnt[12]==1) ro<=32'hbecc44cc;
else {ro[30:0],dout} <= ro;
always @(posedge rd) ri <= {dio,ri[15:1]};
assign dio=reset&(hi|(lo&dout))?1'bz:1'b0;
endmole
第二個文件:ds18b20_hw.tcl
# TCL File Generated by Component Editor 11.0
# Mon Dec 12 00:54:43 CST 2011
# DO NOT MODIFY
# +-----------------------------------
# |
# | ds18b20 "ds18b20" v1.0
# | null 2011.12.12.00:54:43
# |
# |
# | D:/myip11/ds18b20.v
# |
# | ./ds18b20.v syn, sim
# |
# +-----------------------------------
# +-----------------------------------
# | request TCL package from ACDS 11.0
# |
package require -exact sopc 11.0
# |
# +-----------------------------------
# +-----------------------------------
# | mole ds18b20
# |
set_mole_property NAME ds18b20
set_mole_property VERSION 1.0
set_mole_property INTERNAL false
set_mole_property OPAQUE_ADDRESS_MAP true
set_mole_property DISPLAY_NAME ds18b20
set_mole_property TOP_LEVEL_HDL_FILE ds18b20.v
set_mole_property TOP_LEVEL_HDL_MODULE ds18b20
set_mole_property INSTANTIATE_IN_SYSTEM_MODULE true
set_mole_property EDITABLE true
set_mole_property ANALYZE_HDL TRUE
set_mole_property STATIC_TOP_LEVEL_MODULE_NAME "ds18b20"
set_mole_property FIX_110_VIP_PATH false
# |
# +-----------------------------------
# +-----------------------------------
# | files
# |
add_file ds18b20.v {SYNTHESIS SIMULATION}
# |
# +-----------------------------------
# +-----------------------------------
# | parameters
# |
# |
# +-----------------------------------
# +-----------------------------------
# | display items
# |
# |
# +-----------------------------------
# +-----------------------------------
# | connection point clock
# |
add_interface clock clock end
set_interface_property clock clockRate 0
set_interface_property clock ENABLED true
add_interface_port clock clk clk Input 1
# |
# +-----------------------------------
# +-----------------------------------
# | connection point avalon_slave_0
# |
add_interface avalon_slave_0 avalon end
set_interface_property avalon_slave_0 addressAlignment NATIVE
set_interface_property avalon_slave_0 addressUnits WORDS
set_interface_property avalon_slave_0 associatedClock clock
set_interface_property avalon_slave_0 associatedReset clock_reset
set_interface_property avalon_slave_0 burstOnBurstBoundariesOnly false
set_interface_property avalon_slave_0 explicitAddressSpan 0
set_interface_property avalon_slave_0 holdTime 0
set_interface_property avalon_slave_0 isMemoryDevice false
set_interface_property avalon_slave_0 isNonVolatileStorage false
set_interface_property avalon_slave_0 linewrapBursts false
set_interface_property avalon_slave_0 0
set_interface_property avalon_slave_0 printableDevice false
set_interface_property avalon_slave_0 readLatency 0
set_interface_property avalon_slave_0 readWaitTime 1
set_interface_property avalon_slave_0 setupTime 0
set_interface_property avalon_slave_0 timingUnits Cycles
set_interface_property avalon_slave_0 writeWaitTime 0
set_interface_property avalon_slave_0 ENABLED true
add_interface_port avalon_slave_0 chipselect chipselect Input 1
add_interface_port avalon_slave_0 read_n read_n Input 1
add_interface_port avalon_slave_0 readdata readdata Output 16
# |
# +-----------------------------------
# +-----------------------------------
# | connection point conit_end
# |
add_interface conit_end conit end
set_interface_property conit_end ENABLED true
add_interface_port conit_end dio export Bidir 1
# |
# +-----------------------------------
以上兩個文件均在quartus 11中完成,成文DS18B20一個IP.
接下來:將本IP掛接到阿瓦龍匯流排上,直接讀取16位的整數,再根據數據手冊把溫度翻譯為可理解的內容即可。
② 壓力感測器傳過來4-20MA信號 怎麼編程才可以使用它。
採用I/V 模式進行數據轉換就可以了。
兩種方法:
1經過I/V轉換後,直接ADC采樣,計算出4mA電流對應的電壓,將此值設為輸出顯示的0,以後4~20mA線性輸出即為需要。
2製作一個-20mA對應的減壓基準【這種電壓基準很多,分壓後得到】,連接到電路中抵掉4mA,以後按照線性輸出即可。
所謂的I/V轉換就是電流輸入經過合適的電阻【需要精密電阻】網路,在某個電阻網路中得到的分壓。
③ 單片機應用程序的開發步驟
具體步驟如下:
1、首先,開啟我們的keil軟體,具體的安裝步驟就不做太多的介紹內了;
開啟後,點擊菜容單欄上的Project選項,創建我們的工程,如圖所示;
編譯完成後,在我們的文件夾下找到.hex的文件,將其燒寫到我們的晶元中即可。