【先楫HPM6750测评】软件模拟SPI采集ADS1263(32位ADC)数据
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 前段时间在某宝上买了几片TI的32位ADC:ADS1263,官方手册上的性能很强,最高采样到38.4k(26us)需要的处理器性能必须要具有很强的运算功能,正好试下HPM6750,于是画了一块PCB板,经过一周的等待终于到了,焊接了必要的元件就开干。</span></span></p><p> </p>
<p> </p>
<p> <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 PB25<br />
*MOSI--------SPI2.MOSI PB22<br />
*SCK---------SPI2.SCK PB21<br />
*CS----------PF1<br />
*START-------PF4</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 先初始化IO口,时钟的开启已经在board_init()中完成,所以指示配置一下寄存器就行</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> /*设置IO口为通用IO*/<br />
HPM_IOC->PAD.FUNC_CTL = IOC_PE25_FUNC_CTL_GPIO_E_25; <br />
HPM_IOC->PAD.FUNC_CTL = IOC_PE26_FUNC_CTL_GPIO_E_26;<br />
HPM_IOC->PAD.FUNC_CTL = IOC_PB25_FUNC_CTL_GPIO_B_25;<br />
HPM_IOC->PAD.FUNC_CTL = IOC_PB22_FUNC_CTL_GPIO_B_22;<br />
HPM_IOC->PAD.FUNC_CTL = IOC_PB21_FUNC_CTL_GPIO_B_21;<br />
HPM_IOC->PAD.FUNC_CTL = IOC_PF01_FUNC_CTL_GPIO_F_01;<br />
HPM_IOC->PAD.FUNC_CTL = IOC_PF04_FUNC_CTL_GPIO_F_04;<br />
/*配置输入输出*/<br />
/*ps-上下拉电阻 PE-上下拉开关 SMT-施密特 DS-驱动强度 OD-开漏 MS-电压选择*/<br />
uint32_t pad_ctl_out = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1);<br />
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 />
gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOE, 25, 1);<br />
gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOB, 22, 1);<br />
gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOB, 21, 1);<br />
gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOF, 01, 1);<br />
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;"> HPM_IOC->PAD.PAD_CTL = pad_ctl_out;<br />
HPM_IOC->PAD.PAD_CTL = pad_ctl_out;<br />
HPM_IOC->PAD.PAD_CTL = pad_ctl_out;<br />
HPM_IOC->PAD.PAD_CTL = pad_ctl_out;<br />
HPM_IOC->PAD.PAD_CTL = pad_ctl_out;</span></span></p>
<p><br />
<span style="font-family:楷体;"><span style="font-size:18px;"> HPM_IOC->PAD.PAD_CTL = pad_ctl_in;<br />
HPM_IOC->PAD.PAD_CTL = pad_ctl_in;</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 相应的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 gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOF, 1, 1)<br />
#define ADS1263_CS_L gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOF, 1, 0)<br />
#define ADS1263_SCLK_H gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOB, 21, 1)<br />
#define ADS1263_SCLK_L gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOB, 21, 0)<br />
#define ADS1263_DIN_H gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOB, 22, 1)<br />
#define ADS1263_DIN_L gpio_write_pin(HPM_GPIO0, GPIO_DO_GPIOB, 22, 0)<br />
#define ADS1263_DOUT gpio_read_pin(HPM_GPIO0, GPIO_DI_GPIOB, 25)<br />
#define ADS1263_DRDY gpio_read_pin(HPM_GPIO0, GPIO_DI_GPIOE, 26)</span></span></p>
<p> </p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 初始化ADS1263</span></span></p>
<p> </p>
<p><span style="font-family:楷体;"><span style="font-size:18px;">int init_ads1263(void)<br />
{<br />
printf("*************************************************************\r\n");<br />
printf("* *\r\n");<br />
printf("* ADS1263 TEST ^_^ *\r\n");<br />
printf("* *\r\n");<br />
printf("*************************************************************\r\n");<br />
<br />
GPIO_Configuration();<br />
ADS1263_INIT();//ADS1263初始化<br />
ADS1263_CS_L;<br />
Delay(0xf);<br />
ADS1263_WRITE(0x08);//START1 command,当START引脚为低电平时,可由此命令启动ADC1的转换。<br />
ADS1263_CS_H;<br />
Delay(0xf);<br />
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 />
if(ADS1263_DRDY != 1)<br />
{<br />
ADS1263_CS_L;<br />
Delay(0xf);<br />
ADS1263_WRITE(0x12);//读取ADC1<br />
STATUS=ADS1263_READ_REG();<br />
ADC1_DATA=ADS1263_READ();<br />
checksum = ADS1263_READ_REG();<br />
ADS1263_CS_H; <br />
count++;<br />
D++;<br />
if(D > 0)<br />
{<br />
ADC1_DATA = Filter_ch1(ADC1_DATA,D,D);<br />
}<br />
ADC1_DATA = CELL_ADSOURSE_FILTER(ADC1_DATA,D,D);<br />
<br />
mv_Now = ADC1_DATA / 2147483648.0 * 2500 / 32;//mv数<br />
//测试重量参数<br />
Weight = (mv_Now - mv_Zero)/ 10.0f * mv_Full * mv_Cali;</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> INT32toREG(ADC1_DATA,&D);//源码<br />
FP32toREG(mv_Now,&D);//mv数<br />
FP32toREG(Weight,&D);//重量<br />
//校秤参数<br />
mv_Zero = REGtoFP32(&D);//mv零点<br />
mv_Full = REGtoFP32(&D);//满量程<br />
mv_Cali = REGtoFP32(&D);//校准系数 <br />
</span></span><br />
<span style="font-family:楷体;"><span style="font-size:18px;"> return ADC1_DATA;<br />
}<br />
else<br />
return 0;<br />
}</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 利用上次移植的modbus 裸机例子,在主循环中不断查询AD状态读取。</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 连接好线,接上称重传感器开始测试</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> MODBUS上位机画面,使用50kg C3电阻应变桥式称重传感器</span></span><span style="font-family:楷体;"><span style="font-size:18px;">采样400次精度在±1g,后来降低采样到60次/s,滑动平均5次,精度在±0.2g</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 逻辑分析仪抓取波形图。采用软件模拟SPI,速度在3M左右,读取命令+状态+4字节数据+校验共7个字节数据在20.5us左右</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 实验总结:</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 1.HPM6750在配置IO时要注意名称,因为IO引脚较多,宏定义也比较多,在初始化容易写错(这次因为IO编号写错导致两个IO口没有输出,查了1个多小时)。看来图形化代码工具还是很有必要的。</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 2.HPM6750的驱动强度和施密特单独出来和I.MX RT系列比较像增加了IO控制的灵活性,PCB上高速信号的抗信号反射电阻和驱动限流电阻都可以省去了,等以后试下芯片的施密特能否代替外部输入上的74HC14。</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 3.HPM6750运算速度很快,等以后试试高阶FIR看看</span></span></p>
<p><span style="font-family:楷体;"><span style="font-size:18px;"> 4.ADS1263的高速采样及其以来模拟电源的纹波,对内部DCDC电源还是要增加滤波器,采样60HZ对50-hz和60hz纹波抑制后精度一下就上来了。</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p>厉害了,楼主。请问PCB开源吗</p>
<p> </p>
<p>他家图形化代码工具听官方说最近快出来了</p>
<p>幸运的话,估计你测评还没结束前,就能出来,具体时间不太确定</p>
<p>厉害,能硬能软。</p>
nmg 发表于 2022-7-28 11:13
他家图形化代码工具听官方说最近快出来了
幸运的话,估计你测评还没结束前,就能出来,具体时间不太确定 ...
<p>出来了,详见下方</p>
<p> </p>
<p><a href="https://bbs.eeworld.com.cn/thread-1212795-1-1.html" target="_blank">先楫出了可视化配置代码生成工具了。 </a></p>
nmg 发表于 2022-8-1 10:04
出来了,详见下方
先楫出了可视化配置代码生成工具了。
<p>感谢感谢,今天刚试了下,功能还是比较弱吧</p>
freebsder 发表于 2022-7-28 16:00
厉害,能硬能软。
<p>摸鱼时瞎捣鼓玩的!</p>
页:
[1]