AMS_AS5600

Preface

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

The AS5600 has some important hardware setup points. The first point is the selection of magnets. The magnet size should be as circular as possible because it senses the perpendicular change of the magnetic field (size specifications are as follows). Also, note that symmetrical magnets should be used.

The second key point is that the device cannot be offset too much. The following figure shows the effect of offset on magnetic field variation and the actual specification range. Although there is a permissible range for device installation, unlimited offset is not allowed.

Coding Sample

Here we use I2C as an example. You can refer to the Register Map below.

I2C code

This device uses I2C as an example, and it should be noted that its partial transfer is divided into two parts, with 8 bits of data for each part. Therefore, when reading the complete data, it is different from the normal SPI and requires reading from two separate registers.

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
    }
}

Read angle

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

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;
}

Sum

AS5600 is a high-quality sensor with a very convenient usage and is commonly used in low-speed motor control, PTZ, etc. It can detect magnet strength signals and switch outputs in real-time, making it an excellent sensor with high CP value.

Leave a Comment

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

Shopping Cart