Typo in the drawing driver code docs

There seems to be a problem on this page:

I realized only after buying boards that that system shown can’t work for the purpose. You can’t practically use N-channel mosfets on the high side like that, from what I read. N-channel mosfets are turned on by a positive on the gate, relative to the drain. It has to be like 5 volts or something higher at the gate than at the drain. When the drain is connected directly to ground, this works fine.

But the motor is in between ground and the drain, as soon as the mosfet turns on, the voltage on the drain would get close to the positive supply voltage, because the voltage is reduced by however much the resistance the current has crossed divided by the total resistance. The resistance of the transistor would be very low and the coils of the motor at least 10 ohms, not even considering induction.

I don’t know how it even stays on at all, I guess it achieves an equilibrium where the resistance of the transistor is such that the voltage at the drain is just enough to only just keep the transistor partially on, in a state of undesireably high resistance but not extremely high and not extremely low. This obviously implies that the voltage drop across the motor is way less than the intended voltage, and the transistor will get hot, possibly too hot. I guess if the motor was held still and the system allowed to achieve equilibrium it would be supply voltage minus very approximately the 5 volts (which varies between transistors).

This definitely is not going to give a nice sine wave, it will totally mess up the voltage from the system.

My understanding is rudimentary, I apologize, and I know, but who else would get trapped by such a problem. I was about to chop up the boards I bought to extract the N-channel mosfets and rewire them for use on the high side (the board wiring confines them to use on the low side when they are as they come). Fortunately I realized this is not going to work before I sacrificed that time and money…


Please do not get frustrated. Could you please explain a little more about your problem? I don’t believe there is an error in the documentation. Where did you see that? It was a bit unclear from your explanation. Also, any schematics of what you are doing will help.


PS I re-read what you posted, I believe you confuse the sine wave with the on/off PWM modulation of the wave. The mosfets are only turned on or off, they do not work as traditional transistors, for example an audio amplifier, do. You build the sine wave by modulating the timing of the PWM on/off chopping of the voltage over time.

Did I clear your misunderstanding? There is a dramatic difference between a MOSFET and a traditional transistor like this one:


The audio transistors work in the middle ground between fully on and fully off. MOSFETs only work as on and off. If you try to drive a mosfet like an audio transistor it will literally explode and burn.

Please let me know if I misunderstood your understanding and what are you trying to acheive.

Also please don’t get hurt.

Thanks Valentine, I apologize if I sound upset. These are not good times for me in general, and partially because my open source erv project is not going well.

Mosfets will fail to turn fully on or off if they gates are not driven to the right voltage. They do have region where they do act as amplifiers, the bare transistors. When driving a motor, of course you want to keep it out of that range.

I understand the mosfets get turned on and off with a PWM signal, but the signal is then supposed to be filtered and smoothed, causing a good approximation of a sine wave for the current flow into the phases of the motor, as a result of the induction of the motor winding.

This is very important for FOC, is my understanding. The sine wave is the ideal way to drive the motor, giving the smoothest motion. It’s what gives a smoothly rotating magnetic field.

The assumption in the precomputed table for the PWM values is that the Mosfet turns fully on and off as described. I tried this with an L298 recently, and it couldn’t give a smooth waveform, I posted about that in the forum, if you are curious, search “jerky motion with arduino nano and l298”.

If one of the the mosfets isn’t fully on or off, it will change the relative amount of current flowing through any given phase at any given time a great deal. I observed this myself directly with the arduino and l298 setup, I put some potentiometers adjusted to 3 ohms in front of each winding so I could measure the current with an oscilloscope, and one of them got bumped slighly by accident, changing its resistance to 6 ohms. It caused the current waveform on the oscilloscope to get totally messed up, even more than it was before, and the motor to become even more jerky.

With some kind of closed loop system that monitored current flow and compensated the pwm at any given instance, this could perhaps be corrected for.

But the diagram shown in that page is not an acceptable way of driving a load with an N-channel mosfet for the reason I described. There are many resources that point this out. You have to have P channel mosfets on that side, unless you use a driver voltage which gives a higher voltage at the gate than the source voltage. Here for instance : design - Is it possible to build an H-Bridge with only N-MOSFETs (and these other components)? - Electrical Engineering Stack Exchange

I’m still trying to understand your problem. In summary, are you trying to build a half-bridge with two N-channel mosfets without a high side driver? How are you driving the mosfets?

It would help immensely if you post schematics or pictures.

You MUST use a high-side boot-strapped driver. There is no other way. By high side driver I mean, the voltage on the high side mosfet MUST be the motor power voltage plus at least 5 volts. So if you supply 12V for your motor, you MUST drive the sigh side mosfet with 17 volts. The low side you can drive with 5 volts. It’s basic physics (coulombs law).

That’s what I am saying. That is not shown in the schematic on the page I linked to. It just shows the pwm going in, straight to the mosfets. That can’t work. That’s what I was going off of when I decided to buy these driver boards, these ones https://www.amazon.ca/gp/product/B07YKFR72R/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1

I see. The page is an educational conceptual schematics, not even coming close to a blue-print for building a BLDC driver. Hardware design of BLDC drivers is completely out of scope here. This is only targeted at people to conceptually grasp the very basics.

Just buy a driver and bob’s your uncle.

Hey @Anthony_Douglas,

There are many BDLC drivers that use only N-channel mosfets, but yeah there is definitelly some mode logic in between the PWM signals and the mosfets themselves. If you look only the image itself it would not be obvious, I agree.
As Valentine said, these drawings are not schematics and they are there just to enable people to better understand what are different code parameters in the code. I have first put just a simple switch image but then in my drawing software I’ve found something that resembles a transistor so I’ve put it instead. I’ll change the draving to use a P-channel transistor.

The same as the voltage limits drawing shows the sine waves even though the real voltages will be square.

These schematics are in the part of the docs which is called writing the code and particularly the BLDC driver code. It is not there to guide the design of the driver in any way.

If you are designing your own driver using only the mosfets, check this link also. It might be helpful:

Now, I feel like we’ve started off on a wrong foot with you @Anthony_Douglas. I just want you to understand that the SimpleFOC is a community project. It is not a company and has no employees. Nobody works on this project full time or makes money on it. We are all working on it in our free time and because we like it.
SimpleFOClibrary is an arduino library, that being said it is not in any way a production software. It can be, and many people have used it already in their solutions, but it is on to you to make sure it fits.

So I understand that some parts of the SimpleFOC make you angry sometimes, it also gets me frustrated sometimes. Take a deep breath and continue, the answer is probably just around the corner. :smiley:
And just remember that even though the SimpleFOClibrary code and docs seem simple maybe or similar to different software library docs, whenever you include hardware into the equation (especially this large variety of different solutions) finding a balance for a particular use-case is never easy (especially when you are searching for cheap options).

So I am sure you will find your solution and probably using the SimpleFOC but to do so, I am afraid that there is no other way than to put some more days into it and also probably some more bucks.
We will try to support you on our side, as much as the time allows us.