I'm working with a circuit which is regulating the current over a generic, proportional solenoid valve (L1 in the schematic below). The characteristics of the valve coil is unknown/will vary and the task of the application is to compensate for resistance/inductance variations in the coil caused by temperature changes etc, by means of a PID regulator. Currents are roughly between 200mA to 1A.

We are using high side current sense and a high side driver to achieve this. The current is obtained from a 5V 500Hz PWM signal, which controls a "smart" n-channel high side driver MOSFET. On-resistance shouldn't matter much since the task for the circuit is to compensate for resistance.

The driver uses a raw, non-regulated 24VDC from a vehicle to control the valve. The free wheel diode used is this one.

The high side current is measured over R1 with a high side current sense amp which gives its output as a current between 0 and 1mA. This current is in turn measured over the resistor R4 by the microcontroller, so that 1mA equals the maximum ADC value. (For various reasons ADC ref has to be lower than 5V - in this case it is obtained from an accurate voltage reference.)


simulate this circuit – Schematic created using CircuitLab

The PID regulator is implemented in software and works as it should, compensating for changes in resistance. It does however assume that the inputs and outputs are linear, so the current is only measured once per period, at a fixed point. We've tested that this works by connecting resistors in series with the valve. Everything works fine as long as the valve supply is kept constant.

However, when we change the supply voltage, the regulator will attempt to compensate, but we still notice a non-linear pattern in the output current, much higher than the <1% than can be expected from the LT6106. It can vary as much as 10-20% between 20V and 30V supply.

After much investigation, we came to the conclusion that this is because of some non-linear phenomenon in the coil. At the high-side, the PWM always looks pretty much like a digital square wave, so there's not much to tell from that.

But on the low-side, the curve looks very different depending on supply voltage. We managed to measure this by adding a shunt resistor on the low side, it looks something like this:

22VDC supply


30VDC supply


The above pictures are for the same output, but with the regulator trying to compensate for the change of current caused by the change of supply voltage, hence the different duty cycles.

I'm a software guy, so by no means an expert at electronics, let alone at magnetic fields in coils, please bear with me.

  • Q1: Is this a known phenomenon and is there a formula I can use in software to compensate for the non-linearity? It is possible for the MCU to measure the supply voltage if necessary.

    Since the current is measured on the high-side, everything looks fine there. I can calculate peak or average current, but that's of little use, since apparently the square wave looks nothing like the actual current flowing through the coil.

  • Q2: How much, if any, impact does the free wheel diode have on the output? Can I change the curve by picking another diode with a different forward voltage, adding series resistors etc?

General feedback on the design is also welcome - I know that the driver IC is obsolete.

  • \$\begingroup\$ Btw the high-side driver is used to reduce the amount of wires, as the valve is not necessarily located close to the PCB. Measuring the low-side current or putting any form of electronics after the coil would require an extra wire, which was what the design originally tried to avoid. \$\endgroup\$
    – Lundin
    Commented Nov 30, 2016 at 7:42

2 Answers 2

  1. The flyback current should be inside the current sense loop. This is a legitimate part of the solenoid current. Not measuring it gives bad input to the controller.
  2. Another source of non-linearity with respect to the supply voltage is due to the D1 voltage drop. This fixed voltage introduces a non-linear element since it doesn't scale with supply voltage. At higher supply voltage, the PWM off time will be less, so the diode on more, making even a larger difference.

    D1 should be a Schottky diode. These have about half the voltage drop of a normal silicon diode. The non-linearity will still be there, but less prominent.

  3. The FET switch makes no sense as shown. You don't want to drive the coil from a source follower, as you are doing now. The coil common mode voltage can float arbitrarily, so it makes more sense to use a low side switch between the coil and ground. This gives you real PWM, with the full supply voltage across the coil when the switch is on.
  4. A little feed-forward would probably help. Have the control loop compute a normalized PWM at a fixed supply voltage. Then do the divide using the actual measured supply voltage to determine the actual PWM duty cycle to load into the hardware. This removes supply voltage compensation from the control loop, which then sees a more consistent plant response. The control loop then just handles the little non-linearity that making the duty cycle inversely proportional to the supply voltage doesn't take care of.

    I did this with a proportional valve once that had to run from 8 to 20 V supply and it worked very well.

  5. 500 Hz seems very low for the PWM frequency. You want the solenoid current to not decay much during the PWM off time. Think of the solenoid current as the average DC with AC PWM ripple on it. Only the former moves the solenoid. The latter just causes wasted power and heating, and adds noise to your current measurement.
  6. The R3 and C1 filter don't make sense considering the 500 Hz PWM frequency you are using. You want to measure the average solenoid current, so the PWM frequency should be strongly attenuated. Your filter rolls off at 4.1 kHz, so isn't going to do much of anything to reduce the 500 Hz PWM ripple. A higher PWM frequency also helps with this.

    The only way that what you have would be acceptable is if you're sampling the current at well beyond 1 kHz rate and then doing significant filtering in the firmware. 1 kHz is the absolute minimum just to keep the PWM fundamental frequency from aliasing. However, the PWM signal will have significant harmonics, which is why you would need to sample significantly higher than 1 kHz to get a reasonable picture of the current.

    Again, use much faster PWM and much lower filter rolloff. Switching to a Schottky diode as already noted reduces the magnitude of the PWM frequency in the current signal. Even with all that, you may still need to sample at high speed, then digitally filter and decimate.

  • \$\begingroup\$ Thanks for your reply! Lots of things to consider. I'll start with the schottky as that's an easy thing to test on the existing design. Regarding the C1, it is actually just there because of noise we think originates from the "smart" driver's built-in regulator. It isn't there for the 500Hz - the current is measured at a fixed sample point on the positive duty cycle (though there is a moving average filter in the software, before the PID). I do believe that a higher frequency is needed indeed, the existing solution "lets go" of the current, letting it drop too much before the next duty cycle. \$\endgroup\$
    – Lundin
    Commented Nov 30, 2016 at 7:36

Don't expect a relay coil to act like a linear inductor. The relay coil will have an iron core, and when properly designed, it should saturate. The details of the saturation curve will be temperature dependent. This saturation is effect is called the B-H curve of the iron. An extra challenge is that the iron gets magnetized, and this causes hysteresis. To control nonlinear current with hysteresis in software, a Kalman filter should work better than a PID.

One way to think about this is that the relay is a linear motor, and the circuit needs to detect the motor position without directly measuring the position. The paper "Iron Hysteresis and Enhanced Kalman Filtering for Sensorless Position Detection of Synchronous Motors" is an example of someone else using the Kalman filter approach.

Kalman filters used to be more difficult to understand but now there are excellent tutorials such as "How a Kalman filter works, in pictures"

I agree with Olin that a low-side N-channel switch would be better. I would fix this before worrying about the other details.

  • \$\begingroup\$ While what you say is correct, note that the OP specifically said he's working with a proportional solenoid valve. In other words, the solenoid has been deliberately designed to not have the affects you talk about, at least from the outside of the box point of view. \$\endgroup\$ Commented Nov 29, 2016 at 17:54
  • \$\begingroup\$ I think these valves are still quite non-linear in both magnetics and how the inductance changes with displacement. I looked at Theory of Proportional Solenoids and Magnetic Force Calculation Using COMSOL Multiphysics at comsol.com/paper/download/83443/vogel_paper.pdf . Figure 11 in this paper shows a small linear range of force versus current. \$\endgroup\$ Commented Nov 30, 2016 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.