sosandroid / AMS_AS5048B

Arduino Lib for AMS AS5048B I2C - 14-bit magnetic rotary position sensor
Other
48 stars 29 forks source link

Zero position did not reset #1

Closed MechatronicsWorkman closed 6 years ago

MechatronicsWorkman commented 8 years ago

I was trying to use this code on an Arduino Uno and ran into problems. The read angle code seems to work as expected however the reset zero position did not work for me. After reading the AS5048B data sheet it mentioned to clear the zero position register first before writing a new angle to it. Thus I made the following changes which seem to work.

void AMS_AS5048B::setZeroReg(void) {

//I ADDED THIS
AMS_AS5048B::writeReg(AS5048B_ZEROMSB_REG, (uint8_t) 0x00);
AMS_AS5048B::writeReg(AS5048B_ZEROLSB_REG, (uint8_t) 0x00);
//I ADDED THIS

uint16_t zero = AMS_AS5048B::readReg16(AS5048B_ANGLMSB_REG);
AMS_AS5048B::zeroRegW(zero);
return;
}

Just thought I would pass on this information to anyone else using this code.

sosandroid commented 8 years ago

Hi,

Thanks for this feedback. The issue is solved.

oilXander commented 7 years ago

Hi,

The issue wasn't solve. The library have some error.

Now there is :

void AMS_AS5048B::setZeroReg(void) {

    uint16_t newZero = AMS_AS5048B::readReg16(AS5048B_ANGLMSB_REG);
        AMS_AS5048B::zeroRegW((uint16_t) 0x00); //Issue closed by @MechatronicsWorkman
    AMS_AS5048B::zeroRegW(newZero);
    return;
}

But for correct work it seems it should look like this

void AMS_AS5048B::setZeroReg(void) {

        AMS_AS5048B::zeroRegW((uint16_t) 0x00); //Issue closed by @MechatronicsWorkman
    uint16_t newZero = AMS_AS5048B::readReg16(AS5048B_ANGLMSB_REG);
        AMS_AS5048B::zeroRegW(newZero);
    return;
}
sosandroid commented 7 years ago

Comit done, to be validated as I do not have the device with me right now