MCU controlled voltage  - Page 1
Forum section: electronics / projects

author: nerdyrcdriver
author_rank: Contributor
timestamp: June 28, 2018, 02:37:59 pm
content: Hi everyone,I am working on a project where I am controlling a solenoid with an Arduino. An SSR is used to handle the 24v to the solenoid. I am aware of the large negative voltage spike when the solenoid returns to the first state. Right now I am just using an SSR that is rated for a high enough DC voltage. Eventually, I will need to figure out a way to handle that spike without slowing down the solenoid (ranges 50-100 cycles per second).What I am working on now is trying to vary the voltage to the solenoid using the arduino to set it. This will not have to change on the fly. Basically when the system turns on, I would like to tell it what to set the voltage to and then it will stay that way.In my excitement of learning about digital pots, I chose a digital rheostat (MCP4162-502E/P) as the adjustable component in a circuit using an LM338 voltage regulator. However, in my excitement, I failed to notice that the rheostat is only capable of 2.5mA max and my R1 in the circuit was set to have 4.6mA going through the adjustment circuit. So I changed the value of R1 to 680 ohms from 270. Using the equations from the LM388 datasheet, this should allow 1.8mA of current. This will limit the maximum voltage I can adjust, but I wanted to see if it worked anyway.Vout = Vref*(1+(R2/R1)) + Iadj*(R2)Vout = 1.25*(1+(5k/680)) + 1.8mA*(5k)Vout = 10.44 + 9Vout = 19.44vI have a 24v supply voltage with plenty of current capacity. So 19v should be achievable. But, it maxes out around 6.22v well before the digital pot reaches its full resistance (I have the arduino running a slow sweep to adjust the rheostat).Somehow I don't have any pots anywhere near 5k (they are all much higher). So I have been playing with putting different resistors in place of the rheostat. The voltage regulator works as expected without issues.What are my options here? Is there a better way of doing this? Are there digital pots/rheostats that can handle higher current? I need the arduino to control it, so having a regular pot won't work. While the SSR that I am using can pass a PWM signal reasonably well, the solenoid does not respond well to using PWM to change the average voltage.LM338 Datasheet Equations see pages 11-12http://www.ti.com/lit/ds/symlink/lm338.pdfThe basic circuit is shown below. There are other sensors and inputs to the arduino, but they do not concern this part of the circuit. I have switched it so the POB is connected to ground and POW (wiper) is connected to the adjustment. The drawing does not show the changed R1 value.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 28, 2018, 02:58:17 pm
content: I think I would drive the solenoid with a MOSFET and use PWM instead of using a relay and an adjustable voltage source.

author: nerdyrcdriver
author_rank: Contributor
timestamp: June 28, 2018, 05:23:20 pm
content: As nice and simple as that would be, I have tried it before and the Solenoid did not work well with PWM at the speeds I need the solenoid to cycle.Post number 4 in this thread brings up the idea of using an RC filter to bring the PWM signal closer to a regular DC voltage. This might work, but I need to find the correct components to use. The solenoid will draw an average of 2ish amps at 24v, but can peak around 5 if it is physically sitting too close to what it is hitting. Eventually, I would like to detect when it does this using the arduino and have it turn the solenoid off automatically.Edit:Forgot linkhttp://www.picbasic.co.uk/forum/showthread.php?t=15529

