# PID controller question

I came across this PID controller that drives a motor, which I understand well.

For my application, I need to drive a load in both direction (two electromagnets in series with poles opposed).

The feedback is provided by a hall sensor that indicates the position of a magnet. The setpoint is a voltage divider with a value of 2.5V which is the 0 of my hall sensor (0 to 5V output range). I don't have -12V available. The circuit of the bottom side would just do the contrary of the high side to reverse the current in the load. Would this proposition work ?

Thanks.

• Can you briefly explain your rationale of adding the extra OpAmp U5 controlled BJT switch, as a workaround of not using two PSUs? Feb 18 at 7:34
• What are your available power supply rails? What are the details of the Hall sensor? Can it be modified to work with a different offset and different gain than you suggest?
– jonk
Feb 18 at 7:39
• When the high side is pulled high, the bottom side would be pulled low and vice versa. I have a +12V and a +5V (LM7805 from +12V) for the hall sensor, which is a SS495A from Honeywell. Feb 18 at 7:44

No, you need to change your output stage from a single push-pull amplifier into an H-Bridge, supplying one side of it with the output of the PID controller and the other side with the inverted PID output (which you can make by putting it through an inverting op-amp of gain -1, with it's non-inverting input biased at half your supply voltage, which Im going to assume is 12V/2 = 6V). I see you've made the H-bridge already, but the signal for the 2nd side isn't coming from the right place. https://arduinodiy.files.wordpress.com/2013/08/brug.jpg

So, with what I described above, when your PID output is 6V, both sides of the H-Bridge will be 6V, the voltage across the load will be 0V. If your PID output is 4V, one side will be 4V, the inverted one will be 12-4=8V, 4V-8V = -4V across the load. However, the H-Bridge would work better with PWM instead, which you can convert the analog voltage into by comparing it with a high frequency triangle wave https://www.ti.com/lit/ug/slau508/slau508.pdf?ts=1645171678473

Another solution, which is the simplest is to set the non-inverting input of the lower U5 opamp to half your supply voltage, then you loose half the range, but you can drive the load in both directions

• Thank you for your answer. The output of the PID is the output of U5, right? I will try to simulate it. Why would the H-bridge work better with PWM? Can MOSFETs be better ? What happens if I remove the whole PID block and drive the H-bridge with the output of U1: it becomes a P controller with unity gain? Feb 18 at 13:53
• 1st question: Yes, the upper U5 (I updated my answer because I realized you had 2). 2nd: Switching supplies are more efficient and heat up less since they avoid the problem of power that gets lost in transistors that aren't fully on. And yes, MOSFETs and PWM is even better. 3rd: yes, it would be unity voltage gain, you want to be able to adjust it though motioncontroltips.com/…. Feb 19 at 19:52

The circuit of the bottom side would just do the contrary of the high side to reverse the current in the load. Would this proposition work ?

Are you sure? I don't see any similarities. No, it's not going to work, since you don't have the negative rail, the PID can't calculate the negative values.

• Is there a way to do it without a negative rail? Feb 18 at 7:50
• @Ultra67 For this circuit, IMO is not possible. However you could eliminate the D part and bias the all the +inputs to 2.5V, then the input range would be approx. 0-5V, 2.5V middle position. Feb 18 at 9:40