# Angle sensor SPI support / SC60228DC

**URL:** https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682
**Category:** hardware support
**Tags:** sc60228
**Created:** [February 7, 2022, 11:21pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682 "2022-02-07T23:21:02Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 15, 2022, 9:29pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/21 "2022-02-15T21:29:25Z")

</div>

> [@aokholm](#):
>
> 50 pole stepper

No idea about steppers. However:

角度线性误差 \<±0.35° from the documentation means angular non-systemic error less than 0.35°

Which means 360° is divided into 1024 error-free steps or 10-bit error free if you do not use any filtering.

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [February 15, 2022, 9:33pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/22 "2022-02-15T21:33:23Z")

</div>

> [@aokholm](#):
>
> On a side note… Do you think this encoder will be able control a 50 pole stepper?

I doubt it. If you search this forum, other users have had trouble with the high pole count steppers even when using 14bit sensors, and this one is only 12bit.

I think this sensor will be suitable for lower pole-pair motors, maybe up to 11PP or so?

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 15, 2022, 9:46pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/23 "2022-02-15T21:46:03Z")

</div>

> [@aokholm](#):
>
> 50 pole stepper? From my understanding having 80 positions

That’s 4000 positions. Perhaps an optical graycode encoder, but those are more expensive than the stepper. Cheapest I’ve seen are $50 and more.

[https://www.digikey.com/en/products/detail/cui-devices/AMT203S-V/9739186](https://www.digikey.com/en/products/detail/cui-devices/AMT203S-V/9739186)

---

<div class="post-metadata">

### Author: ![aokholm](https://community.simplefoc.com/user_avatar/community.simplefoc.com/aokholm/32/2439_2.png) [@aokholm](https://community.simplefoc.com/u/aokholm)
#### Post date: [February 15, 2022, 10:00pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/24 "2022-02-15T22:00:02Z")

</div>

Sure I just noticed this aspect in the data sheet.

Here is an English version of the data sheet: [https://semiment.com/wp-content/uploads/2021/04/SC60228\_EN-VA1.0.pdf](https://semiment.com/wp-content/uploads/2021/04/SC60228_EN-VA1.0.pdf)

Still. 2^10 = 1024. That’s roughly equivalent to equivalent to a regular stepper driver with 4 micro steps. (4micro/full\*200 full steps/rev = 800 micro steps/rev). Still I don’t how the accuracy effects the speed and position estimates in this library.

I got the 14 bit AS5048A working great earlier to day (1 prototype).

The AS5048A has even worse (perhaps more accurate specs)

 ![image](https://community.simplefoc.com/uploads/default/original/2X/9/94fced26e0d5b17f16949c7fdf2c4056a60f935d.jpeg)

Thanks for the answers. I will not be too hopeful! 🙂

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [February 16, 2022, 12:09am UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/25 "2022-02-16T00:09:54Z")

</div>

I coded up a driver for it:

> **[Arduino-FOC-drivers/src/encoders/sc60228 at dev · simplefoc/Arduino-FOC-drivers](https://github.com/simplefoc/Arduino-FOC-drivers/tree/dev/src/encoders/sc60228)**
>
> Drivers and support code for SimpleFOC. Contribute to simplefoc/Arduino-FOC-drivers development by creating an account on GitHub.

It’s not yet tested since I’m still waiting on my boards… so its still on the dev branch of the drivers repo. I will merge it to master once it is tested.

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 16, 2022, 1:03am UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/26 "2022-02-16T01:03:10Z")

</div>

> [@runger](#):
>
> coded up a driver for it:

@runger

That’s great. Question:

`SC60228SPISettings(8000000, SC60228_BITORDER, SPI_MODE1);`

Is 8000000 hardcoded clock speed?

Thanks,  
Valentine

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [February 16, 2022, 7:37am UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/27 "2022-02-16T07:37:31Z")

</div>

As the default… but you can always override it by passing your own instance of settings.

I think 10MHz is the max if I read the datasheet correctly.

It’s really the kind of thing I check when I test the driver. Also the SPI mode 1 I have to look at TBH I didn’t check it.

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [February 17, 2022, 8:13am UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/28 "2022-02-17T08:13:00Z")

</div>

![image](https://community.simplefoc.com/uploads/default/original/2X/5/5361283edad0f355c4d54ab4b4dc27750f8ba708.png)

This means PCBs done. Now assembly will follow.

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 17, 2022, 4:22pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/29 "2022-02-17T16:22:30Z")

</div>

![image](https://community.simplefoc.com/uploads/default/original/2X/3/3e5ced35edafd0c9928c689a64cc6c2478d70bcb.png)

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 17, 2022, 4:26pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/30 "2022-02-17T16:26:30Z")

</div>

My cat, HexaDecimal, is waiting to test the new sensors!

 ![image](https://community.simplefoc.com/uploads/default/original/2X/6/6c855681ceefd41a6f426e31358e365b30be8643.jpeg)

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 22, 2022, 11:01pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/31 "2022-02-22T23:01:13Z")

</div>

The sensors have arrived. Time to feed the cat.

 ![image](https://community.simplefoc.com/uploads/default/original/2X/a/a02c274b97208709d35405558f9f27fef7c48ea3.jpeg)

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [February 23, 2022, 12:35am UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/32 "2022-02-23T00:35:07Z")

</div>

Supercool!

Mine are still in production… that’s what you get for the more bespoke treatment, it takes a lot longer for the assembly because the components are not “in-house”…

I’ll keep you updated, but in the meantime you can try yours out and let us know if they work! I’m excited to find out!

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 25, 2022, 4:08am UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/33 "2022-02-25T04:08:45Z")

</div>

> [@runger](#):
>
> not yet tested since I’m still waiting on my boards

I’m trying to run it, but hitting some problems. First, the

encoders/sc60228/MagneticSensorSC60288.h

should be 228 (228 instead of 288) but that’s a minor problem.

I’m not getting any readings, not sure why.

I’ll post more tomorrow and some pictures, it’s getting late here.

Cheers,  
Valentine

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [February 25, 2022, 8:07am UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/34 "2022-02-25T08:07:10Z")

</div>

Hmmm… mine will still be a few days…

 ![image](https://community.simplefoc.com/uploads/default/original/2X/4/46b8cf3f45f7e4328c4aaddd328e6fe301b76b81.png)

---

<div class="post-metadata">

### Author: ![aokholm](https://community.simplefoc.com/user_avatar/community.simplefoc.com/aokholm/32/2439_2.png) [@aokholm](https://community.simplefoc.com/u/aokholm)
#### Post date: [February 25, 2022, 4:48pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/35 "2022-02-25T16:48:43Z")

</div>

I also order a set of 5 board with 2 of these encoders per board last Saturday at jlcpcb. They just finished production. Hopefully they will arrive next week.

 ![image](https://community.simplefoc.com/uploads/default/original/2X/2/24365ad88d87a4e5b6723ef7be3d98ec32082799.png)

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 25, 2022, 5:34pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/36 "2022-02-25T17:34:20Z")

</div>

More details. I’m testing a second sensor (the first is buried inside a complex mechanical part, so I may have messed up the wiring or mechanically damaged the sensor). The PWM interface works fine. I’m proceeding to testing the SPI. It may be the sensor works fine but the code cannot “talk” to the sensor SPI, because the fact that the PWM works fine means the sensor is alive and signaling the angle.

Let me try with other means of connecting the wires.

Update1: The PWM frequency is 1kHz and duty cycle is between 0 and 100 depending on magnet orientation. This means realistically for PWM interface the RPM measured cannot exceed 600rpm (10rps) which will give 100 measuring points around the circle before we exceed the delay). That’s a little disappointing, they could have done easily 10kHz PWM.

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 25, 2022, 6:03pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/37 "2022-02-25T18:03:13Z")

</div>

> [@aokholm](#):
>
> order a set of 5 board with 2 of these encoders per board last Saturday at jlcpcb.

Wow that’s brave. Hopefully the sensor will work on your board. Are you using the PWM or SPI interface?

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 25, 2022, 6:38pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/38 "2022-02-25T18:38:15Z")

</div>

Gives 0.0 reading. This is the code below. Let me see if I could read raw values directly from the SPI bypassing SimpleFOC.

```auto
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include "encoders/sc60228/MagneticSensorSC60228.h"

BLDCMotor motor = BLDCMotor(1);

BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PB13, PA9, PB14, PA10, PB15, PB12);

MagneticSensorSC60228 sensorSC60228(PA4);

void setup() {

  sensorSC60228.init();

  driver.voltage_power_supply = 12;

  driver.pwm_frequency = 15000;

  driver.init();

  motor.linkDriver(&driver);

  motor.voltage_limit = 3; // [V]
  motor.velocity_limit = 10; // [rad/s] cca 50rpm
 
  motor.controller = MotionControlType::velocity_openloop;

  motor.init();

  Serial.begin(115200);
  Serial.println("Motor ready!");
  Serial.println("Set target velocity [rad/s]");
  _delay(1000);
}

void loop() {

  _delay(100);
   Serial.println(sensorSC60228.getAngle());
  motor.move(2);
}

```

---

<div class="post-metadata">

### Author: ![robotsmith](https://community.simplefoc.com/user_avatar/community.simplefoc.com/robotsmith/32/1929_2.png) [@robotsmith](https://community.simplefoc.com/u/robotsmith)
#### Post date: [February 25, 2022, 7:39pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/39 "2022-02-25T19:39:29Z")

</div>

Hi,  
Any information from a logic analyser or oscilloscope?  
Is the clk frequency ok?  
Have you the requested pullups?

Cheers!

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [February 25, 2022, 7:42pm UTC](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682/40 "2022-02-25T19:42:47Z")

</div>

Still working on this. If it doesn’t work from the first try, then it takes days to do hardware debugging. Hopefully we don’t have to involve logic analyzers.

[Previous page](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682.md?page=1)

[Next page](https://community.simplefoc.com/t/angle-sensor-spi-support-sc60228dc/1682.md?page=3)