author: ajb
author_rank: Super Contributor
timestamp: June 28, 2018, 05:38:52 pm
content: Most digital pots are designed such that the voltage on any terminal is not permitted to be outside of its supply voltage range. From page three of the MCP4162 datasheet:QuoteTo get 19V the voltage at P0B would have to be ~17V! So that's why you're not seeing the adjustment range you expect.Depending on the power requirements of your solenoid and the desired voltage, a linear regulator may not be the best choice. Using a transistor to drive the solenoid via PWM would definitely be simpler, and you can control the amount of power applied to the solenoid by controlling the PWM duty cycle.If you are concerned with the actuation speed of the solenoid, then you probably want peak-and-hold drive to turn it on, and fast decay to turn it off.Peak-and-hold can be done easily with PWM, you simply set a higher PWM duty cycle when you first turn the solenoid on (peak), then after some period of time drop to a lower duty cycle (hold). That gives you maximum pull-in force and helps overcome the solenoid's inductance (you can sometimes even use a higher supply voltage than the solenoid is rated for at steady state), but limits power dissipation while the solenoid is held in position and reduces the amount of energy stored in the coil that you will need to extract to release the solenoid.Fast decay means allowing the reverse voltage on the coil to go as high as possible to allow the current to drop quickly. You can do this using an RC network, a TVS diode, or a full bridge driver. Using a simple reverse bias diode across solenoid means that when the solenoid is turned off, the voltage across the coil is quite low, which means not much power is dissipated, so it takes a while for the energy in the coil to be dissipated. If you use a full bridge, you can allow the voltage across the solenoid to completely reverse and quickly dump the coil energy back into the supply.Attached is a basic semi-full-bridge mixed decay driver. Q2, R1, R2, and D1 simply form a level shifter for the P-channel MOSFET Q1B and for high power applications could be replaced with a proper high-side switch driver. R3 and R4 simply serve to guarantee that the bridge is off if the inputs are not driven.When Decay Mode is high and PWM is high, current flows through Q1B, through the coil, and through Q1A. When Decay Mode is high and PWM is low, current recirculates through Q1B, through the coil, and through D2. This is ideal for the "hold" portion of the driving cycle. When Decay Mode is low and PWM is low, current flows through D3, through the coil, and through D2 until most of the energy in the coil is dissipated. Because the voltage across the coil is equal and opposite to the supply voltage, energy is dissipated quite rapidly giving a fast release.EDIT: You might also be able to find a motor driver IC that you can use to implement mixed-decay control in a single part, but IME it can be hard to find suitable ICs for >12V and at modest currents (so much of the market is aimed at automotive use).

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 28, 2018, 07:58:44 pm
content: Quote from: nerdyrcdriver on June 28, 2018, 05:23:20 pmI see. If you want to cycle it a high frequencies, you would need a much greater PWM frequency, which may lead to huge losses in the solenoid, basically rendering it useless. Maybe that's what you ran into?

author: nerdyrcdriver
author_rank: Contributor
timestamp: June 28, 2018, 08:33:33 pm
content: Maybe. The solenoid speed is controlled, but generally runs around 50-100 cycles per second depending on some mechanical variables and a delay that I set in the code. A cycle is defined as the solenoid going from the top resting position, to the bottom, and back up to the top resting position. Turning on and off the power to the solenoid essentially is a square wave and the cycles per second is determined by the period of pulses.I did have some code written to PWM the output, which in theory would make the output to the solenoid look something like the attached image if the duty cycle were set to 50% (and a very low PWM frequency). The arduino PWM is default set to just under 500Hz on most pins, with two of them capable of just under 1kHz. The measurements I made with the scope had the PWM frequency around 500Hz, so I must have been using one of the lower frequency pins. It turns out that the frequency can be set relatively easily. I suppose I could turn it way up for a specific pin and see what happens. That wouldn't require any additional circuitry.

author: nerdyrcdriver
author_rank: Contributor
timestamp: June 28, 2018, 08:47:23 pm
content: Quote from: ajb on June 28, 2018, 05:38:52 pmWow, I missed to very important parameters on the datasheet. I saw them one day, and then found what I thought would be a good use for them.A linear regulator was chosen based on the solenoids previously poor response to PWM testing. I for such a low price, I figured I would just skip switching regulators to avoid the same issues. However, as my last post states, I just learned that it is easy to greatly increase the pwm frequency on an arduino. So that might help.Otherwise, your circuit looks like a great place to start! I will have to spec out and order some components for it (which it turns out i'm not so good at).

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 29, 2018, 01:01:41 am
content: Ok so, looks like your problem was not too high a PWM freq, but much too low.Ideally, and if the characteristics of the solenoid allows this without too much loss, I would go for a freq slightly above the audio range (> 20 kHz) so as to avoid any annoying whining noise. If it's in the kHz range, you will most likely hear a whining noise. You'll see, you'll have to try for yourself.I have no clue about the limitations of the Arduino, but in any case, I would go for a PWM frequency greater than at least 10 times the solenoid's max activation frequency. So in your case 1 kHz seems like a bare minimum to me, unfortunately, but it may work (although maybe with a limited dynamic range). You will most likely hear a noise though. Keep us posted!

author: CopperCone
author_rank: Super Contributor
timestamp: June 29, 2018, 01:18:00 am
content: if you mod into a voltage regulator consider the failure modes. I have kinda started this before but I never finished my analysis.You can directly tie into it with a current source (well ghetto one made of a resistor connected to a DAC), or bias it with a voltage divider at some impedance and then inject current into it, or do something more elaborate like a summing amplifier. How to load connects back to your MCU PWM or DAC is different.Not sure if it can do something stupid on startup if a pin is floating, intermittant or whatever, particular with DC DC converters. I believe a certain webpage said you should bias it to ground then use your DAC/PWM as a trim factor rather then just adjust setpoint with PWM, but it was sparse on details. Don't feel like researching it now. Would like to hear other peoples analysis though, most people don't care because it seems to work ok in most situations.

author: nerdyrcdriver
author_rank: Contributor
timestamp: June 29, 2018, 03:22:15 am
content: Quote from: SiliconWizard on June 29, 2018, 01:01:41 amWill do. I look forward to trying it in the lab tomorrow. This might be further complicated because I am ultimately using a custom board with an 1248P instead of a normal arduino. But I can just switch back to an Uno for this testing and figure out what registers I need to play with on the 1248p if it works well on the uno first.The SSR I am currently using costs $70, luckily I found it in a random parts bin in the lab. But if I ever want to duplicate this project, which is fairly likely, I don't want to spend that much on whatever drives the solenoid. Are MOSFETs suitable for this application? Would they be able to handle the voltage spike caused by the release of the field? (approx 120vdc pk-pk for about 2ms per cycle). Typical current draw around 2 amps, with peaks near 5. A system will be in place to detect the situation that causes the higher current draw and turn off the solenoid.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 29, 2018, 02:28:09 pm
content: Quote from: nerdyrcdriver on June 29, 2018, 03:22:15 amSure. Just select an appropriate MOSFET (I would go for something like VDS > 50 V, ID > 5 A to be safe, like the IRFR120Z for instance), and don't forget to add a freewheeling (also called flyback) diode across the solenoid (which will take care of the spike when the transistor switches off), or you'll kill the transistor in no time! Seehttps://en.wikipedia.org/wiki/Flyback_diode

author: nerdyrcdriver
author_rank: Contributor
timestamp: June 29, 2018, 04:08:48 pm
content: Quote from: SiliconWizard on June 29, 2018, 02:28:09 pmI was able to get regular old PWM on the arduino to work great! The difference was the mechanical load that I had on the solenoid. Before it had a lot of load, so lowering the pwm duty cycle would make it too weak. But now that it has a lighter load, I have a pretty good adjustment between 200 and 255.Good to hear about the MOSFET. I have used a diode in the past and it slowed the solenoid down a lot, which would make it too slow for my use. However, that was with a much different mechanical setup which changed how the solenoid could move (thus changing how the rod moves past the wire core and the properties of the voltage spike). So, I might get away with it now. What parameters would I have to look at to choose a suitable diode?Thanks for the help so far!

author: nerdyrcdriver
author_rank: Contributor
timestamp: June 29, 2018, 06:11:20 pm
content: So after looking for mosfets, I think that I found a suitable one. But since I missed a few important parameters on the last component I picked out (digital rheostat), I would appreciate another set of eyes on the datasheet before I place an order. I chose the 220 package because I have heat sinks lying around that I would like to use on the mosfets if necessary.IRL510PBFhttps://www.mouser.com/ProductDetail/Vishay-Siliconix/IRL510PBF?qs=sGAEpiMZZMshyDBzk1%2fWi1F3z9PgzPBnDetAusVMMI8%3dAlso, I found the attached sample circuit. It looks like the mosfet listed above already has the diode labeled as D1 built in. I am driving a solenoid not a motor, but it is an inductive load none the less. What parameters should I look for when choosing diodes for the snubber or clamping circuit?

author: ajb
author_rank: Super Contributor
timestamp: June 29, 2018, 06:39:49 pm
content: The diode shown is an inherent feature of the way the MOSFET is constructed. The good news is that this body diode often this means that no external diode is needed. If you look at the datasheet, you'll note that there is a section that describes the body diode's characteristics. Note that it has a similar continuous current rating to that of the transistor, so that's good.However, you mentioned that you have peaks up to 5A, which is awfully close to the absolute maximum rating of the transistor. Never plan on extended operation near the abs. max ratings of any part!You will need to review the Safe Operating Area of the transistor (figure 8, page 4) and insure that you stay well within the relevant dotted area. Note that for switching operation VDSis determined by RDS(on), which is a function of VGS(and other things), and is often spec'ed as VGS=10V. So if you are driving the transistor from a 5V logic output you may not get the performance that the headline of the datasheet would lead you to expect.Also, MOSFET maximum current ratings are often made assuming a perfect, infinite heatsink, so in order to determine a more realistic rating you will need to look at the power dissipated by the MOSFET and its thermal resistance, since that will determine the operating temperature, which will be one of your limiting factors. Without knowing the nature of your 5A pulses, I would recommend that you start by filtering for MOSFETS with ID> 8A, and then dig into the datasheet to verify that your operating conditions are well within its specifications.

author: nerdyrcdriver
author_rank: Contributor
timestamp: June 29, 2018, 07:56:46 pm
content: Quote from: ajb on June 29, 2018, 06:39:49 pmNormal operating conditions will run around 2 amps. But if you go outside of the ideal operating conditions, the solenoid can stall and pull about 5 amps. There will be a circuit detecting this and turning it off within a second or so. But I could definitely go to a higher rating to be on the safe side.If I am reading the datasheet to the mosfet that I posted correctly, the specified Vgs in the product summary and features at the top of page 1 is 5vdc. The absolute maximum ratings section shows Vgs (max) as 10v.Or am I missing something there?If I am reading the Vgs spec (not the absolute max) correctly, then this should be rated for more than enough current. Though the current rating is higher, the total power is still around 60 watts.https://www.mouser.com/ProductDetail/Vishay-Siliconix/IRL520PBF?qs=sGAEpiMZZMshyDBzk1%2fWi1F3z9PgzPBnlTjNiUoCftk%3d

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 29, 2018, 09:40:17 pm
content: Quote from: nerdyrcdriver on June 29, 2018, 06:11:20 pmI'd suggest going for an IRL520 instead, with a higher continuous ID and lower RDSon @5V.Be aware that with a continuous current of 2 A (to get an idea, it may be less in practice) and a RDSon of 0.27 ohm, it's going to dissipate more than 1 W. It will get warm. You should probably add a (small should be enough) heatsink.The body diode of a MOSFET certainly isn't going to replace a freewheeling diode, which again should be across (in parallel) the inductive load, not across the transistor itself.You shoud use a diode such as the 1N4007 which should be fine for your application.

author: nerdyrcdriver
author_rank: Contributor
timestamp: June 30, 2018, 12:06:11 am
content: Quote from: SiliconWizard on June 29, 2018, 09:40:17 pmAwesome! I will get the parts ordered and hopefully get the circuit built in the next week or so. In the mean time, I have a lot of other stuff I can do for the project. But it is mostly mechanical stuff.

author: nerdyrcdriver
author_rank: Contributor
timestamp: July 11, 2018, 02:09:59 pm
content: Ok, my parts finally came in. I think that is the longest I have had to wait for a package from Allied. I must have ordered something that was back ordered or something.I built the circuit and it works great! Except the flyback diode across the solenoid. It slows down the solenoid far too much for my use. Would a snubber circuit dissipate that voltage spike faster?I have run some torture tests on the circuit and the mosfet maxed out around 125F using a medium heat sink (had it already) and 95F with the addition of the small fan.I am concerned about reliability for the mosfet with that voltage spike though. It works great right now, but who knows what long term reliability will be like. The mosfet is switching the negative to the solenoid. The spike is about -100V with respect to ground level.

author: ajb
author_rank: Super Contributor
timestamp: July 11, 2018, 05:29:29 pm
content: Quote from: nerdyrcdriver on July 11, 2018, 02:09:59 pmYes, the rate at which the energy stored in the solenoid is dissipated depends on the voltage across the coil during the decay cycle. If you have 5A running through the coil and a diode clamps the decay voltage to -0.5V, then you're initially dissipating only 2.5W. But if you clamp the decay voltage to, say, -24V, the initial power dissipation is 120W. The power drops rapidly as the coil energy is dissipated, but it drops much faster in the latter case--either way the total energy dissipated per cycle is the same, as it depends on the coil inductance and current (Energy = (IL2)/2. You can use an RC snubber, a TVS diode, or a mixed decay circuit such as the one I posted earlier. Actually if you use the TVS or mixed decay approach you'll probably want a small snubber as well to help take the edge off.Note that stored energy is related to the square of the current, so if you can reduce the hold current you will substantially reduce the stored energy and therefore the amount of energy that will need to be dissipated.QuoteYou should be concerned, but be careful, there are number of measurement traps here. How exactly are you measuring that? Transients like this must be measured using a short ground spring as opposed to the typical flying lead on a scope probe, and care must be taken regarding where the probing is done. It's very easy to get an inaccurate picture of the situation through improper probing and wind up heading off in the wrong direction.

author: nerdyrcdriver
author_rank: Contributor
timestamp: July 11, 2018, 08:40:14 pm
content: Quote from: ajb on July 11, 2018, 05:29:29 pmAfter making some mechanical changes, normal operating currents are around 600mA. There is not a situation where I can make the solenoid stall and draw 5 amps like there was before, though it can still spike to around 1 amp in certain circumstances.As far as measuring it goes, there are only normal scope probes in the lab. I am measuring directly across the solenoid with the alligator clamp on the negative side (scope rated for 300V).What parameters are important to look for when choosing a TVS diode? Any useful resources for designing a snubber for use with a TVS diode?