① 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的文件,将其烧写到我们的芯片中即可。