Hello! I have a rather embarassing noob-question that arose when I googled how to control a MG90-servo. I checked the HeaterMeter schematics and how the servo is controlled. It didnt look intuitive to me, and different from most other solutions I've seen. Here is the part of the schematics that got me confused:
SERVO is a signal from an output pin, and is used to control a servo with +5V through SRVBST (with PWM).
I know very little about circuits and electronics (SW engineer). If I try to analyze it, when the SERVO-signal is HIGH, there is no voltage between the Gate and Source of the MOSFET (since both are 3V compared to GND), so the transistor is OFF. That means that the 5V power source has nowhere to go except through SRCBST, and it powers the servo that way.
If the SERVO-signal is LOW, there is a voltage difference between the Gate and Source (3V vs 0V), so the transistor is active. This means that current will flow from the 5V source, through the transistor (D->S) and back to the Arduino OUTPUT-pin!? Which, if an output-pin that's set to low is equivalent to GND, would prevent any current from the 5V source to reach the servo/SRVBST.
I've never seen stuff like this before, where you connect your control signal to the Source of a MOSFET and apply a constant voltage to the Gate. I've mostly seen examples where the GPIO-pin is used to control the Gate (together with a gate+pull-down resistor), or examples where the GPIO-pin controls a BJT which in turns controls a MOSFET.
So my two questions are:
Will a GPIO-pin configured to output act as GND when it's set to LOW/0?
Are my interpretation of how the circuit works correct?
Main question: Why would you do it this way?? Any advantages to the more intuitive approaches?
That circuit is basically a logic level translator. You are conctolling a servo that needs a 5V PWM signal with a 3.3V PWM signal
Are my interpretation of how the circuit works correct?
Yes
Will a GPIO-pin configured to output act as GND when it's set to LOW/0?
Not really. When configured as a output, a GPIO can outpt a logic HIGH level or a logic LOW level. A logic LOW will never quite be zero and the amount of current it can handle depends on the device. It not the same as a GND pin on an Arduino
I do understand that we want to control a 5V servo using 3V outputs, I was mostly confused about the design. I have a few follow-up questions, hope you don't mind
So even if an output pin set to LOW is not the same as GND, it's still okay to apply the 5V voltage to it, and the current will flow from the 5V source, through the resistor and the transistor, and into the IO-pin? And the resistance will be so low that no current will go to the servo?
What's the advantage of the design above, compared to for instance
Neither of those schematics would work.
The power to run the servo connects to the servo power wire and the ground wire.
Now when the MOSFET is off, you are cuting off power to the servo.
So even if an output pin set to LOW is not the same as GND, it's still okay to apply the 5V voltage to it, and the current will flow from the 5V source, through the resistor and the transistor, and into the IO-pin? And the resistance will be so low that no current will go to the servo?
You should never apply any voltage directly to an output pin.
In the translator circuit, when the servo signal is HIGH, the 5V is not connected to the I/O pin.
When it is LOW the 5V is connected through the 1K pullup resistor.
For the first part, why wouldn't they work? Assuming that the servo also has a steady 5V and GND connection, and the signal from those schematics is only used as a control signal (which is pulsed)?
Right, sorry, now I understand, after drawing it Thank you! So, to control a servo (assuming that it can't be controlled directly by the output-pin due to low voltage), the solution in my original question is the way to go?
Btw, in the original schematic, when the servo is powered from the 5V, will the pullup transistor have any negative effect? Since there will be a voltage drop before it reaches the servo?
Thank you! Does that matter, if it's inverted? I'm getting a bit confused again, and I don't know exactly how servos work.
When IN is low, the MOSFET is turned off, so PWM gets voltage. When IN is high, there is no voltage on PWM. Why is that a problem (assuming you just invert the IN-signal too)?
will the pullup transistor have any negative effect?
The servo power and the Servo PWM control signal are two different connections to the servo.
Many servos will work with 4.8V to 6V power and the control signal can still be 5V.
The SRVBST signal will connect to the servo PWM input, the current draw should be very very small so the voltage drop across the resistor will be negligible.
Thank you so much, for both answers, now it makes sense I guess the microcontroller doesn't support that, then? To output inverted pulses? And if it did, in that case, the design would work? Just for my own understanding
Inverting an output would be done in software and I don't know of any micro that couldn't do it.
If you can invert then it would work.
The circuit I provided does NOT do level translation, the IN signal must be 5V
I presented that circuit in order to show you why the circuits you suggested would not work.
You are right, if the micro generates 5V PWM signals then the circuits are not needed.
Considering UNO --
When I execute digitalWrite(8, LOW);, the logic level of DPin-8 is guaranteed not to go above 0.9 V. It will be within 0.0 V - 0.9 V. There will be flow of current from +5 V-point to 0.9 V-point. SRVBST-pin is effectively at logic LOW which will not generate turning torques for the Servo Motor.
Thank you! But the circuit you presented, if we ignore the inverted PWM, why wouldn't it work with a 3V IN-signal (and turn a 0V IN-signal into 5V for the servo control signal)? Just trying to learn and understand
Thank you! Out of curiosity, what happens in that case? Where do the power end up? Like, usually when something is connected to GND it will return to the power source, but in this case, both the DPIN and the 5V are power sources (although with a voltage difference).