New ground-up ESC - MESC_FOC_ESC

Electric Motors and Controllers
flute2k3@hotmail.com   10 W

10 W
Posts: 82
Joined: Nov 26 2019 8:16pm

Re: New ground-up ESC - MESC_FOC_ESC

Post by flute2k3@hotmail.com » May 11 2022 8:29pm

mxlemming wrote:
May 11 2022 7:58pm
It could but it would take porting and setup. Also you'd need external op amps or current sensors since f302 i recall only has 2 and I'm not going to deal with that nonsense.
yes, only 2, give up.
mxlemming wrote:
May 11 2022 7:58pm
Just built up the easy DIY ESC from badgineer and casainho (I've been helping badgineer a bit) and I'm trying to port MESC to the black pill f401 which is (just about) pin compatible with blue pill so that might bea better option for you!
IMG_20220512_015313297.jpgIMG_20220512_015327825_HDR.jpg
agree, after playing with easy DIY ECS board, I expect a board/chip with fpu like F3/F4 can greatly improve the performance.

mxlemming   10 kW

10 kW
Posts: 866
Joined: Jul 17 2020 7:56am

Re: New ground-up ESC - MESC_FOC_ESC

Post by mxlemming » May 13 2022 8:50pm

https://www.youtube.com/watch?v=qFH7duzY3uM


Just ported MESC to F401CC. Been running in the Easy DIY ESC from Badgineer, Casainho, Andre. Nice piece of kit. Cute size, better ADC readings than the MESC board, but significantly down on power.

This is interesting, because 1) it can now be run from a blackpill, a 3$ breakout board and 2) it's the first time I have tried running FOC on a chip with a single ADC.

It runs fine. The single ADC doesn't really seem to impede the performance. No special conversion and sample positioning management, it just works regardless.

HFI not yet functional on the F401, I think the ADC conversions are not happening fast enough to fully populate the FOC buffers before it does the clark/park so the signal is a mess. One for another day.

Also re-implemented field weakening, Works pretty well, but needs a bit of tweaking to stabilise the id current. Thinking a hysteresis loop on the id request might work well.
Hold my beer while I divide by zero :flame:

flute2k3@hotmail.com   10 W

10 W
Posts: 82
Joined: Nov 26 2019 8:16pm

Re: New ground-up ESC - MESC_FOC_ESC

Post by flute2k3@hotmail.com » May 14 2022 5:55am

what is the HFI performance (I mean on your F303), I asked the same question to stancecoke before... can it work as good as hall sensor under load? any harsh noise for heavy load starting?
stancecoke wrote:
Feb 23 2022 6:58am
flute2k3@hotmail.com wrote:
Feb 23 2022 2:09am
what is your feeling for Lishui sensorless performance
The sensorless branch works for an EBike with a geared hubmotor and freewheel. The firmware has no ability to start the motor under load. The rider has to give the first push by the pedal first, so the wheel spins, then the rotor can start turning in open loop without load due to the freewheel. After the observer syncronized the commutation, the motor runs flawlessly. (with some limitation in max current and temperature)
For a direct drive without freewheel, the sensorless firmware is not suited and I don't plan to implement something like HFI to make the motor start sensorless under load

regards
stancecoke

mxlemming   10 kW

10 kW
Posts: 866
Joined: Jul 17 2020 7:56am

Re: New ground-up ESC - MESC_FOC_ESC

Post by mxlemming » May 14 2022 6:01am

flute2k3@hotmail.com wrote:
May 14 2022 5:55am
what is the HFI performance (I mean on your F303), I asked the same question to stancecoke before... can it work as good as hall sensor under load? any harsh noise for heavy load starting?
stancecoke wrote:
Feb 23 2022 6:58am
flute2k3@hotmail.com wrote:
Feb 23 2022 2:09am
what is your feeling for Lishui sensorless performance
The sensorless branch works for an EBike with a geared hubmotor and freewheel. The firmware has no ability to start the motor under load. The rider has to give the first push by the pedal first, so the wheel spins, then the rotor can start turning in open loop without load due to the freewheel. After the observer syncronized the commutation, the motor runs flawlessly. (with some limitation in max current and temperature)
For a direct drive without freewheel, the sensorless firmware is not suited and I don't plan to implement something like HFI to make the motor start sensorless under load

regards
stancecoke
So far the HFI is only tuned manually for the motors I have. It works brilliantly on my ebike motor the at12070 and on the big CA120.

I tried it on a hub and honestly it needed a lot of fiddling. It will work eventually but it's complicated.

Benjamin Vedder implemented my HFI method on VESC and it worked really well for him as well. He also implemented some method for setting the parameters which means it works with less effort on different motors.

I just need to catch up with the auto setting parameters.
Hold my beer while I divide by zero :flame:

flute2k3@hotmail.com   10 W

10 W
Posts: 82
Joined: Nov 26 2019 8:16pm

Re: New ground-up ESC - MESC_FOC_ESC

Post by flute2k3@hotmail.com » May 14 2022 6:26am

