首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

基于FPGA+XADC读取温度(附代码)

  • 25-03-08 00:02
  • 4276
  • 8967
blog.csdn.net

好久没有写文章了,这会正在跑工程,我顺便写一下这两天调的一个功能。这个功能实现的目的是获取FPGA内核温度,并将内核温度进行输出显示。那么,怎么去实现这个功能呢?主要分以下几步:一、配置XADC IP核;二、编写读温度时序逻辑;三、温度解算。下面将展开说明。

一、配置XADC IP核

①在Vivado软件 IP Catalog中搜索“XADC”,打开XADC Wizard,如下图所示;

②根据下图进行配置。

二、编写读温度时序逻辑

在编程代码之前需要知道DRP接口的时序关系,如下图所示。

FPGA读时序代码如下:

  1. process(clk,rst)
  2. begin
  3. if rst = '1' then
  4. di_in <= (others => '0');
  5. daddr_in <= (others => '0'); --XADC温度传感器数据读取寄存器地址
  6. den_in <= '0';
  7. dwe_in <= '0';
  8. elsif rising_edge (clk) then
  9. if cnt_time = 999999 then --采样频率设置为100Hz,模块时钟100MHz
  10. cnt_time <= (others => '0');
  11. daddr_in <= (others => '0'); --XADC温度传感器数据读取寄存器地址
  12. den_in <= '1';
  13. dwe_in <= '0';
  14. else
  15. cnt_time <= cnt_time + 1;
  16. den_in <= '0';
  17. dwe_in <= '0';
  18. end if;
  19. end if;
  20. end process;

 XADC例化如下:

  1. u_xadc : xadc
  2. port map(
  3. di_in => di_in ,
  4. daddr_in => daddr_in ,
  5. den_in => den_in ,
  6. dwe_in => dwe_in ,
  7. dclk_in => clk ,
  8. reset_in => rst ,
  9. vp_in => '0' ,
  10. vn_in => '0' ,
  11. drdy_out => drdy_out ,
  12. do_out => do_out ,
  13. channel_out => open ,
  14. eoc_out => open ,
  15. alarm_out => open ,
  16. eos_out => open ,
  17. busy_out => open
  18. );

 三、温度解算

温度解算的方法如下:

 需要注意将输出的do_out取值为高12bit。

 Note: The ADCs always produce a 16-bit conversion result. The 12-bit data correspond to the 12 MSBs (most significant) in the 16-bit status registers.

温度解算代码如下:

  1. process(clk,rst)
  2. begin
  3. if rst = '1' then
  4. data_out <= (others => '0');
  5. temp_polarity_flag <= '1';
  6. elsif rising_edge (clk) then
  7. if drdy_out = '1' then
  8. if do_out(15 downto 4) >= 2219 and do_out(15 downto 4) <= 3250 then
  9. data_out <= ("000" & do_out(15 downto 4) & "000000000") - ("000000000" & do_out(15 downto 4) & "000");
  10. temp_polarity_flag <= '1';
  11. elsif do_out(15 downto 4) >= 1186 and do_out(15 downto 4) < 2219 then
  12. data_out <= ("000" & do_out(15 downto 4) & "000000000") - ("000000000" & do_out(15 downto 4) & "000");
  13. temp_polarity_flag <= '0';
  14. else
  15. data_out <= conv_std_logic_vector(3251,24);
  16. end if;
  17. else
  18. data_out <= data_out;
  19. end if;
  20. end if;
  21. end process;
  22. process(clk,rst)
  23. begin
  24. if rst = '1' then
  25. temp_data <= (others => '0');
  26. drdy_out_r0 <= '0';
  27. elsif rising_edge (clk) then
  28. drdy_out_r0 <= drdy_out;
  29. if drdy_out_r0 = '1' and temp_polarity_flag = '1' then
  30. temp_data <= (x"000" & data_out(23 downto 12)) - 273;
  31. elsif drdy_out_r0 = '1' and temp_polarity_flag = '0' then
  32. temp_data <= 273 - (x"000" & data_out(23 downto 12));
  33. end if;
  34. end if;
  35. end process;
  36. process(clk,rst)
  37. begin
  38. if rst = '1' then
  39. xadc_temp_data <= (others => '0');
  40. elsif rising_edge (clk) then
  41. if temp_polarity_flag = '1' then --温度为正
  42. xadc_temp_data <= '0' & temp_data(6 downto 0); --b7为0表示正,b7为1表示负
  43. else --温度为负
  44. xadc_temp_data <= '1' & temp_data(6 downto 0);
  45. end if;
  46. end if;
  47. end process;

 四、实际效果

五、总结

以上几步可以正确的解析出FPGA核温,方法简单,无需进行乘除运算,降低资源开销。但会损失温度小数点精度。 

注:本文转载自blog.csdn.net的春风细雨无声的文章"https://blog.csdn.net/xingchenfeiying/article/details/140966507"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

123
硬件开发
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top