[STM32F1] 有没有用过SCA61T 或 SCA100T倾角传感器的,测量角度问题,急!

[复制链接]
 楼主| 18518779114 发表于 2017-3-30 11:52 | 显示全部楼层 |阅读模式
我用的是SCA61T-FA1H1G倾角传感器,用的SPI方式读取X轴的值,读取11位数据后,发现在0度和90度时候都比较准确,而始终测不到-90度,读取值11位数据最小是217,换算后也就是-80度,这个是怎么回事?
mmuuss586 发表于 2017-3-30 14:44 | 显示全部楼层
没用过;

是不是换算方式不对
 楼主| 18518779114 发表于 2017-3-30 16:08 | 显示全部楼层
mmuuss586 发表于 2017-3-30 14:44
没用过;

是不是换算方式不对

应该不是,我在采集端,把采集值固定写成205,换算出来的是-90度。 现在问题是,采集这个传感器值,读不到205,我把传感器按90度放置,只能读出217的值(也就是80度),不知道是传感器自身问题,还是硬件电路问题,还是软件采集SPI方式采集问题。
 楼主| 18518779114 发表于 2017-3-30 16:43 | 显示全部楼层
这是采集值与角度对应的表
微信截图_20170330113624.png
chenghaichao 发表于 2017-3-30 20:58 | 显示全部楼层
你可以跟模拟电压对比量一下。
 楼主| 18518779114 发表于 2017-3-31 09:09 | 显示全部楼层
chenghaichao 发表于 2017-3-30 20:58
你可以跟模拟电压对比量一下。

目前因为硬件工程师已经做好板子,没有接那个模拟电压的管脚,暂时没法测量。
不过昨天我又测试了一下SPI方式读取X轴的值,发现在-90的位置的时候,并不是读不到205,可以偶尔读到205,或207的值(换算后角度是-90度左右)。但是必须在-90度位置一直得晃动传感器,才可以读到。 如果在-90度位置静止不动,就只能读出217或更高,换算角度就是-70多度至-80度。 不停的晃动,才偶尔出现-90度,这个现象好奇怪?不知道是什么原因。
chenghaichao 发表于 2017-3-31 21:14 | 显示全部楼层
传感器本身在端值的时候都是跳变的,采样加滤波处理吧,另外不知道什么封装的,引脚应该能测量到吧。
 楼主| 18518779114 发表于 2017-4-1 16:43 | 显示全部楼层
chenghaichao 发表于 2017-3-31 21:14
传感器本身在端值的时候都是跳变的,采样加滤波处理吧,另外不知道什么封装的,引脚应该能测量到吧。 ...

加过滤处理了,数值稳定,但是值不是-90度。目前考虑用传感器的模拟输出管脚测试一下。
 楼主| 18518779114 发表于 2017-4-1 16:46 | 显示全部楼层
18518779114 发表于 2017-4-1 16:43
加过滤处理了,数值稳定,但是值不是-90度。目前考虑用传感器的模拟输出管脚测试一下。 ...

用的STM32采集的传感器值,一开始使用硬件SPI方式,其它角度测量都没问题,就是-90度总是不行。后又用IO口模拟SPI方式读取传感器值,效果是一样的,将传感器-90放置,测量总是-80。依然没能解决问题。
chenghaichao 发表于 2017-4-1 21:42 | 显示全部楼层
所有的电源相关都得是高精度的。
febgxu 发表于 2017-4-1 22:59 | 显示全部楼层
计算的数据有问题吗
febgxu 发表于 2017-4-1 23:01 | 显示全部楼层
看看你的代码,使用传感器数据对不对
 楼主| 18518779114 发表于 2017-4-2 09:55 | 显示全部楼层
chenghaichao 发表于 2017-4-1 21:42
所有的电源相关都得是高精度的。

现在又用AD方式采集测试了一下,当平放时候,采集电压时2.5V,0度。 当按-90度方向放置传感器,采集值是0.54左右,是-80度左右,还是没到-90,跟SPI方式采集的现象基本一致。
 楼主| 18518779114 发表于 2017-4-2 09:57 | 显示全部楼层
febgxu 发表于 2017-4-1 23:01
看看你的代码,使用传感器数据对不对