mxlemming wrote:
May 14 2022 6:01am
I just need to catch up with the auto setting parameters.
yep, if there is an autodetect algorithm suitable for generic motor application that will be perfect. looking forward to see your progress.

liminalsunset   1 µW

1 µW
Posts: 1
Joined: Apr 19 2022 5:52pm
Location: Vancouver, BC

Re: New ground-up ESC - MESC_FOC_ESC

Post by liminalsunset » May 19 2022 12:14am

Hi all -

This is going to be my first post here - have been lurking in this thread for some time and I've decided to build one of these MESCs to test out. I think it's a pretty approachable platform to work on! I like the validated power stage layout and I think it's one of the best open source ESCs currently available. Thank you, mxlemming for the excellent open source contribution!

I made a couple of changes to the board layout based on the original schematic v0.5. For now, my fork will be called SQESC because my board is more or less square, to differentiate it from the main version. This is in no way a promise that I will maintain this fork for any amount of time, but you are welcome to contact with questions etc. In my version, I decided to add the following changes and features:

1) It seems like the STM32F303CBT6 processor used in the design has hardware support for the CAN bus. Seeing as the USB code was recently removed from the software repository, I made the assumption this was no longer needed, and repurposed these pins for this purpose. I would like to use the CAN bus to connect multiple systems, such as BMS, taillight, display or dashboard controller/data recorder, cellular IoT module, etc in my intended application. I used the TJA1051T transceiver, which is available on JLCPCB assembly service. This is a little bit of an older transceiver, which consumes a few mA of quiescent current. As such, I added a P-Mosfet to shut the power to this chip down as needed. There are two pins on the CAN connector reserved for the termination, which is needed at the ends of the bus.

2) Some of the DC-DC converters on the board are no longer available. I changed the architecture of the power delivery on this board. First, the high voltage input will be stepped down to 12 V using the MPS MP9486A. This chip is widely available on AliExpress for a low cost and supports 170uA quiescent current. This 12V rail is used to derive 5V and 3.3V using the TPS54331 (x2), which also has a low quiescent current and is available on LCSC.

It is possible to back-power the board with an external 12V supply on CAN connector if the MP9486A is not installed or shut down. I didn't add a diode for Diode OR redundant power in this board, or as a way to shut down the on board converter. In my application, I will not use the on board 12V converter because the driver will be co-located with the "mid-chassis" controller hub, which will implement power cut off to the board externally in order to reduce the vampire power draw, as well as secondary power cutoff should the motor controller produce an overcurrent condition.

3) Some misc parts on the board have been replaced to better suit LCSC assembly. Due to some errors the first time ordering, some of the part selections don't match the footprints and this was manually resolved. I will try to resolve the problem in the BOM when I get some time. The three power rail LEDs are removed, as are some connectors used for presumably validation of the power layout. A "Heartbeat" LED connected to the MCU is added.

4) I changed the location of mounting holes. They are now M2 diameter, and I will make some corresponding aluminum core PCBs for both sides of the boards, to be attached with M2 round knurled standoffs and screws/insulating washers. The aluminum PCB itself has a very good isolation layer, so without any copper layer, there will be a 1500 Vrms isolation pad built in, and thermal paste can be used to attach the plate to the back side. The aluminum PCB can have holes freely added or drilled, to make mounting easier.

5) All of the connectors have been consolidated or rearranged into Hall, Digital IO, Analog IO, CAN Bus, Debug(2.54 header) JST PH 2.0MM connectors. The pinouts are not the same between the original and my version. The unused pin for the Hall connector is repurposed to connect a 10K thermistor internal to the motor. I considered whether it was worth trying to design this to multiplex multiple sensors over the hall inputs, but decided that should this be needed, one sensor plus some characterization and software modelling would be a better way to estimate the internal temperature or hot spots of the motor winding.

6) The layout of the PCB has been changed to about 87*84mm. This makes it "significantly" larger, which is acceptable in my application but might not be for yours. The purpose of this expansion is to allow for the new DC DC architecture, connectors, and CAN bus expansion. I re-routed the entire PCB with the exception of the power stage MOSFET/Power distribution layout. The layer stack up has been changed to use GND for the internal layers, with 95% of the routing on front and back. The sense resistor traces are run at 45 degree angles and/or away from the current path wherever possible. Many of the parts of the board have been spaced out more than in the original to facilitate easier automatic JLCPCB SMT assembly.

I ordered five boards for testing. The total without gate drivers, connectors, and MP9486A comes out to about 210 USD for five assembled boards. The cost of the STM32 processor used is about 10 USD now, as opposed to 2 in the documentation. When the testing is complete, I can imagine about 2-3 boards will be surplus and available to those interested.

