Application Notes

Application Note: AS5048B - I2C sensor readout
AS5048B
14-bit Rotary Position Sensor with Digital Interface
www.ams.com
Revision 1.1 / 2013/06/26
AS5048
2
I C sensor readout
Table of Contents
1.
General Description ............................................................................................................... 2
2.
Reading the AS5048B using I2C ........................................................................................... 2
3.
Sensor Output Averageing .................................................................................................... 3
4.
Setting the Zero Position ....................................................................................................... 3
5.
I2C Register Map ................................................................................................................... 4
6.
Output registers read-cycle ................................................................................................... 5
7.
Ordering Information .............................................................................................................. 6
Copyright ....................................................................................................................................... 7
Disclaimer ..................................................................................................................................... 7
Revision History
Revision
Date
Owner
Description
1.0
03.28.2013
rph
Initial Version
1.1
26.06.2013
rph
Updated Averaging Description
www.ams.com
Revision 1.1 / 26/06/13
page 1/8
AS5048
2
I C sensor readout
1.
General Description
This Application Note explains how to communicate with the AS5048 14-bit Rotary Position
Sensor. There are two versions of the AS5048 available:
Table 1:
AS5048 versions
Ordering Code
AS5048A
AS5048B
Digital Angle Interface
SPI
I2C
Find more information on our webpage:
http://ams.com/eng/Products/Magnetic-Position-Sensors
2.
Reading the AS5048B using I2C
2
The next code lines demonstrate how the AS5048B can be read using the I C interface of the
application microcontroller.
#define readings 6
unsigned char buffer[readings];
for(i = 0; i < readings; i++)
{
buffer[i] = I2C_Read8_AS5048B(0x40, 0xFA+i);
}
AGC=buffer[0];
error_status=buffer[1]&0x0F;
MAG=(buffer[2]<<6)+(buffer[3]&0x3F);
ANG=(buffer[4]<<6)+(buffer[5]&0x3F);
www.ams.com
Revision 1.1 / 26/06/13
page 2/8
AS5048
2
I C sensor readout
3.
Sensor Output Averageing
The code example below shows an easy averaging algorithm to reduce noise of the angular
output for angular values within one rotation and with no zero crossing of the output data .
Note: As 360° is the same as 0° this would cause an averaging error. To perform averaging of
output data with more than one rotation refer to “Mean of circular quantities”.
Example:
#define average 100
for (count = average; count; count--)
{
data = sensor_read(); //reading,computing sensor output
position += data;
}
position = position / average;
4.
Setting the Zero Position
The Zero Position of the angle output can be set individually depending on the application
requirements. Following code examples show how to set the Zero Position.
Example:
I2C_Write8(0x40,0x16,0x00); // Reset Zero Position high byte
I2C_Write8(0x40,0x17,0x00); // Reset Zero Position low byte
for(i = 0; i < 6; i++) // Readout Position
{
buffer[i] = I2C_Read8_AS5048B(0x40, 0xFB+i); // start reading at
Error Register 0xFB
}
error_status=(buffer[0]&0x0F);
if(error_status==1) // No Error
{
ANG=(buffer[3]<<6)+(buffer[4]&0x3F); // Calculate Angle
I2C_Write8(0x40,0x16,buffer[3]); // Write Zero Position high byte
I2C_Write8(0x40,0x17,buffer[4]); // Write Zero Position low byte
}
else printf ("\n\n
www.ams.com
ERROR
");
Revision 1.1 / 26/06/13
page 3/8
AS5048
2
I C sensor readout
5.
I2C Register Map
The available registers for I2C communication of the AS5048B are listed in Figure 1.
Figure 1:
I2C Register Map
Programmable Customer settings
Control OTP
Address
dec
3
21
Programming
Control
I²C slave
address
Access
Type Bit Nr.
R/W
R/W
+
Program
22
OTP Register
Zero Position
Hi
R/W
+
Program
23
OTP Register
Zero Position
Low 6 LSBs
R/W
+
Program
250
Automatic
Gain
Control
R
251
Readout Registers
Name
Diagnostics
252
R
R
Magnitude
253
R
254
R
Angle
255
www.ams.com
R
7
6
5
4
3
2
1
0
7
:
5
Symbol
Default
Description
not used
Verify
not used
Burn
0
reserved
Programming control register.
Programming must be enabled before burning the
fuse(s). After programming is an verification mandatory.
See programming procedure.
Programming Enable
not used
4
I²C address<4>
:
0
7
:
0
7
6
5
:
0
7
:
0
7
:
4
3
2
1
0
7
:
0
7
6
5
:
0
7
:
0
7
6
5
:
0
:
I²C address<0>
Zero Position <13>
:
Zero Position <6>
n.a.
I²C slave address
slave address consist of 5 programable bits (MSBs)
and the hardware setting of Pins A1 and A2
internally
inverted I²C address <4> is by default not programmed and due
to the inversion defined as '1'
:
0
0
:
Zero Position value high byte
0
not used
n.a.
Zero Position <5>
:
Zero Position <0>
AGC value<7>
:
AGC value<0>
0
:
0
1
:
0
not used
n.a.
Comp High
Comp Low
COF
OCF
Magnitude<13>
:
Magnitude<6>
0
0
0
1
0
:
0
not used
Magnitude<5>
:
Magnitude<0>
Angle<13>
:
Angle<6>
n.a.
0
:
0
0
:
0
not used
n.a.
Angle<5>
:
Angle<0>
0
:
0
Revision 1.1 / 26/06/13
Zero Position remaining 6 lower LSB's
Automatic Gain Control value.
0 decimal represents high magnetic field
255 decimal represents low magnetic field
Diagnostic flags
Magnitude information afer ATAN calculation
Angle Value afer ATAN calculation
and zero position adder
page 4/8
AS5048
2
I C sensor readout
6.
Output registers read-cycle
For further reference, a logic plot showing the readout of the output registers 0xFE and 0xFF is
shown below.
Figure 2:
Output registers read-cycle
www.ams.com
Revision 1.1 / 26/06/13
page 5/8
AS5048
2
I C sensor readout
7.
Ordering Information
Table 2:
Ordering Information
Ordering Code
Description
comments
AS5048B-EK-AB-STM1.0
AS5048B Eval-Kit for stepper motor
I2C interface
www.ams.com
Revision 1.1 / 26/06/13
page 6/8
AS5048
2
I C sensor readout
Copyright
Copyright © 1997-2013, ams AG, Tobelbader Strasse 30, 8141 Unterpremstaetten, Austria-Europe.
Trademarks Registered ®. All rights reserved. The material herein may not be reproduced, adapted, merged,
translated, stored, or used without the prior written consent of the copyright owner.
All products and companies mentioned are trademarks or registered trademarks of their respective companies.
Disclaimer
Devices sold by ams AG are covered by the warranty and patent indemnification provisions appearing in its
Term of Sale. ams AG makes no warranty, express, statutory, implied, or by description regarding the
information set forth herein or regarding the freedom of the described devices from patent infringement. ams
AG reserves the right to change specifications and prices at any time and without notice. Therefore, prior to
designing this product into a system, it is necessary to check with ams AG for current information.
This product is intended for use in normal commercial applications. Applications requiring extended
temperature range, unusual environmental requirements, or high reliability applications, such as military,
medical life-support or lifesustaining equipment are specifically not recommended without additional
processing by ams AG for each application. For shipments of less than 100 parts the manufacturing flow might
show deviations from the standard production flow, such as test flow or test location.
The information furnished here by ams AG is believed to be correct and accurate. However, ams AG shall not
be liable to recipient or any third party for any damages, including but not limited to personal injury, property
damage, loss of profits, loss of use, interruption of business or indirect, special, incidental or consequential
damages, of any kind, in connection with or arising out of the furnishing, performance or use of the technical
data herein. No obligation or liability to recipient or any third party shall arise or flow out of ams AG rendering of
technical or other services.
Contact Information
Headquarters
ams AG
Tobelbader Strasse 30
8141 Unterpremstaetten
Austria
T. +43 (0) 3136 500 0
For Sales Offices, Distributors and Representatives, please visit:
http://www.ams.com/contact
www.ams.com
Revision 1.1 / 26/06/13
page 7/8