计算应该没问题吧,0度到正90度的计算都正确,但是从传感器采集的数值,始终不能到-90度,只能到-80度左右。
  1. void SCA61T_SpiInit(void)
  2. {
  3.   
  4.   SPI_InitTypeDef  SPI_InitStructure;
  5.   GPIO_InitTypeDef GPIO_InitStructure;
  6.   
  7.   /* Enable SPI3 and GPIO clocks */  
  8.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3 , ENABLE);
  9.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  10.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  11.   
  12.   /* Connect PXx to SPI_SCK */
  13.   GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3);
  14.   
  15.   /* Connect PXx to SPI_MISO */
  16.   GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SPI3);
  17.   
  18.   /* Connect PXx to SPI_MOSI */
  19.   GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3);  
  20.   
  21.   /* Configure SPI3 pins: SCK, MISO and MOSI */
  22.   GPIO_InitStructure.GPIO_Pin         = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
  23.   GPIO_InitStructure.GPIO_Mode         = GPIO_Mode_AF;
  24.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  25.   GPIO_InitStructure.GPIO_PuPd         = GPIO_PuPd_UP;
  26.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  27.   GPIO_Init(GPIOC, &GPIO_InitStructure);
  28.   
  29.   /* SPI3 configuration */
  30.   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  31.   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  32.   SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  33.   SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  34.   SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  35.   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  36.   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;
  37.   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  38.   SPI_InitStructure.SPI_CRCPolynomial = 7;
  39.   SPI_Init(SPI3, &SPI_InitStructure);
  40.   
  41.   /* Enable SPI3 */
  42.   SPI_Cmd(SPI3, ENABLE);
  43.   
  44.   /* Configure GPIO PIN for Lis Chip select */
  45.   GPIO_InitStructure.GPIO_Pin         = GPIO_Pin_15;
  46.   GPIO_InitStructure.GPIO_Mode         = GPIO_Mode_OUT;
  47.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  48.   GPIO_InitStructure.GPIO_PuPd         = GPIO_PuPd_NOPULL;
  49.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  50.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  51.   
  52.   /* Deselect : Chip Select high */
  53.   GPIO_SetBits(GPIOA, GPIO_Pin_15);
  54.        
  55. }

  56. /*******************************************************************************
  57. * Function Name  : SCA61T_SPI_SendByte
  58. * Description    : Sends a Byte through the SPI interface and return the
  59. *                  Byte received from the SPI bus.
  60. * Input          : Byte : Byte send.
  61. * Output         : None
  62. * Return         : The received byte value
  63. *******************************************************************************/
  64. uint8_t SCA61T_SPI_SendByte(uint8_t byte)
  65. {
  66.   /* Loop while DR register in not emplty */
  67.   while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET);
  68.   
  69.   /* Send Half Word through the SPI peripheral */
  70.   SPI_I2S_SendData(SPI3, byte);
  71.        
  72.   /* Wait to receive a Half Word */
  73.   while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET);
  74.   
  75.   /* Return the Half Word read from the SPI bus */
  76.   return (int8_t)SPI_I2S_ReceiveData(SPI3);
  77. }


  78. uint8_t SCA61T_ReadDataReg(uint8_t Reg, uint16_t* Data)
  79. {
  80.    
  81.     uint8_t value_h=0,value_l=0;
  82.     uint16_t value_temp=0;
  83.                
  84.     SCA61T_CS_LOW();
  85.                
  86.     SCA61T_SPI_SendByte(Reg);                                                                                //read x data command
  87.     value_h = SCA61T_SPI_SendByte(0xFF);                                //read  hight 8 bit data       
  88.     value_l = SCA61T_SPI_SendByte(0xFF);                                //read  low 8 bit data
  89.    
  90.     SCA61T_CS_HIGH();
  91.                
  92.     value_temp = ((uint16_t)value_h & 0x00FF);                                                                                                                                       
  93.     value_temp = ((value_temp << 3) & 0x07F8) + (((value_l & 0xE0) >> 5) & 0x07);                //hight 8 bit + low 3 bit  = 11bit x data;
  94.    
  95.    *Data = value_temp;
  96.                
  97.     return MEMS_SUCCESS;
  98. }

  99. uint16_t SCA61T_Read_Xdata(void)
  100. {
  101.                 uint16_t x_value=0;
  102.                
  103.                 SCA61T_CS_HIGH();
  104.                 vTaskDelay(1);
  105.                 SCA61T_ReadDataReg(RDAX_REG,&x_value);
  106.                 my_uDelay(10);
  107.                 return x_value;
  108.                
  109. }

  110. float SCA61T_Transformation_Angle(float senscomp)
  111. {
  112.                 float angle=0.00f;
  113.                 uint8_t i=0;
  114.                 uint16_t x_value=0;
  115.                 uint32_t temp_value=0;
  116.                
  117.                 for(i=0; i<3; i++)
  118.                 {
  119.                     temp_value += SCA61T_Read_Xdata();
  120.                 }
  121.                 x_value = temp_value / i;
  122.                
  123.                 if(x_value <= 1024 - SENS) x_value = 1024-SENS;
  124.                 if(x_value >= 1024 + SENS) x_value = 1024+SENS;
  125.                 angle=asinf(((float)x_value-1024.00)/senscomp);
  126.                
  127.                 angle=angle*180/PI;
  128.                
  129.                 return angle;
  130. }
 楼主| 18518779114 发表于 2017-4-2 10:03 | 显示全部楼层
我的主芯片是STM32 传感器用的是 SCA61T-FA1H1G  测量范围是正负90度   
wangdezhi 发表于 2017-4-2 11:36 | 显示全部楼层
使用校准算法了吗?
wangdezhi 发表于 2017-4-2 11:40 | 显示全部楼层
推荐mpu6050芯片,这个计算角度。
uiint 发表于 2017-4-2 22:33 | 显示全部楼层
这个不是ADC采样的角度传感器么
uiint 发表于 2017-4-2 22:41 | 显示全部楼层
换算的方式不对,这个没有用过。
 楼主| 18518779114 发表于 2017-4-3 20:39 | 显示全部楼层
uiint 发表于 2017-4-2 22:41
换算的方式不对,这个没有用过。

换算方式不对么????

这个是ADC采样和SPI采用两种方式,可通过硬件接线选择。  目前我这两种方式都尝试过,效果一样。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

13

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部