AMS_AS5600

前言

position sensor is a sensor that facilitates measurement of mechanical position. 
The AS5600 is an easy to program magnetic rotary position sensor with a high-resolution 12-bit analog or PWM output. The AS5600 is also equipped with a smart low power mode feature to automatically reduce the power consumption.

Design Note

AS5600有部分硬體設置重點,第一點是磁鐵選用,磁體尺寸盡可能是圓形因為他是感受磁場垂直變化(尺寸規範如下)
且這邊注意磁鐵是使用對稱

第二點在裝置上也不能偏移太多,下圖是偏移對磁場變化影響圖與實際規範範圍圖,可以看到雖然是有容許裝置範圍但不可無限制偏移

Coding Sample

這邊選用I2C來做為範例可以先參考下圖Register map

I2C傳輸

這邊只需要注意它的部分傳輸是分2筆,每筆DATA 8Bit因此在讀完整Data時與一般SPI不同是分2個register讀取

uint16_t readTwo_register(uint8_t Sensor_register)
{
	  int highByte = read_register(Sensor_register );
	  int lowByte  = read_register(Sensor_register+1);
	  return ( highByte << 8 ) | lowByte;
};

uint8_t read_register(uint8_t Sensor_register)
{
    HAL_StatusTypeDef status;
    uint8_t return_value = 0;

    status = HAL_I2C_Mem_Read(&hi2c1,ams5600_Address ,Sensor_register, I2C_MEMADD_SIZE_8BIT, &return_value, 1, 100);
    HAL_Delay(10);
    /* Check the communication status */
    if(status != HAL_OK)
    {
    	printf("I2C read status error =%#x \n\r",status);
    			/*
	HAL_ERROR    = 0x01U,
  	HAL_BUSY     = 0x02U,
	HAL_TIMEOUT  = 0x03U
    			 */
    }

    return return_value;
};

void write_register(uint8_t Sensor_register, uint8_t register_value)
{
    HAL_StatusTypeDef status = HAL_OK;

    status = HAL_I2C_Mem_Write(&hi2c1,ams5600_Address , Sensor_register, I2C_MEMADD_SIZE_8BIT, &register_value,1, 100);
    HAL_Delay(10);
    /* Check the communication status */
    if(status != HAL_OK)
    {
    	printf("I2C write status error =%#x \n\r",status);// Error handling, for example re-initialization of the I2C peripheral
    }
}

讀取角度

這部分就比較簡單單純讀取出來換算而已,至於其他功能可以做切換輸出模式等等可以再額外設定

uint16_t getRawAngle()
{
	return readTwo_register(addr_raw_angle);
}

float convertRawAngleToDegrees(uint16_t newAngle)
{
  /* Raw data reports 0 - 4095 segments, which is 0.087 of a degree */
  float retVal = newAngle * 0.087;
  return retVal;
}

總結

AS5600是使用在低轉速馬達控制PTZ等,很方便使用,也可以及時偵測磁鐵強度訊號和切換輸出,算一個CP質非常高感測器

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart