# SC60228DC + NEMA17 Stepper + DRV8841 + ESP32 Simple FOC system

**URL:** https://community.simplefoc.com/t/sc60228dc-nema17-stepper-drv8841-esp32-simple-foc-system/1802
**Category:** Uncategorized
**Created:** [March 15, 2022, 7:57pm UTC](https://community.simplefoc.com/t/sc60228dc-nema17-stepper-drv8841-esp32-simple-foc-system/1802 "2022-03-15T19:57:09Z")
**Posts on this page:** 5
**Page:** 1

<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: [March 15, 2022, 7:57pm UTC](https://community.simplefoc.com/t/sc60228dc-nema17-stepper-drv8841-esp32-simple-foc-system/1802/1 "2022-03-15T19:57:09Z")

</div>

I just wanted to describe my system and experience getting this system to work as an inspiration for others.

We wanted to make a pitch system for a small wind turbine using the above mentioned components.

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

The pitch system needs to be fast - achieve 5 degree pitch change in less than 50 ms. We also wanted it to be low cost and have low power consumption.

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

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

The encoder SC60228DC is low resolution 12bit magnetic that’s available on jlcpcb for about 3$ per piece. It was chosen due to it’s low cost and supposedly reasonable performance.

NEMA17, 50 poles with 3Ohm phase resistance. We needed at least 0.4Nm of torque. We have chosen that resistance in order to be able to run the DRV8841 relatively cool without additional cooling. To get enough speed we are using a 24V power supply.

The board uses a ESP32 since we primarily work with this microcontroller at work. The WIFI connectivity isn’t enabled on our board.

1. As already mentioned we needed to have a more accurate calibration to achieve good results with the stepper + SC60228DC. How this calibration is done + code is described in this topic. [Stepper FOC with just 12bit encoder - #7 by aokholm](https://community.simplefoc.com/t/stepper-foc-with-just-12bit-encoder/1716/7)  
This is various calibrations done with the same system after installation and reinstallation. Clearly encoder A has a lot of variation, while B is almost linear.

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

1. Torque control is done through voltage. The DRV8841 actually come with optional current control features, which we will likely use in the next iteration of the board, but for now I added the following software compensation loop to the main loop. This increase the performance dramatically.

```auto
float motor_kv = 18; // this is slightly too low, but it works.
loop() {
...
  float backEMFA = abs(motorA.shaft_velocity) * RADS_TO_RPM / motor_kv; 
  motorA.PID_velocity.limit = BASE_CURRENT + backEMFA / motorA.phase_resistance;
...

```

Currently the main loop

```auto
motorA.loopFOC();
motorA.move(-angles.upper - zeroOffsetA);
motorB.loopFOC();
motorB.move(angles.lower - zeroOffsetB);

```

runs at 10kHz. This seemed fast enough so I haven’t tried to distribute the main loop code on the two cores. Instead I run other interfacing code on the second core.

This show the performance of the system. It’s able to step ~1.5 shaft rad in 60 ms. It achieves a peak speed of ~ 40 rad/s

 ![image](https://community.simplefoc.com/uploads/default/original/2X/9/9406dc2803c89ef96d47e24c6c34b5c950c771d4.png)

Now we will need to see how the systems performance for longterm testing. Fingers crossed.

Main parameters

```auto
  motor.velocity_limit = 70;

  // // // velocity PID controller parameters
  // // // default P=0.5 I = 10 D =0
  motor.PID_velocity.P = 0.2;
  motor.PID_velocity.I = 4; // used to be 10
  motor.PID_velocity.D = 0;// 0.003;
  // // jerk control using voltage voltage ramp
  // // default value is 300 volts per sec ~ 0.3V per millisecond
  // motor.PID_velocity.output_ramp = 1000;

  // // angle PID controller 
  // // default P=20
  motor.P_angle.P = 80; // used to be 500
  motor.P_angle.I = 0; // usually only P controller is enough 
  motor.P_angle.D = 0; // usually only P controller is enough 

```

BR  
Andreas

---

<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: [March 15, 2022, 10:11pm UTC](https://community.simplefoc.com/t/sc60228dc-nema17-stepper-drv8841-esp32-simple-foc-system/1802/2 "2022-03-15T22:11:54Z")

</div>

Such an awesome project!! 😍

So cool that you’re using simpleFOC to make green tech!

Will there be a monitoring page to see how much power has been produced by the wind turbine during your long term test? Is it an open source type project that others will be able to build for themselves?

---

<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: [March 15, 2022, 10:40pm UTC](https://community.simplefoc.com/t/sc60228dc-nema17-stepper-drv8841-esp32-simple-foc-system/1802/3 "2022-03-15T22:40:04Z")

</div>

> [@aokholm](#):
>
> describe my system and experience getting this system to work as an inspiration for others

Fantastic. All the best and wish that your system is successful.

Cheers,  
Valentine

---

<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: [March 16, 2022, 3:38pm UTC](https://community.simplefoc.com/t/sc60228dc-nema17-stepper-drv8841-esp32-simple-foc-system/1802/4 "2022-03-16T15:38:18Z")

</div>

> [@runger](#):
>
> Will there be a monitoring page to see how much power has been produced by the wind turbine during your long term test?

We won’t/don’t have a live monitoring page, although it shouldn’t be too hard to make one. Data from the wind turbine is uploaded live to a influxdb and we do have a webcam on site. Perhaps once the turbine is even more sorted!

We do write progress updates every now and then on our kickstarter site: [https://www.kickstarter.com/projects/kitex/wind-catcher-portable-power-generating-wind-turbine/posts](https://www.kickstarter.com/projects/kitex/wind-catcher-portable-power-generating-wind-turbine/posts) There will be a new one in the coming days.

> [@runger](#):
>
> Is it an open source type project that others will be able to build for themselves?

The mechanical design will be open source, such that you will be able to easily reprint spares or modify the design. We haven’t decided whether the electronics and source code should be open as well.

---

<div class="post-metadata">

### Author: ![Antun\_Skuric](https://community.simplefoc.com/user_avatar/community.simplefoc.com/antun_skuric/32/21_2.png) [@Antun\_Skuric](https://community.simplefoc.com/u/Antun_Skuric)
#### Post date: [March 17, 2022, 9:00am UTC](https://community.simplefoc.com/t/sc60228dc-nema17-stepper-drv8841-esp32-simple-foc-system/1802/5 "2022-03-17T09:00:23Z")

</div>

Hey @aokholm

> [@aokholm](#):
>
> 1. Torque control is done through voltage. The DRV8841 actually come with optional current control features, which we will likely use in the next iteration of the board, but for now I added the following software compensation loop to the main loop. This increase the performance dramatically.
> 
> ```auto
> float motor_kv = 18; // this is slightly too low, but it works.
> loop() {
> ...
> float backEMFA = abs(motorA.shaft_velocity) * RADS_TO_RPM / motor_kv; 
> motorA.PID_velocity.limit = BASE_CURRENT + backEMFA / motorA.phase_resistance;
> ...
> 
> ```

I love your solution for the backemf considering for current limiting. I’ll try to integrate similar approach to the next release 😃
