You are here

AS5048A and the AS5047D Problems.

3 posts / 0 new
Last post
raess
Offline
Last seen: 2 years 7 months ago
Joined: 2018-03-22 20:10
Posts: 38
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: 2 weeks 1 day ago
VESC FreeVESC OriginalVESC Platinum
Joined: 2016-12-26 15:20
Posts: 490

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;
}

 

liqikai
Offline
Last seen: 3 years 1 week ago
Joined: 2018-09-11 11:13
Posts: 1

Hello, I also have a problem when I am using as5048a. I have tried software SPI and hardware SPI to make connection between as5048a and VESC, but failed all. I  can't pass through the Motor Setup Wizard if I choose FOC and as5047, there is always a serial resource error. So I tested all the Pin and found something weird, here is the img from CS Pin:

magic.jpeg

It's almost same in both SPI Mode. I have also tried the method above and the sensor works fine in my program for testing. So is it because of the hardware filter that the CS Pin can't reach GND? But how to explain this even though I used hardware SPI?