【跑步姿势训练鞋】No.003-数据采集和实时显示
<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">上一篇介绍了软件开发环境的建立,这一篇介绍</font></span></span><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">数据采集和实时显示</font></span></span><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">。</font></span></span></span></span></p><p style="text-indent:24.0000pt; text-align:justify"> </p>
<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">首先叙述一下我的作品整体规划。本作品采用四个压力传感器采集足底的压力,通过对四个点的压力变化进行分析,识别出当前的跑步姿势,通过蓝牙将结果发到手机或电脑,训练人员就能通过实时获取的数据来对比纠正自己的跑步姿势,达到正确健康的跑步训练效果。具体的系统框图如下:</font></span></span></span></span></p>
<p> </p>
<p align="center" style="text-indent:24.0000pt; text-align:center"></p>
<p align="center" style="text-indent:24.0000pt; text-align:center"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">图</font>1,系统框图</span></span></span></span></p>
<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">本篇文章重点介绍如何获取</font>4路ADC数据并通过串口实时显示到电脑上。使用到的工具有:IAR EW for Arm,SSCOM串口助手,J-Link RTT Viewer,DataScope 串口虚拟示波器。</span></span></span></span></p>
<ol>
<li> <span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">获取例程</font></span></span></span></span></li>
<li><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">在上一篇已经介绍过如何装</font>RSL10软件开发包了,本篇直接在上篇基础上开整。打开IAR库管理,选择例程标签,导入ADC_UART例程,编译运行。除了配置一下J-Link RTT Viewer的宏配置选项,其他基本上傻瓜式操作就好使。如下图。</span></span></span></span></li>
</ol>
<p align="center" style="text-align:center"></p>
<p>
<p align="center" style="text-align:center"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">图</font>2,导入ADC例程</span></span></span></span></p>
</p>
<p>
<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">打开</font>SSCOM和J-Link RTT Viewer,就可以看到开发板不停的输出ADC input value,如此,即可说明开发板、通讯链路,串口配置等都是没问题的,为改造程序做准备。串口输出如下图。</span></span></span></span></p>
</p>
<p>
<p align="center" style="text-indent:24.0000pt; text-align:center"></p>
</p>
<p>
<p align="center" style="text-indent:24.0000pt; text-align:center"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">图</font>3,开发板输出</span></span></span></span></p>
</p>
<ol start="2">
<li><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">修改例程</font></span></span></span></span></li>
<li><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">例程中,模拟信号采集的是电源的电压,此处我不改变,因为后面还会用到。我额外增加了</font>4个外部输入通道。根据原理图,增加4个模拟输入口的初始化,见下图。</span></span></span></span></span></li>
</ol>
<p align="center" style="text-indent:24.0000pt; text-align:center"></p>
<p> </p>
<p align="center" style="text-indent:24.0000pt; text-align:center"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">图</font>4,模拟IO初始化</span></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">然后进行</font>ADC的初始化配置。原来的电量采集通道不变,增加0-3通道的采集配置。代码如下:</span></span></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> /* Configure ADC_CHANNEL input selection to VBAT/2 */</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> Sys_ADC_InputSelectConfig(ADC_CHANNEL, ADC_POS_INPUT_VBAT_DIV2|ADC_NEG_INPUT_GND);</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> /* Configure both input selection for an ADC channel to GND so the OFFSET is</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> * subtracted automatically to result. */</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> Sys_ADC_InputSelectConfig(ADC_0_CHANNEL, ADC_POS_INPUT_DIO0 |</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> ADC_NEG_INPUT_GND);</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> Sys_ADC_InputSelectConfig(ADC_1_CHANNEL, ADC_POS_INPUT_DIO1 |</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> ADC_NEG_INPUT_GND);</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> Sys_ADC_InputSelectConfig(ADC_2_CHANNEL, ADC_POS_INPUT_DIO2 |</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> ADC_NEG_INPUT_GND);</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> Sys_ADC_InputSelectConfig(ADC_3_CHANNEL, ADC_POS_INPUT_DIO3 |</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> ADC_NEG_INPUT_GND);</span></span></span></span></i></span></span></span></p>
<p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">在中断函数</font>ADC_BATMON_IRQHandler中添加数据接收缓存代码:</span></span></span></span></span></p>
</p>
<p>
<p align="justify" style="text-indent:72.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic">adc_array = adc_array + ADC->DATA_TRIM_CH;</span></span></span></span></i></span></span></span></p>
</p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> adc_array = adc_array + ADC->DATA_TRIM_CH;</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> adc_array = adc_array + ADC->DATA_TRIM_CH;</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> adc_array = adc_array + ADC->DATA_TRIM_CH;</span></span></span></span></i></span></span></span></p>
<p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">在发送函数</font>Send_ADC_Value中添加数据格式化和发送代码:</span></span></span></span></span></p>
</p>
<p>
<p align="justify" style="text-indent:44.8500pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic">sprintf(buffer,"%d,%d,%d,%d\n",adc_array,adc_array,adc_array,adc_array);</span></span></span></span></i></span></span></span></p>
</p>
<p align="justify" style="margin-left:28px; text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic">size = strlen((const char *)buffer);</span></span></span></span></i></span></span></span></p>
<p align="justify" style="margin-left:28px; text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic">UART_FillTXBuffer(size, (uint8_t *)buffer);</span></span></span></span></i></span></span></span></p>
<p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">然后编译运行,就可以在</font>SSCOM中接收到4个通道的数据了,如下图。</span></span></span></span></span></p>
</p>
<p>
<p align="center" style="text-indent:24.0000pt; text-align:center"></p>
</p>
<p align="center" style="text-indent:24.0000pt; text-align:center"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">图</font>5,四通道数据</span></span></span></span></p>
<p> </p>
<ol start="3">
<li><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">对接串口虚拟示波器</font></span></span></span></span></li>
<br />
<li><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">如果只是在</font>SSCOM中显示采集到的数据,太不直观了,不能实时体现出压力变化状态,我想到了以前用到的一个工具,DataScope 串口虚拟示波器,感谢ACE-Tech(恒智高科)免费提供如此好用的开发工具。要使用此工具需要将DataScope_DP.C和DataScope_DP.h两个文件添加到工程,然后改动程序接口,让4路缓存数据能够按照工具要求的格式发送,使用下面代码格式化数据:</span></span></span></span></span></li>
</ol>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> DataScope_Get_Channel_Data( adc_array+30000, 1 ); //将数据 1.0 写入通道 1</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> DataScope_Get_Channel_Data( adc_array+10000, 2 ); //将数据 2.0 写入通道 2</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> DataScope_Get_Channel_Data( adc_array-10000, 3 ); //将数据 3.0 写入通道 3</span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> DataScope_Get_Channel_Data( adc_array-30000, 4 ); //将数据 4.0 写入通道 4 </span></span></span></span></i></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><i><span style="font-size:12.0000pt"><span style="background:#d9d9d9"><span style="font-family:宋体"><span style="font-style:italic"> size = DataScope_Data_Generate(4); //生成10个通道的 格式化帧数据,返回帧数据长度</span></span></span></span></i></span></span></span></p>
<p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">此处我遇到一个小坑,由于前面声明缓存变量一直使用例程</font>unsigned无符号形式,在调用此函数时未注意,导致上位机收到的波形特别奇怪,数据忽大忽小,差值还特别大,后来经过反复检查,发现是做减法时本应该出现负数,结果由于是无符号,补码变成一个超大数了。我把变量改成有符号型的就解决问题了。</span></span></span></span></span></p>
</p>
<p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">我为什么要在后面或加或减那</font>10000和30000呢?是因为我要在显示的时候各波形分开距离,防止混叠。</span></span></span></span></span></p>
</p>
<p>
<p align="center" style="text-indent:24.0000pt; text-align:center"></p>
</p>
<p align="center" style="text-align:center"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">图</font>6,波形显示</span></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">至此,基本完成了数据采集和实时显示功能,为下一步数据分析做好了准备。接下来重点调试压力传感硬件,分析数据特点,抽象分析算法。</font></span></span></span></span></span></p>
<p align="justify" style="text-indent:24.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">IAR工程源代码如下:</font></span></span></span></span></span></p>
<p>期待后续,这个很实用呀</p>
<p>代码能分享一份吗</p>
<p>这个软件不错,看串口数据波形</p>
dql2016 发表于 2021-5-27 13:05
代码能分享一份吗
<p>可以,回头我传上来</p>
<p>这个ad输入是0~2V么,怎么配置3.3V?</p>
dql2016 发表于 2021-5-30 09:20
这个ad输入是0~2V么,怎么配置3.3V?
<p>这个跟电源设置关系比较大,具体参见:</p>
<p>RSL10_hardware_reference.pdf-》5.3.4 Digital Supply Voltages</p>
<p> </p>
<p>ADC章节也有提示:</p>
<p>IMPORTANT: For accurate ADC measurements across operating conditions, the VDDC supply voltage level must be a minimum of 1.00 V. For more information about VDDC configuration, see Section 5.3.4, “Digital Supply Voltages” on page 46, and the “Manufacturing Calibrated Settings” from the RSL10 Firmware Reference.</p>
页:
[1]