PID Controller

PID controller question

Ask Question

Asked today

Active today

Viewed 159 times


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

pid motor

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 ?

pid modified





asked 18 hours ago


31922 silver badges1313 bronze badges

  • Can you briefly explain your rationale of adding the extra OpAmp U5 controlled BJT switch, as a workaround of not using two PSUs? – tlfong01 18 hours ago  
  • 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 17 hours ago
  • 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. – Ultra67 17 hours ago 

Add a comment

2 Answers



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 U5 to half your supply voltage, then you loose half the range, but you can drive the load in both directions



edited 17 hours ago

answered 17 hours ago


8633 bronze badges

 New contributor

  • 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? – Ultra67 11 hours ago

Add a comment


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.



answered 18 hours ago

Marko Buršič

22.8k22 gold badges1515 silver badges3030 bronze badges

  • Is there a way to do it without a negative rail? – Ultra67 17 hours ago
  • @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. – Marko Buršič 15 hours ago

Add a comment

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.