How to change AS5047U settings?

Could someone please explain how to change the AS5047U ABI resolution to 14 bits (instead of the default 11)?

I can see that someone took the time to create the AS5047U driver and included the correct function

void writeSettings3(AS5047USettings3 settings);

It looks like I can call the writeSettings3 function and pass values to it, but they need to be of the union type

union AS5047USettings3 {
	struct {
		uint16_t uvwpp:3;
		uint16_t hys:2;
		uint16_t abires:3;
	};
	uint16_t reg;
};

However, I’m struggling to figure out how to pass these values into the function. Any ideas?

I was able to get something to compile by doing this

  AS5047USettings3 settings3;
  settings3 = {0,0,4};
  sensor.writeSettings3(settings3);

However, the resolution isn’t changing. I can read the 14-bit angle via SPI just fine though so I know SPI is working correctly.

If I do a quick write then read, it looks like the write isn’t going through

  AS5047USettings3 settings3_write;
  settings3_write.abires = 4;
  sensor.writeSettings3(settings3_write);

  AS5047USettings3 settings3_read;
  settings3_read = sensor.readSettings3();
  Serial.println(settings3_read.abires);

The output is 0 when it whould be 4

If I place this in the loop, the angle comes back in 14 bits which means SPI is working well.

Serial.println(sensor.readCorrectedAngle());

Serial Monitor:

9350
9350
9349
9349
9349

@runger Any ideas what might be happening here? Have you ever flashed the Non-volatile memory in the AS5074U? I’m not trying to burn it in permanently, just set it in the setup loop

Hey,

I recently fixed bugs in the drivers for the AS5047 and AS5047U. I was able to test the AS5047 driver on an AS5047P, and this was working for my test cases.

The AS5047U is unfortunately a bit different in terms of its protocol, hence it has its own driver. I didn’t have a chance to test it yet. So it could be that there are still bugs to be fixed in the driver.

The code looks ok in principle, but you should read the settings first, and change only the value you’re trying to write, like this:

  AS5047USettings3 settings3;
  settings3 = sensor.readSettings3();
  settings3.abires = 4;
  delay(1);
  sensor.writeSettings3(settings3);
  delay(50);
  settings3 = sensor.readSettings3();
  Serial.println(settings3.abires);

Adding some delays can’t hurt, either. On a fast MCU you could in theory hit the chip too quickly, it likes a bit of delay after operations.

If the above is not working for you, it is probably down to problems with the write implementation and/or CRC calculation…
You could check using the sensor.errorflag and sensor.warningflag fields, and also by calling:

AS5047UError errinfo = clearErrorFlag();
// then check fields of errinfo like errinfo.crc_error ...
if (errinfo.crc_error) Serial.prinltln("CRC Error");

@runger Unfortunately that didn’t work, but in the process I thought I’d check out all the error data. Looks like it’s getting a ton of SPI errors:

ERRORS:
agc_warning: 1
cmd_error: 1
cordic_ovf: 0
crc_error: 0
frame_error: 1
maghalf: 0
off_notfinished: 0
p2ram_error: 0
p2ram_warning: 1
wdtst: 0
  1. Command_ error: SPI invalid command received
  2. Framing error: Framing if SPI communication wrong
  3. P2ram_warning: ECC is correcting one bit of P2RAM in customer area

I’m really sorry - I will have to debug it.
It will take me a little while, as I have a lot of other work right now.

If you can make progress on it in the meantime, all the better!

Otherwise I have a AS5147U which I can test on - it has the same protocol as the AS5047U as far as I can tell. I will set it up and test it next week if I can find the time.

I really appreciate all the time you’re putting into this regardless, and there’s absolutely no rush. I will keep working on it and post my progress here