当前位置:网站首页>FPGA采集DHT11温湿度
FPGA采集DHT11温湿度
2022-06-22 14:03:00 【奋斗小鹏】
一. 简介
在温湿度传感器中,dht11是使用的最多的一个,在很多课设,毕设中是首选。仅需要一个IO口,就可以完成温湿度采集。在这里分享利用FPGA来完成DHT11温湿度采集的一个demo分享。
需要完整代码的可以关注微信公众号 FPGA之旅回复 DHT11-FPGA 获取
二. 温湿度采集
- 数据传输过程包括以下三个部分 : 采集开始,采集数据,采集结束。
- 采集开始,FPGA拉低数据线,然后释放,等待dht11响应。
- 采集数据为40bit,分别为(高到底) 8bit湿度整数位,8bit湿度小数位,8bit温度整数位,8bit温度小数位,8bit校验和。
- 校验和为温湿度数据之合的后8位。
- 采集结束,从机拉低数据线。
数据传输过程还是比较容易的,下面来详细说明一下各个部分的持续情况。
(1) 采集开始
- FPGA拉低数据线最少18ms,推荐20ms。释放总线,等待从机拉低总线响应。响应接收后,总线被释放。详细过程如下。

(2) 采集数据
数据表示:数据0 : 50us的低电平加26us~28us的高电平 。数据1:50us的低电平加70us的高电平
(3) 采集结束
从机拉低总线50us。
这里的时间可以根据实际测试的结果进行调整。这很重要,不然可能会出现采集到的数据不准确的情况。
三. 代码实现
需要完整代码的可以关注微信公众号 FPGA之旅回复 DHT11-FPGA 获取
这里采用三段式状态机来实现,比较方便。由传输过程可以轻松确定整个采集过程由四个状态确定。
下面是用逻辑分析仪得到的采集结果,可以看到在S_OVER中,已经采集到了一次完整的数据。
通过计算42 + 05 + 1D + 03 = 67 (十六进制)可以确定采集到的数据是完全正确的。
module DTH11(
input clk,
input rst,
inout dht11,
input dht11_req, //数据采集请求
output dht11_down, //数据采集完成
output[7:0] tempH, //温度数据整数
output[7:0] tempL, //温度数据小数
output[7:0] humidityH, //温度数据整数
output[7:0] humidityL //温度数据小数
);
localparam S_IDLE = 'd0; //空闲状态
localparam S_START = 'd1; //开始采集数据
localparam S_DATA = 'd2; //接收采集到的数据
localparam S_OVER = 'd3; //数据采集完成
状态转移过程
- S_START: 采集请求过来的时候,就进入到开始状态
- S_DATA:step表示start状态中的四个部分,分别为主机拉低,从机响应开始和结束以及数据传输开始。
- S_OVER:step表示接收到数据的个数,当接收到数据为40的时候,进入S_OVER状态
- S_IDLE : timeCount 拉低时间结束进入S_IDLE状态。
[email protected](*)
begin
case(state)
S_IDLE:
if(dht11_req == 1'b1)
next_state <= S_START;
else
next_state <= S_IDLE;
S_START:
if(step == 'd4)
next_state <= S_DATA;
else
next_state <= S_START;
S_DATA:
if(step == 'd40)
next_state <= S_OVER;
else
next_state <= S_DATA;
S_OVER:
if(timeCount == Time50us)
next_state <= S_IDLE;
else
next_state <= S_OVER;
default:
next_state <= S_IDLE;
endcase
end
边栏推荐
- 扩散模型又杀疯了!这一次被攻占的领域是...
- After 100 days, Xiaoyu built a robot communication community!! Now invite moderators!
- Redistemplate serialization
- Support vector machine for machine learning
- U++ programming array learning notes
- Are there many unemployed people in 2022? Is it particularly difficult to find a job this year?
- 那些令人懵逼的用户态&内核态
- Driving the efficient growth of the manufacturing industry, UFIDA u9 cloud is constantly improving the password behind it
- ROS2前置基础教程 | 小鱼教你用CMake依赖查找流程
- Groovy list operation
猜你喜欢
![[Software Engineering] acquire requirements](/img/52/01320eee5e519910a62f48d604b180.png)
[Software Engineering] acquire requirements
![[Zhejiang University] information sharing of the first and second postgraduate entrance examinations](/img/15/298ea6f7367741e1e085007c498e51.jpg)
[Zhejiang University] information sharing of the first and second postgraduate entrance examinations

本周四晚19:00战码先锋第7期直播丨三方应用开发者如何为开源做贡献

KEIL仿真和vspd

ML笔记-matrix fundamental, Gradient Descent

PHP built-in protocols (supported and encapsulated protocols)

Reading of double pointer instrument panel (II) - Identification of dial position

The diffusion model is crazy again! This time the occupied area is

Zhongshanshan: engineers after being blasted will take off | ONEFLOW u

Is the encryption market a "natural disaster" or a "man-made disaster" in the cold winter?
随机推荐
Redistemplate serialization
谷歌竞价账户可以探测到全球市场吗?
NF RESNET: network signal analysis worth reading after removing BN normalization | ICLR 2021
Reading of double pointer instrument panel (II) - Identification of dial position
Can Google bidding account detect the global market?
Biden signs two new laws aimed at strengthening government cyber security
U++ programming array learning notes
PowerPoint 教程,如何在 PowerPoint 中添加水印?
What are the five characteristics of network security? What are the five attributes?
FreeRTOS task priority and interrupt priority
Bochs software usage record
Front and back management system of dessert beverage store based on SSM framework dessert mall cake store [source code + database]
Token processing during API encapsulation
A thorough understanding of singleton
Closure of groovy
RealNetworks vs. 微软:早期流媒体行业之争
【毕业设计】基于半监督学习和集成学习的情感分析研究
Is the encryption market a "natural disaster" or a "man-made disaster" in the cold winter?
Groovy list operation
We will resolutely fight and win the hard battle of flood control and disaster relief and spare no effort to ensure the safety of people's lives and property