Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
AS5601.cpp
- Committer:
- kimuraYUKI
- Date:
- 2019-11-27
- Revision:
- 0:f1ca084bfe47
- Child:
- 1:81d37343e965
File content as of revision 0:f1ca084bfe47:
#include "AS5601.h"
AS5601::AS5601(PinName sda, PinName scl, int ppr, int offset_val) : i2c(sda,scl)
{
i2c.frequency(400000);
offset = offset_val;
//初期化
//平均化数設定
int conf1_set = read(CONF1_REG);
conf1_set |= SF_16X;
write(CONF1_REG ,conf1_set);
//PPR設定
int abn_set = read(ABN);
if(ppr < 0b1000)abn_set |= ppr;
else abn_set |= PPR2048;
write(ABN,abn_set);
}
int AS5601::getAngleAbsolute()
{
char cmd1=0x0E,cmd2=0x0F;
int data=0;
data=this->read(cmd1) << 8;
data=data+this->read(cmd2);
return data;
}
float AS5601::getAngleDegrees()
{
return (((float)this->getAngleAbsolute()-offset) * 180) / 2048 ;
}
char AS5601::read(char address)
{
char retval;
i2c.write(I2C_ADDR * 2, &address, 1);
i2c.read(I2C_ADDR * 2, &retval, 1);
return retval;
}
int AS5601::write(char address, char data)
{
char buf[2];
buf[0] = address;
buf[1] = data;
int val = i2c.write(I2C_ADDR * 2, buf, 2);
return val;
}