You are here

AS5048A and the AS5047D Problems.

2 posts / 0 new
Last post
raess
Offline
Last seen: 1 week 4 days ago
VESC Free
Joined: 2018-03-22 20:10
Posts: 25
AS5048A and the AS5047D Problems.

I have the same problem with the AS5048A and the AS5047D.
they reads position between 180 and 360 very well and not at all 0-180.

Connected as follwing:

SCL/SCK  -> HALL 1
A2/MISO  -> HALL 2
SDA/CSn  -> HALL 3
A1/MOSI  -> VCC
GND  -> GND
5V - > VCC

I have tried to compile the latest FW with suggestions from pf26 at the vedder forum, but that had no effect on the outcome of the readings.

// Software SPI
static void spi_transfer(uint16_t *in_buf, const uint16_t *out_buf, int length) {
   for (int i = 0;i < length;i++) {
      uint16_t send = out_buf ? out_buf[i] : 0xFFFF;
      uint16_t recieve = 0;

      for (int bit = 0;bit < 16;bit++) {
         //palWritePad(HW_SPI_PORT_MOSI, HW_SPI_PIN_MOSI, send >> 15);
         send <<= 1;

         spi_delay();
         palSetPad(SPI_SW_SCK_GPIO, SPI_SW_SCK_PIN);
         spi_delay();
         
         palClearPad(SPI_SW_SCK_GPIO, SPI_SW_SCK_PIN); // Moved before MISO Read
         spi_delay();

         int r1, r2, r3;
         r1 = palReadPad(SPI_SW_MISO_GPIO, SPI_SW_MISO_PIN);
         __NOP();
         r2 = palReadPad(SPI_SW_MISO_GPIO, SPI_SW_MISO_PIN);
         __NOP();
         r3 = palReadPad(SPI_SW_MISO_GPIO, SPI_SW_MISO_PIN);

         recieve <<= 1;
         if (utils_middle_of_3_int(r1, r2, r3)) {
            recieve |= 1;
         }
      }

      if (in_buf) {
         in_buf[i] = recieve;
      }
   }
}

 

However The AS5047D did support ABI interface and that worked very well, reading 0-360 degrees perfectly.

I am also going to try the AS5047P tomorrow and see how that works.

Any other suggestions on how to get this encoders working at 0-360degreess with SPI?
 

 

Thanks Robin

benjamin
Offline
Last seen: 1 week 5 days ago
VESC Original
Joined: 2016-12-26 15:20
Posts: 249

It sounds like the MSB is always 1 for some reason, but I don't know why. I have used the AS5047D without problems many times.

You can have a look at this function and make some kind of hack to work around the problem:

https://github.com/vedderb/bldc/blob/master/encoder.c#L241

For example, this would ignore the MSB and use 13 bits instead of 14.

void encoder_tim_isr(void) {
	uint16_t pos;

	spi_begin();
	spi_transfer(&pos, 0, 1);
	spi_end();

	pos &= 0x1FFF;
	last_enc_angle = ((float)pos * 360.0) / 8192.0;
}