- ページ 9
アクセサリー AMS AS5048 Eval-KitのPDF ユーザーマニュアルをオンラインで閲覧またはダウンロードできます。AMS AS5048 Eval-Kit 12 ページ。 14-bit rotary position sensor with digital angle (interface) and pwm output
AMS AS5048 Eval-Kit にも: キットマニュアル (16 ページ), 操作マニュアル (10 ページ)
User Manual – AS5048-AB
5
Firmware coding
The following source code fits the 4-Wire application
The function
void
spiReadData() reads/writes 4 values from the AS5048
- Send command READ AGC / Receive value unknown
- Send command READ MAG / Receive value AGC
- Send command READ Angle / Receive value MAG
- Send command NOP (no operation) / Receive value ANGLE
If a READ ANGLE only is necessary in a loop, the procedure can be reduced to one line:
- Send command READ Angle / Receive value Angle
The function
static
u8 spiCalcEvenParity(ushort value)
stream.
/*!
*****************************************************************************
*
Reads out chip data via SPI interface
*
*
This function is used to read out cordic value from chips supporting SPI
*
interface.
*****************************************************************************
*/
#define
SPI_CMD_READ 0x4000
#define
SPI_REG_AGC
#define
SPI_REG_MAG
#define
SPI_REG_DATA
#define
SPI_REG_CLRERR 0x1
void
spiReadData()
{
u16 dat;
u16 magreg;
ushort angle, agcreg;
ubyte agc;
ushort value;
bit alarmHi, alarmLo;
/* Send READ AGC command. Received data is thrown away: this data comes from the precedent
command (unknown)*/
dat
= SPI_CMD_READ | SPI_REG_AGC;
dat |= spiCalcEvenParity(dat) << 15;
spiTransfer((u8*)&dat, sizeof(u16));
/ /* Send READ MAG command. Received data is the AGC value: this data comes from the
precedent command (unknown)*/
dat
= SPI_CMD_READ | SPI_REG_MAG;
dat |= spiCalcEvenParity(dat) << 15;
spiTransfer((u8*)&dat, sizeof(u16));
magreg = dat;
/* Send READ ANGLE command. Received data is the MAG value, from the precedent command */
dat
= SPI_CMD_READ | SPI_REG_DATA;
dat |= spiCalcEvenParity(dat) << 15;
spiTransfer((u8*)&dat, sizeof(u16));
agcreg = dat;
/* Send NOP command. Received data is the ANGLE value, from the precedent command */
dat = 0x0000;
spiTransfer((u8*)&dat, sizeof(u16));
angle = dat >> 2;
}
if
((dat & 0x4000) || (agcreg & 0x4000) || (magreg & 0x4000))
{
/* error flag set - need to reset it */
www.ams.com
/*!< flag indicating read attempt when using SPI interface */
0x3ffd
/*!< agc register when using SPI */
0x3ffe
/*!< magnitude register when using SPI */
0x3fff
/*!< data register when using SPI */
/*!< clear error register when using SPI */
// 16-bit data buffer for SPI communication
// NOP command.
Revision 1.2 / 14.01.2014
is optional, it calculates the parity bit of the 16-bit SPI
page 9/12