xiashuang 发表于 2022-7-27 22:36

【先楫HPM6750测评】软件模拟SPI采集ADS1263(32位ADC)数据

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 前段时间在某宝上买了几片TI的32位ADC:ADS1263,官方手册上的性能很强,最高采样到38.4k(26us)需要的处理器性能必须要具有很强的运算功能,正好试下HPM6750,于是画了一块PCB板,经过一周的等待终于到了,焊接了必要的元件就开干。</span></span></p>

<p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-family:楷体;"><span style="font-size:18px;">为了先验证板子的情况,先用软件模拟SPI进行实验,需要7根信号线进行连接通讯,定义的GPIO如下:</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">*RST---------PE25<br />
*DRDY--------PE26<br />
*MISO--------SPI2.MISO &nbsp;PB25<br />
*MOSI--------SPI2.MOSI &nbsp;PB22<br />
*SCK---------SPI2.SCK &nbsp; PB21<br />
*CS----------PF1<br />
*START-------PF4</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 先初始化IO口,时钟的开启已经在board_init()中完成,所以指示配置一下寄存器就行</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;/*设置IO口为通用IO*/<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.FUNC_CTL = IOC_PE25_FUNC_CTL_GPIO_E_25;&nbsp;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.FUNC_CTL = IOC_PE26_FUNC_CTL_GPIO_E_26;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.FUNC_CTL = IOC_PB25_FUNC_CTL_GPIO_B_25;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.FUNC_CTL = IOC_PB22_FUNC_CTL_GPIO_B_22;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.FUNC_CTL = IOC_PB21_FUNC_CTL_GPIO_B_21;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.FUNC_CTL = IOC_PF01_FUNC_CTL_GPIO_F_01;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.FUNC_CTL = IOC_PF04_FUNC_CTL_GPIO_F_04;<br />
&nbsp; &nbsp; /*配置输入输出*/<br />
&nbsp; &nbsp; /*ps-上下拉电阻 PE-上下拉开关 SMT-施密特 DS-驱动强度 OD-开漏 &nbsp;MS-电压选择*/<br />
&nbsp; &nbsp; uint32_t pad_ctl_out = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1);<br />
&nbsp; &nbsp; uint32_t pad_ctl_in = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1)|IOC_PAD_PAD_CTL_SMT_SET(1);<br />
&nbsp; &nbsp; gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOE, 25, 1);<br />
&nbsp; &nbsp; gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOB, 22, 1);<br />
&nbsp; &nbsp; gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOB, 21, 1);<br />
&nbsp; &nbsp; gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOF, 01, 1);<br />
&nbsp; &nbsp; gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOF, 04, 1);</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; HPM_IOC-&gt;PAD.PAD_CTL = pad_ctl_out;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.PAD_CTL = pad_ctl_out;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.PAD_CTL = pad_ctl_out;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.PAD_CTL = pad_ctl_out;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.PAD_CTL = pad_ctl_out;</span></span></p>

<p><br />
<span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; HPM_IOC-&gt;PAD.PAD_CTL = pad_ctl_in;<br />
&nbsp; &nbsp; HPM_IOC-&gt;PAD.PAD_CTL = pad_ctl_in;</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 相应的IO输出及输入读取如下:</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">#define ADS1263_RESET_H gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOE, 25, 1)<br />
#define ADS1263_RESET_L gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOE, 25, 0)<br />
#define ADS1263_START_H gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOF, 4, 1)<br />
#define ADS1263_START_L gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOF, 4, 0)<br />
#define ADS1263_CS_H &nbsp; &nbsp;gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOF, 1, 1)<br />
#define ADS1263_CS_L &nbsp; &nbsp;gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOF, 1, 0)<br />
#define ADS1263_SCLK_H &nbsp;gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOB, 21, 1)<br />
#define ADS1263_SCLK_L &nbsp;gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOB, 21, 0)<br />
#define ADS1263_DIN_H &nbsp; gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOB, 22, 1)<br />
#define ADS1263_DIN_L &nbsp; gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOB, 22, 0)<br />
#define ADS1263_DOUT &nbsp; &nbsp;gpio_read_pin(HPM_GPIO0, GPIO_DI_GPIOB, 25)<br />
#define ADS1263_DRDY &nbsp; &nbsp;gpio_read_pin(HPM_GPIO0, GPIO_DI_GPIOE, 26)</span></span></p>

<p>&nbsp;</p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 初始化ADS1263</span></span></p>

