有没有用过SCA61T 或 SCA100T倾角传感器的,测量角度问题

我用的是SCA61T-FA1H1G倾角传感器,用的SPI方式读取X轴的值,读取11位数据后,发现在0度和90度时候都比较准确,而始终测不到-90度,读取值11位数据最小是217,换算后也就是-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. }



已邀请:

laoguo - 微信:17764509575

实际上这可能是零点校正的问题的,也就是你没有做0度校正,每个传感器都会有点零点误差,因为SCA100T这个系列的倾角传感器是基于加速度原理计算倾角的,他是个正弦波对应关系,也就是说0度时分辨率,90度的分辨小,如果零点误差有0.2度的话,可能在大角度就相差很大,所以会出现你这个现象,其实输出值217已经是90度了。

要回复问题请先登录注册