SC60228DC + NEMA17 Stepper + DRV8841 + ESP32 Simple FOC system

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.

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.

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
    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.

  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.
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

motorA.move(-angles.upper - zeroOffsetA);
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

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

Main parameters

  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 



Such an awesome project!! :heart_eyes:

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?

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


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: There will be a new one in the coming days.

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.

Hey @aokholm

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

1 Like