<p>&nbsp;</p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">int init_ads1263(void)<br />
{<br />
&nbsp; &nbsp; printf(&quot;*************************************************************\r\n&quot;);<br />
&nbsp; &nbsp; printf(&quot;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *\r\n&quot;);<br />
&nbsp; &nbsp; printf(&quot;* ADS1263 TEST ^_^ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*\r\n&quot;);<br />
&nbsp; &nbsp; printf(&quot;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *\r\n&quot;);<br />
&nbsp; &nbsp; printf(&quot;*************************************************************\r\n&quot;);<br />
&nbsp; &nbsp;&nbsp;<br />
&nbsp;&nbsp; &nbsp;GPIO_Configuration();<br />
&nbsp;&nbsp; &nbsp;ADS1263_INIT();//ADS1263初始化<br />
&nbsp; &nbsp;&nbsp;ADS1263_CS_L;<br />
&nbsp; &nbsp; Delay(0xf);<br />
&nbsp;&nbsp; &nbsp;ADS1263_WRITE(0x08);//START1 command,当START引脚为低电平时,可由此命令启动ADC1的转换。<br />
&nbsp; &nbsp; ADS1263_CS_H;<br />
&nbsp; &nbsp; Delay(0xf);<br />
&nbsp; &nbsp; return 0;<br />
}</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">读取AD值</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">int read_ads1263(void)<br />
{<br />
&nbsp; &nbsp; if(ADS1263_DRDY != 1)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; ADS1263_CS_L;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Delay(0xf);<br />
&nbsp; &nbsp; &nbsp; &nbsp; ADS1263_WRITE(0x12);//读取ADC1<br />
&nbsp; &nbsp; &nbsp; &nbsp; STATUS=ADS1263_READ_REG();<br />
&nbsp; &nbsp; &nbsp; &nbsp; ADC1_DATA=ADS1263_READ();<br />
&nbsp; &nbsp; &nbsp; &nbsp; checksum = ADS1263_READ_REG();<br />
&nbsp; &nbsp; &nbsp; &nbsp; ADS1263_CS_H;&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; count++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; D++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; if(D &gt; 0)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ADC1_DATA = Filter_ch1(ADC1_DATA,D,D);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ADC1_DATA = CELL_ADSOURSE_FILTER(ADC1_DATA,D,D);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mv_Now = ADC1_DATA / 2147483648.0 * 2500 / 32;//mv数<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//测试重量参数<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Weight = (mv_Now - mv_Zero)/ 10.0f * mv_Full * mv_Cali;</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; &nbsp; &nbsp; INT32toREG(ADC1_DATA,&amp;D);//源码<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;FP32toREG(mv_Now,&amp;D);//mv数<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;FP32toREG(Weight,&amp;D);//重量<br />
&nbsp; &nbsp; &nbsp; &nbsp; //校秤参数<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mv_Zero = REGtoFP32(&amp;D);//mv零点<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mv_Full = REGtoFP32(&amp;D);//满量程<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mv_Cali = REGtoFP32(&amp;D);//校准系数&nbsp;&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;</span></span><br />
<span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; &nbsp; &nbsp; return ADC1_DATA;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; else<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
}</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 利用上次移植的modbus 裸机例子,在主循环中不断查询AD状态读取。</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 连接好线,接上称重传感器开始测试</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; MODBUS上位机画面,使用50kg C3电阻应变桥式称重传感器</span></span><span style="font-family:楷体;"><span style="font-size:18px;">采样400次精度在&plusmn;1g,后来降低采样到60次/s,滑动平均5次,精度在&plusmn;0.2g</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 逻辑分析仪抓取波形图。采用软件模拟SPI,速度在3M左右,读取命令+状态+4字节数据+校验共7个字节数据在20.5us左右</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 实验总结:</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp;&nbsp;&nbsp;&nbsp;1.HPM6750在配置IO时要注意名称,因为IO引脚较多,宏定义也比较多,在初始化容易写错(这次因为IO编号写错导致两个IO口没有输出,查了1个多小时)。看来图形化代码工具还是很有必要的。</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 2.HPM6750的驱动强度和施密特单独出来和I.MX RT系列比较像增加了IO控制的灵活性,PCB上高速信号的抗信号反射电阻和驱动限流电阻都可以省去了,等以后试下芯片的施密特能否代替外部输入上的74HC14。</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 3.HPM6750运算速度很快,等以后试试高阶FIR看看</span></span></p>

<p><span style="font-family:楷体;"><span style="font-size:18px;">&nbsp; &nbsp; 4.ADS1263的高速采样及其以来模拟电源的纹波,对内部DCDC电源还是要增加滤波器,采样60HZ对50-hz和60hz纹波抑制后精度一下就上来了。</span></span></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

yang8555u 发表于 2022-7-28 09:08

<p>厉害了,楼主。请问PCB开源吗</p>

<p>&nbsp;</p>

nmg 发表于 2022-7-28 11:13

<p>他家图形化代码工具听官方说最近快出来了</p>

<p>幸运的话,估计你测评还没结束前,就能出来,具体时间不太确定</p>

freebsder 发表于 2022-7-28 16:00

<p>厉害,能硬能软。</p>

nmg 发表于 2022-8-1 10:04

nmg 发表于 2022-7-28 11:13
他家图形化代码工具听官方说最近快出来了

幸运的话,估计你测评还没结束前,就能出来,具体时间不太确定 ...

<p>出来了,详见下方</p>

<p>&nbsp;</p>

<p><a href="https://bbs.eeworld.com.cn/thread-1212795-1-1.html" target="_blank">先楫出了可视化配置代码生成工具了。 </a></p>

xiashuang 发表于 2022-8-8 21:40

nmg 发表于 2022-8-1 10:04
出来了,详见下方

&nbsp;

先楫出了可视化配置代码生成工具了。

<p>感谢感谢,今天刚试了下,功能还是比较弱吧</p>

xiashuang 发表于 2022-8-8 21:41

freebsder 发表于 2022-7-28 16:00
厉害,能硬能软。

<p>摸鱼时瞎捣鼓玩的!</p>
页: [1]
查看完整版本: 【先楫HPM6750测评】软件模拟SPI采集ADS1263(32位ADC)数据