When the boards arrive, I will do some testing. I hope to implement some extra features in the firmware if it is feasible, such as CAN bus and variable switching frequency (Not sure if it would be possible to do this - I want the switching frequency to be changeable while the motor is turning. For example, some applications prefer the motor to produce some harmonics noise at a low speed, or the inverse - a high frequency at low current, and decreased frequency when the current is high (motor noise is greater than switching noise and efficiency is more important)

I don't currently have a way to load test this other than a 350 W geared hub motor. I might try to output a simple 60 Hz sine wave and use two large 1500VA UPS step up transformers connected in Open Delta to connect three kettles or hair driers....

If you would like to check out the changes, the repo is at https://github.com/larryqiann/MESC_FOC_ ... -CANBus-IC. You need to check the branch corresponding to "change power supply, add canbus IC".

I do not recommend ordering it until I can test mine and find out how many thin(?) blue wires are needed to make it work...
I do not take responsibility for any action or result taken based on the design.

Some pictures of the layout:
Screen Shot 2022-05-18 at 9.58.53 PM.png
Screen Shot 2022-05-18 at 9.58.53 PM.png (534.8 KiB) Viewed 94 times
Screen Shot 2022-05-18 at 9.59.27 PM.png
Screen Shot 2022-05-18 at 9.59.27 PM.png (406.4 KiB) Viewed 94 times

User avatar
Lebowski   1 GW

1 GW
Posts: 3403
Joined: Jun 28 2011 1:38am
Location: beautiful Zurich, Switzerland

Re: New ground-up ESC - MESC_FOC_ESC

Post by Lebowski » May 19 2022 1:05am

mxlemming wrote:
Jan 23 2022 5:49pm

My concept (second concept) is as follows:
The basic idea behind the Lebowski controller is simpler:
- the phase of the voltage delivered to the motor (so the voltage at the output of the controller) must be equal to the phase of the current delivered by the controller. In this way positive power is delivered to the motor. What the motor does with this positive power, the controller does not care (but it makes the motor spin). This is basically Stator Oriented Control.
- A correction is applied to the imaginary part of the outputted voltage to account for the motor inductance. This effectively modifies the algorithm from SOC to FOC.

The controller knows its own outputted voltage, and measures the outputted current. Phase control is very easy, it calculates the imaginary (or blind) power and tries to keep this 0. No need to know motor resistance, inductance or BEMF for the SOC part of the algorithm. To make FOC you only need the motor inductance (you dont need the Kv or resistance).

mxlemming   10 kW

10 kW
Posts: 866
Joined: Jul 17 2020 7:56am

Re: New ground-up ESC - MESC_FOC_ESC

Post by mxlemming » May 19 2022 3:40am

liminalsunset wrote:
May 19 2022 12:14am
Hi all -

This is going to be my first post here - have been lurking in this thread for some time and I've decided to build one of these MESCs to test out. I think it's a pretty approachable platform to work on! I like the validated power stage layout and I think it's one of the best open source ESCs currently available. Thank you, mxlemming for the excellent open source contribution!
....
Very exciting to wake up to this! I hope it works as well for you as it has for me. I've had really good results from my 4 layer board with the f3 and TOLL FETs, and though I haven't used the ones with 2 layer and d2pak for a very long time, I recall they easily handled 50A and behaved well enough. I think my main recommendation (to late now?) Is that you should use 4 layer since the ground plane did wonders for the switching. Hopefully you did.

All your changes seem sensible, the semiconductor shortage is killing us all, and the price of stm32 is :confused: . The different DCDC is one I've been considering because of the fragility of the ti parts but I really don't need any more boards in my life right now!

USB... I removed it from the code base because it just never really worked properly on f3 (I had better luck with f4 and l4 but still not great). Endless enumeration problems and code hanging. One day I might revisit but for now I'm recommending the ch340 chips you can buy for very little money. I've never tried CAN atall.

I'm currently making a lot of code changes so the active branch is prototype. Sensorless is my default at the moment, I think hall sensors still work but I haven't used them for months. The other thing that's currently problematic is that my friend wrote a fairly complex layer for the profiles used and com port handling. This means the previously incredibly simple but working single letter command line is now... Obsolete... And replaced with the complicated one which isn't yet working properly. Will try to get on that. It seems like it will be pretty nice once it's integrated properly.

Lebowski wrote:
May 19 2022 1:05am
mxlemming wrote:
Jan 23 2022 5:49pm

My concept (second concept) is as follows:
The basic idea behind the Lebowski controller is simpler:
- the phase of the voltage delivered to the motor (so the voltage at the output of the controller) must be equal to the phase of the current delivered by the controller. In this way positive power is delivered to the motor. What the motor does with this positive power, the controller does not care (but it makes the motor spin). This is basically Stator Oriented Control.
One day I'll try to implement this. It makes perfect sense. I'm a long way down the FOC rabbit hole right now but I'm certainly feeling like FOC isn't the be all and end all of motor control.

One of the really nice things about the observer I created is that it requires absolutely no startup code, provided load torque is low and the resistance term is fairly close. How well does the Lebowski controller achieve initial phase lock?

I'll take this opportunity to say thanks for all your contributions to knowledge over the years. I've learnt a huge amount from your posts... And come to expect that in any sea of babble and discussion, the Lebowski post contains the objectively correct answer :lol:
Hold my beer while I divide by zero :flame:

Post Reply