当前位置:网站首页>【FPGA】串口以命令控制温度采集
【FPGA】串口以命令控制温度采集
2022-06-24 22:15:00 【机智的橙子】
一.任务要求
能够通过串口向FPGA芯片发送命令,以命令控制FPGA接收温度传感器数据,以及串口发送和数码管显示。该项目以前面学习的ds18b20温度传感器为例。
二.设计思路
①温度传感器返回数据是二进制的形式,为了方便后续处理,我们需要先将数据转换为bcd码的形式。
BCD码(Binary-Coded Decimal),用4位二进制数来表示1位十进制数中的0~9这10个数码,是一种二进制的数字编码形式,用二进制编码的十进制代码。BCD码这种编码形式利用了四个位元来储存一个十进制的数码,使二进制和十进制之间的转换得以快捷的进行。相对于一般的浮点式记数法,采用BCD码,既可保存数值的精确度,又可免去使计算机作浮点运算时所耗费的时间。此外,对于其他需要高精确度的计算,BCD编码亦很常用。
在这里,我们采用的是8421BCD码,也就是采用4位二进制的前十组代码表示0~9。
方法是:将要转的二进制值向左移动,一旦表示一位十进制数的4位二进制的值大于4,就加上3。
具体如下:
②串口以ASCII的形式收发数据,所以我们需要两个模块用于ASCII码和16进制数据转换。
根据下表对串口输入数据进行操作:
ASCII转16进制数据(关键代码):
这部分用于将串口发送的数据转换成我们需要的16进制命令,而该命令以两个16进制数据组成,所以该模块需要一次输出连续处理的两个数据。
[email protected](posedge clk or negedge rst_n)begin
if(!rst_n)begin
tmp <= 0;
end
else if(din >= 8'h30 && din <= 8'h39)begin//0~9
tmp <= din - 8'h30;
end
else if(din >= 8'h41 && din <= 8'h46)begin//A~F
tmp <= din - 8'h37;
end
else if(din >= 8'h61 && din <= 8'h66)begin//a~f
tmp <= din - 8'h57;
end
end
16进制转ASCII(关键代码):
[email protected](posedge clk or negedge rst_n)begin
if(!rst_n)begin
data <= 0;
end
else if(din_vld)begin
data <= din + 8'h30;//16进制数与相应ASCII数相差8'h30
end
end
③命令解析,接收到串口发送的相关命令后,对数码管,串口发送以及温度采集的使能信号开启。
这里使用了一个帧结构,包含帧头,命令,帧尾。简单用一个状态机(含有三个状态,对应帧结构)
④设计一个控制模块,例化上述模块,对接收的串口数据进行转换,命令解析,温度传感器的数据进行转换,将各个使能信号传递给相应模块。
三.代码实现
略
边栏推荐
- 全排列II[存在相同元素去重 + 标准回溯]
- How to get the picture outside the chain - Netease photo album [easy to understand]
- Please run IDA with elevated permissons for local debugging.
- Half of the year has passed. How many flags have been achieved at the end of the year?
- [mobile terminal] design size of mobile phone interface
- What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?
- 多模态数据也能进行MAE?伯克利&谷歌提出M3AE,在图像和文本数据上进行MAE!最优掩蔽率可达75%,显著高于BERT的15%
- Cusdis - lightweight, privacy first open source comment system | chain of the city
- Cusdis - 轻量级、隐私优先的开源评论系统 | 倾城之链
- DDD概念复杂难懂,实际落地如何设计代码实现模型?
猜你喜欢

After integrating the aurora push plug-in in the uni app, the real machine debugging prompts "the currently running base does not contain the native plug-in [jg-jpush]..." Solutions to problems

JS array object to object

The innovation consortium of Haihe laboratory established gbase and became one of the first member units of the innovation Consortium (Xinchuang)

Application session coverage solutions with different ports on the same server

創新藥二級市場審餅疲勞:三期臨床成功、產品獲批也不管用了
![Full arrangement ii[duplicate removal of the same elements + standard backtracking]](/img/d3/93ddb49e580be60be4f056f141b782.png)
Full arrangement ii[duplicate removal of the same elements + standard backtracking]
![uni-app集成极光推送插件后真机调试提示“当前运行的基座不包含原生插件[JG-JPush]...”问题的解决办法](/img/8b/0e982711c225ec8b0a2b90819d8a11.png)
uni-app集成极光推送插件后真机调试提示“当前运行的基座不包含原生插件[JG-JPush]...”问题的解决办法

Hands on data analysis data modeling and model evaluation

DDD概念复杂难懂,实际落地如何设计代码实现模型?

Day 04 - file IO
随机推荐
Unity C # e-learning (VI) -- FTP (II)
SQL aggregate function handling null [easy to understand]
监听 Markdown 文件并热更新 Next.js 页面
最长连续序列[扩散法+空间换时间]
DDD概念复杂难懂,实际落地如何设计代码实现模型?
Some Modest Advice for Graduate Students - by Stephen C. Stearns, Ph.D.
MOS管相关知识
Full arrangement ii[duplicate removal of the same elements + standard backtracking]
基本布局-QHBoxLayout类、QVBoxLayout类、QGridLayout类
Listen to the markdown file and hot update next JS page
同一服务器两个端口不同的应用session覆盖解决方案
Chinese address and English address
多模态情感识别_多模态融合的情感识别研究「建议收藏」
疫情防控,居家办公,网上授课之心得 | 社区征文
MPLS notes Part 1
菊花链(寒假每日一题 39)
Combined with practice, you will understand redis persistence
全排列II[存在相同元素去重 + 标准回溯]
[mobile terminal] design size of mobile phone interface
Viewing MySQL password on Linux_ MySQL forgets password "suggestions collection" under Linux