lugl4313820 发表于 2024-2-17 16:02

【先楫HPM6750EVK2测评】体验ADC功能

<p>1、新建RTT工程,工程中添加对ADC的驱动:<br />
&nbsp;</p>

<p>2、保存工程后,添加测试代码。<br />
3、我们根据原理图上的J10接个,只有PE29是ADC3的输出通道<br />
&nbsp;<br />
4、先定义通道、任务</p>

<p>```<br />
#define ADC_DEV_NAME &nbsp; &nbsp; &nbsp; &nbsp;&quot;adc3&quot; &nbsp; &nbsp; &nbsp;/* ADC 设备名称 */<br />
#define ADC_DEV_CHANNEL &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* ADC 通道 */<br />
#define REFER_VOLTAGE &nbsp; &nbsp; &nbsp; 330 &nbsp; &nbsp; &nbsp; &nbsp; /* 参考电压 3.3V,数据精度乘以100保留2位小数*/<br />
#define CONVERT_BITS &nbsp; &nbsp; &nbsp; &nbsp;(1 &lt;&lt; 16) &nbsp; /* 转换位数为16位 */<br />
```</p>

<p>5、添加任务:</p>

<p>```<br />
static void Adc_entry(void* paremeter)<br />
{<br />
&nbsp; &nbsp; rt_adc_device_t adc_dev;<br />
&nbsp; &nbsp; rt_uint32_t value,vol;<br />
&nbsp; &nbsp; rt_err_t ret = RT_EOK;</p>

<p>&nbsp; &nbsp; adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);<br />
&nbsp; &nbsp; if (adc_dev == RT_NULL)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; rt_kprintf(&quot;adc sample run failed! can&#39;t find %s device!\n&quot;, ADC_DEV_NAME);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; /* 使能设备 */<br />
&nbsp; &nbsp; ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL);<br />
&nbsp; &nbsp; if(ret == RT_EOK)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; rt_kprintf(&quot;adc sample run success! &nbsp;find %s device!\n&quot;, ADC_DEV_NAME);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; while(1)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; /* 读取采样值 */<br />
&nbsp; &nbsp; &nbsp; &nbsp; value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL);<br />
&nbsp; &nbsp; &nbsp; &nbsp; rt_kprintf(&quot;the value is :%d \n&quot;, value);<br />
&nbsp; &nbsp; &nbsp; &nbsp; /* 转换为对应电压值 */<br />
&nbsp; &nbsp; &nbsp; &nbsp; vol = value * REFER_VOLTAGE / CONVERT_BITS;<br />
&nbsp; &nbsp; &nbsp; &nbsp; rt_kprintf(&quot;the voltage is :%d.%02d \n&quot;, vol / 100, vol % 100);</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; rt_thread_delay(500);<br />
&nbsp; &nbsp; }<br />
}<br />
```</p>

<p>7、在主函数里启用任务</p>

<p>```<br />
Adc_thread = rt_thread_create(&quot;adc1&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Adc_entry,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RT_NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 512,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 16,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 20);<br />
&nbsp; &nbsp; &nbsp; &nbsp; if(Adc_thread != RT_NULL)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rt_thread_startup(Adc_thread);<br />
&nbsp; &nbsp; &nbsp; &nbsp; else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;<br />
```<br />
下载到开发板后,效果如下:</p>

<p> &nbsp;</p>

<p>【总结】</p>

<p>HPM6750拥用16位ADC以及12位ADC。经过试验后效果非常好。</p>

LitchiCheng 发表于 2024-2-18 09:24

<p>精度怎么样,外部的分压电阻的精度是多少的</p>

lugl4313820 发表于 2024-2-18 09:26

LitchiCheng 发表于 2024-2-18 09:24
精度怎么样,外部的分压电阻的精度是多少的

<p>还有进行精度测试,我现在只学习如何把数据读出来,下一篇跑跑这方面的测试。</p>

LitchiCheng 发表于 2024-2-18 11:46

lugl4313820 发表于 2024-2-18 09:26
还有进行精度测试,我现在只学习如何把数据读出来,下一篇跑跑这方面的测试。

<p>好的,ADC的功能都有,但是各家的精度都有差异</p>

rainterry 发表于 2024-4-29 10:10

LitchiCheng 发表于 2024-2-18 11:46
好的,ADC的功能都有,但是各家的精度都有差异

<p>费工说没有16位</p>

nh7527 发表于 2024-10-25 16:18

<table cellpadding="0" cellspacing="0">
        <tbody>
                <tr>
                        <td id="postmessage_3370081">
                        <p id="contents">小伙伴们一定要注意,如果购买JLINK调试器,一定要JLINK V11以上的,别问我怎么知道的,也老贵了。</p>

                        <p>对于HPM6750EVK2没有板载调试器的小伙伴,不妨试试板载那种FT2232HL的,可以采用淘宝上这个FT2232HL调试器,与官方板载的功能一样,价格感人,详见购买链接http://e.tb.cn/h.gx7VTHWCvoFnNkN?tk=fCJQ3n9ZOAF</p>

                        <p><img file="" height="88" initialized="true" inpost="1" lazyloaded="true" loading="lazy" onclick="zoom(this, this.getAttribute('zoomfile'), 0, 0, '0')" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" src="https://i0.hdslb.com/bfs/new_dyn/9f9b0621e29f57c1d6bd891f19ef501740764353.png@176w_176h_1c_1s.avif" width="88" zoomfile="" /><img file="" height="88" initialized="true" inpost="1" lazyloaded="true" loading="lazy" onclick="zoom(this, this.getAttribute('zoomfile'), 0, 0, '0')" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" src="https://i0.hdslb.com/bfs/new_dyn/77f7b3f681f5766dd6cc06093c559aa640764353.png@176w_176h_1c_1s.avif" width="88" zoomfile="" /></p>
                        </td>
                </tr>
        </tbody>
</table>
页: [1]
查看完整版本: 【先楫HPM6750EVK2测评】体验ADC功能