Slow smooth diy motor with simpleFOC

Hey all,

I wanted to say thanks for sharing this library. I made a very crude motor and attached it to a L293. The results are here:

My main goal is slow and smooth rotation. The overshoots are very big and while I spent quite a bit of time trying to tune the PID I barely know what i’m doing. The resistance is a bit too low and the L293’s overheat pretty quickly so I abandon’ed trying to manually tune out the overshooting for angle and velocity control. Has anyone had any luck using something like autoPID tuning?

Next I’m going to make a L6234 board. My coils are ~3 ohms and I may try to make new coils with a larger resistance. I wonder if I should try to make them coreless? If anyone has any advice for me on how to make a silent and slow speed DIY motor/controller pair please let me know.

Regarding the L6234 I read there should be some protections on the inputs/enable pins. I was planning on 4.7k serial resistors, wondering why those are not included on the simpleFOC board? Also wondering what exactly this means “The device GND has to be connected with a separate path to the input capacitor ground.” since there are so many device GND connections?

Thanks and cheers for creating a community around this!

1 Like

Hi @schoch, welcome to the community!
The l293, I believe is a quad half bridge. So I’m guessing you are using 3 of those 4 output channels. I think @David_Gonzalez has used the l293 in the past but has since moving on to beafier driver/mostfets (DRV8323 + something).

Looking at the spec of your l293 - I think the L6234 (triple h bridge) has about twice the power. It might run a little cooler.

I’ve not seen that type of encoder, can you tell me a bit more about it? Did you have to change the Encoder.cpp to get it to work?

@Antun_Skuric has recently said that he’ll be adding a bit of ‘D’ (from PID) so you’ll soon have a bit of damping to tune. This might help with your overshoot. Keep an eye on the dev branch for changes to bldcmotor.cpp.

Just watched your video again. This is a homemade motor! So it’s an inrunner, with 3 slots and, what, 20 pole pairs?
How many turns does each phase have? 3 ohms, you say - what thickness is the wire? . I’m assuming this is a star (rather than Delta) type.
I’d like to make my own motor (or rewind a motor) some day.

this is just 2 optointerrupters with a 70 slot disk to provide the pulses. Since it is quadrature no changes are needed to the code.

ya, it is home made 3 coils and 22 magnets with a 60mm ID delrin bearing with glass balls. The wire is .25mm and it is ~300 turns wired in WYE configuration. The coil cores were turned on my lathe in a bobbin shape but I think printing out bobbins would be better for focusing the field. They have plenty of push for the slow movements i’m looking for. I do want to increase the turns to 900. it was running off a current limited supply at between .4 and 1.2A. I think the L293s are very inefficient and that the L6234’s have better thermal design and more efficient mosfets. I made a board for it today and will give it a try tomorrow.

here’s the L6234. Much better control!!!

I had some wonky issues with my UNO’s pins but i’m not sure if that was related to an issue I had with the board I made or the MCU itself. I’m going to mess with an STM32 next…

The uno has a crappy 8bit analogWrite. It looks like a saw tooth sign wave by the time it gets to your l2634! Especially if you’ve got a high value for your motor.power_supply but are just using a small fraction of that.
I believe the stm32 (like the esp32) is capable of 12bit output e.g. using analogWriteResolution(12);
The esp32 implementation (by @David_Gonzalez) goes one better and ensure that the pwm output is ‘centralised’.
The end result is a motor that runs without that annoying whine and is probably smoother and more efficient.

I did some experiments with the esp32 code. I did not not have much success tuning the PI controller to the level I am after but I didn’t think my home made motor really would have been able to do what I wanted. I think a guide would be helpful on tuning the PI controller or even better some description on how to code an auto tuning function!

Below is really what i’m after. This is driven with steppers and maybe they are the best way to do this but these X27 steppers are not silent (perhaps the arduino PWM frequency, maybe esp32 could drive them more quietly). I could also try to do some mechanical reduction with a BLDC. If anyone has any ideas on how to make a very low torque motor that can rotate silently, smoothly, and very slowly please let me know.

Does it have to be closed loop? If it’s low torque and constant - then I’d just run it open loop. No PI tuning required. Or is that cheating? :wink:

If you are going for constant speed / closed loop and your encoder is 70 slots (~6bits per revolutions), it may need to have a higher Tf - you could even try going crazy high like 0.5. I’m not talking from experience just intuition so I’m likely wrong!

@Antun_Skuric might correct me - but if you want it to go slow but aren’t massively concerned on the exact speed then you could try not using I. Just P. With just P and undertuned you might ask for 20 degrees per second but get 10 degrees per second. If speed is still lumpy then it’s likely due to cogging. P will only oscillate when its overtuned.

If it is cogging then you could try to implement an anti-cogging algorithm. From what I’ve read this involves profiling how speed/position changes in an electrical rotation (or perhaps even a full shaft rotation) and storing some ‘corrections’ in some lookup. Then after your profiling is complete you add your corrections into simplefoc at some layer. Haven’t thought how it would work - perhaps you could add your correction code inside motor.normalizeAngle() so that this function returns slight adjustments to the setPhaseVoltage’s angle.

One more thing. At such slow speed stepper motors can be silent. I’ve used the drv8825 (which is slightly better than an a4988 imho) at 32 microstepping (i.e. 200x32 steps per revolution) and it is quiet and costs about $2. Perhaps the current needs to be reduced? A4988 and DRV8825 have a little pot to alter the current. My drv8825 are typically paired with a nema17 which comes in a range of thicknesses.

If you want to get fancy - you could go for one of the silentstep trinamic drivers used in newer 3d printers (e.g. TMC2209) but they are more like $10 and I can’t tell you if they are easy to use.