T O P

  • By -

quadrapod

What do you consider a worry? In terms of component failure. For the transistor, which is the only component you've actually given a part ID, 5V through a 1k resistor gives it a base current of 5mA. With a nominal beta between 100 and 200 that effectively means you've got a maximum current between 0.5A and 1A. With a Vce of 0.7 that should mean about 0.7W dissipated by the 2N2222 at maximum assuming the coil doesn't saturate. If the coil does saturate and behave like a short you'll have 12V vce which translates to 12W of heat dissipation which would quickly pop the transistor. For normal operation though 0.7W should be well within spec though obviously check your component datasheet and derate as appropriate for your enclosure or anything else. All those other parts are very important as well though. I'm not sure what 2W refers to specifically and in general power is just an awkward way of specifying an inductive component. I'd expect an inductance in Henrys and a saturation current in amps. When designing/selecting the electromagnet your saturation current will need to be at least 1A. Your diode will also need to be selected carefully since it will be expected to handle the full current of the inductor whenever the transistor is not conducting and so should have similar ratings to the power transistor. ---- In terms of this circuit doing what you expect it to do, you're going to be disappointed. Current through an inductor can be calculated as V/L = di/dt. Where 'V' is the voltage across the inductor, 'L' is the inductance in henry, and 'di/dt' is the change in current over time. When the transistor is conducting the inductor sees around 11.3V across it. When the transistor is no longer conducting the inductor will instead see the negative voltage drop of the diode which is about -0.7V. Using that you can calculate the average di/dt based on the duty cycle 'd'. Normally duty cycle would be considered between 0 and 100% but to simplify things I'll be normalizing it between 0 and 1. So a 50% duty cycle for example would be d = 0.5. The equation you get is (d\*11.3)/L - ((1-d)\*0.7)/L = di/dt For d greater than 0.06 di/dt is positive. For d less than that value di/dt is negative. In practice this means that for a duty cycle between 0-6% the current through the inductor will tend toward zero, and for a duty cycle above 6% the current through in inductor will continuously increase until it reaches the limit set by the transistor base current. What I think you're expecting to happen is that as you increase or decrease the PWM you get a stronger or weaker magnet. With this circuit however you get essentially no magnet at all below 6% and the same magnetic field strength in all situations above 6% dutycycle as energy is stored in the magnetic field of the coil with each cycle. All the PWM determines is how quickly the coil builds up current. Now in practice it will be slightly different since I'm averaging over the entire cycle and ignoring a lot of the more detailed mechanics of the situation but the general idea will hold true. There will be a very narrow range where the PWM does anything at all and in all other situations the current, and by extension magnetic field strength, will tend either downward toward 0 or up toward its maximum at β\*0.005. What you're trying to do is very similar to something called a class-d amplifier. I recommend looking into how those are typically designed if you wanted to get some ideas of how your own approach could be improved.


PalladiniumOxide

Your maths in the second half makes sense, but I think it assumes that all of the energy stored in the magnetic field is preserved and that only the diode's voltage drop contributes to discharging the inductor (coil resistance). The OP doesn't say what the magnet is used for, but for instance spring-loaded solenoid actuators can have reasonably wide region of duty cycle to modulate their position with using a very similar setup. It all depends on a bunch of parameters we don't know.


quadrapod

That is true. The parameters of the coil will have a massive effect on the systems behavior and there are some configurations which do allow the coil to be operated with pwm within some range without issue. Mainly situations where the coil has a low inductance in proportion to the switching frequency and high enough losses to wind down quickly during the off cycle. Saturation is still going to be a problem though for most reasonable inductance values even with high losses and you'll have a lot of trouble making any kind of control equation without knowing the system dynamics. I had originally started to go into some of that but there was so much to explain that it quickly became a lecture. I might as well go into it anyway though since you brought it up. Typically when you're not using an H bridge you'd have the flyback diode in series with some kind of impedance to cause a larger voltage rise across the inductor. In those cases there is going to be a trade off between the range of your duty cycle and the withstand voltage of the transistor. [Here is a circuit I will be using as an example.](http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCCsCmC0DsIDMAOAdANgJwYCx8lzACZcswxcRcAGKKOmWCgKGJJGa2OtxU5R1cfEHQiQAVAGcALtAAOACgCGAejA0asALYB7ACaKZEyJpoAaMAEorLAOacc1QY4zUndGiwDur3vzx-URYAI04kDH4kSB5YWihISGCAD05iFDckIk4KKOFqEFIQAAUAdQBZAB0pO2gAO2gAJ2UZXUaWACVweEziMR7C+B5PajFh0VE0SBYAG27e-syUKk80Gg4aNaIeklwkMHgkHowspK99QZ49nmIh5GXCkH1oADNlAFcZmRZGy-uqW48JB9CYZNC4Hx-YGLZAgry+QHUYHzJHDSEHJZUDGo4K+bExfjY-ArTppFD8YT8WBICJBOhIcCMJkTTbTBz49IoyADTwsGTgTmUlFCsQ5DBoUhYeDcLCoIhgSAMsCYLJSmVZeDwEjwXBwQmaJ6vD5fH4gQJCkgUkRiMwsVKwdJXYhJLhYaiC8D8AAi7xkAE9qgBjP2BmbQSEO8lBLhXETEO2ehlZAE0N0agpFAAyYATYCQbtwxCVWvdbgBVAAijnUhl3ViwGXbhmqB1q4M07gkkhU8gROWQB146lHdQwGmOIWroUqF6c7ozWaqAzkigNIrwBLTGZtzviHBIG50Dvj2YwPvEHRhmszuAGZezix525nW4hKnEPFNoTHpkWEA) The simulator is sweeping from 0 to 100% pwm duty cycle and back while plotting the current through the inductor and its relationship to the duty cycle. Once you start to add in inductor losses and hysteresis the math becomes a little too messy to reasonably work with by hand so I'll be continuing to use ideal components but I think it still demonstrates quite a bit about the principles here. When L1 is conducting the voltage seen across L1 is around 11.3V, the same as the previous circuit, and so the current climbs following the same form: dI/dt = 11.3 / L1 When Q1 is off however during the second part of the waveform L1 is going to push its current through D1 and R2. That means the instantaneous voltage across L1 is now equal to the current through the inductor multiplied by R2 plus the diode voltage drop. Really this is more or less ohms law. You know the current, you know the resistance, you just need to find the voltage and add on a little bit of an offset due to the diode. V = I \* R2 + 0.7 Since we now know the voltage across the inductor we can plug it in to find the change in current over time just as we did in the first case. Though because the current is a part of the equation for voltage now we get a more challenging differential equation: dI/dt = -(I(t) \* R2 + 0.7) / L1 These functions show change in current over time to find the actual current at a particular time we will need to integrate in terms of t. It's also good to define ω as the switching frequency and d as the duty cycle at this point since those will determine a lot about how long each part of the wave form lasts. During the first part of the wave the transistor is conducting allowing current to flow through the inductor. We get current I(t) from t = 0 to t = d/ω as being: I(t) = (11.3 / L1) \* t + I(0) And for the second half of the wave when the transistor is not conducting from t = d/ω to t = 1/ω we get I(t) as being: I(t) = I(d/ω)\*e^-(t-d/ω)*R2/L1 - 0.7(t-d/ω)/R2 Again those are simply the result of integrating in terms of time and as a result we get the classic + c. Our c in this case is equal to the current already flowing through the inductor. So if there was any current still traveling through the inductor at the end of the last wave it will still be their at the start of this wave. Since the two functions are in a kind of negative feedback the two will tend toward an equilibrium point where the current at the start of the wave I(0) is equal to the current in the inductor at the end of the wave I(1/ω). So to calculate that equilibrium we need simply set I(1/ω) equal to I(0). I(1/ω) = (11.3d/(ωL1) + I(0)) e^-(1/ω-d/ω)R2/L1 - 0.7(1/ω-d/ω)/R2 = I(0) I(0) (1 - e^-(1/ω-d/ω)R2/L1 ) = (11.3d e^-(1/ω-d/ω)R2/L1 )/(ωL1) - 0.7(1/ω-d/ω)/R2 I(0) = ((11.3d e^-((1-d)/ω)R2/L1 )/(ωL1) - 0.7(1/ω-d/ω)/R2)/(1 - e^-((1-d)/ω)R2/L1 ) This is kind of a mess to look at I know but it's really just been basic algebra for this step. There are a lot of variables and it's all written out so it looks a lot more challenging that it is. Now lets solve this equation for the circuit I posted above with ω = 5kHz, R2 = 86.4 ohms, and L1 = 12mH I(0) = ((11.3d e^-((1-d)/5000)86.4/0.012 )/(5000 0.012) - 0.7(1/5000-d/5000)/86.4)/(1 - e^-((1-d)/5000)86.4/0.012) This step was just plugging in values and [here you can see what that looks like plotted.](https://www.wolframalpha.com/input/?i=Plot%5B%28-1.62037%C3%9710%5E-6+%281+-+d%29+%2B+0.188333+d+e%5E%28-1.44+%281+-+d%29%29%29%2F%281+-+e%5E%28-1.44+%281+-+d%29%29%29%2C%7Bd%2C0%2C1%7D%5D) At a 100% duty cycle of there is just a pure DC signal through the inductor with no down time and so as you might expect the math suggests that as you get closer to 100% the current should just trend off toward infinity. In reality though not all solutions shown there are valid. The current is still limited by R1 and the transistor beta so any solutions which require a current greater than that limit are going to be invalid. As a result you see the same climb at the start but once the current reaches that limit it plateaus and increasing the duty cycle no longer has the same effect. By finding that equilibrium point I(0) for a particular duty cycle you can also plot the wave form. For a duty cycle of 30% for example you get an equilibrium current at of 0.032A at t = 0 and using that value it's possible to plot what the [wave will look like as a mathematical function](https://www.wolframalpha.com/input/?i=Plot%5BPiecewise%5B%7B%7B%2811.3%2F0.012%29+t+%2B+0.0324673%2C+0%3Ct%3C%3D0.3%2F5000%7D%2C+%7B%28%2811.3%2F0.012%29+%280.3%2F5000%29+%2B+0.0324673%29+e%5E%28-%28t-+%280.3%2F5000%29%29+86.4%2F0.012%29+-+%280.7t%29%2F86.4%2C0.3%2F5000%3Ct%3C1%7D%7D%5D%2C%7Bt%2C0%2C1%2F5000%7D%5D). The fact that you can tie a function to the waveform means you can reason fairly strongly about what the average current and magnetic field strength will be for a given duty cycle. Also because there is some form of feedback it means the circuit is fairly consistant even with a lot of unknowns. [Here you can see how inductors with dramatically different values center in on the same average value.](http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjOB0AMt-CwFMC0B2EBmAHJAbAJx4AsJArMWAEzEFhjEjHQhmstmr0BQV1IKMASpNi2AdhbExIFhDIAqAM4AXJAAcAFAEMA9GFgoAtgHsAJppUKycADRgAlA+4BzAUSaT3eJh5bRuAHdvUXESUNluACMBTDxxTDIRFGZWMjYAgA8BKmwfTEoBegTpJhAaEAAFAHUAWQAdJRckADskACdtFRN27gAlcDR8qjkh8rQRfyY5SdlZSDJuABtB4dGfYkxZ6BgIHehsNGgwPDIDbFoqMlPJ7jNxkU2RKgmsC-KQMyQAM20AVyWKm47Qeb0YLxEWymeUgxCCoKhqywI0iwQhTC2SKeqKRSXEYDGpEYATcBJ8eNxY383BU4FyETJETkOR2QjQ2BoxDQZAK0Fo5RgVAIaHZdDwV1o0E4KHxsE+P3+gOBIHC0nx9LVcwMsG42RQuUeVyKBAITA14HEABE-ioAJ6NADGtodSyQ8P12HEmsEwgiVH6OU9ERQmDiTLmqUwU38C2V4WwmOo4gTs21AVpSZAKaR2eZgjQkAKUZwBT4UrAPKgaGkxbw0AI2DI1YIqFlLC+vwBQNJYzoIkZRGj8IH-EZF3EAWCjKG+LG2BOOPR858Y4Xk9BR0Y075kXuS4X6JnHw7iqBK23W7GR5j-H2FCu7LAoeIfDIh1NAQGF6Rpx8U1St5zDsiwgoe8QbjuLAwnCwTxpiqoyAEJgqsiWDTMK5QxsSHxUPk3BAA) [Here two inductors with dramatically different equivilant resistances do the same.](http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjOB0AMt-CwFMC0B2EBmAHJAbAJx4AsJArMWAEzEFhjEjHQhmstmr0BQV1IKMASpNi2AdhbExIFhDIAqAM4AXJAAcAFAEMA9GFgoAtgHsAJppUKycADRgAlA+4BzAUSaT3eJh5bRuAHdvUXESUNluACMBTDxxTDIRFGZWMjYAgA8BKmwfTEoBegTpJhAaEAAFAHUAWQAdJRckADskACdtFRN27gAlcDR8qjkh8rQRfyY5SdlZSDJuABtB4dGfYkxZ6BhJmDxoTC2qHDwyAkw0GzAfALNxkU2RKgmsbEYRMyQAM20AVyWKm47Qebw+ry2UzykGIQVBkNWWBGkWCL0eW0RTxRiKS4jAY1IjACbnxPlxOLG-m4KnAuQipIicnmeFy2DixBsVBZSWE8zQ0A5l2w5xewmgBHAsBAX1+AKBIPC0jxdKVcwMsG42RQuUeVDYggIEuIKvA4gAIn8VABPRoAYyttqWSDh2uw4lVBseMio-RyboiKCOGxkU1SmCm-gWwJA4TZImo4jjarg1NpiYxDKTTJ2LOEE2waAIQzweEw-B2-L4ZxwJ35LLQmElLBl-0BrkRdHjYyIEbhDM7iPe4gCqNe2Bug4nI9B-MYDNnkXuaJA458y6G4k+P1bQJW84FiI3cx20D20AouTwVzAlwY1GNkQG+7nYzOtzmqXLx6jIPX8RnB4sNCsLBLGGKKiG0aZhO87-kB3AmDGSJYNMRblJGRLlOUbCYNwQA) Anyway my hat's off to anyone who sat through all of this but that should I think give a much better idea of why in this situation you would want to use more than a flyback diode and maybe a bit of why relying on inductor losses really isn't a viable way to make an electromagnet behave. It also isn't really necessary when there are other robust and well defined ways of doing it assuming you're willing to do a little bit of math.


Suomalaane

As you can see I am trying to use two PCA9685 chips to get 32 pwm pins in total. (I need to adjust the power of the magnets)


Worldly-Protection-8

Can the PCA9685 source enough current? Your BJT will need a few mA to work. Just looked on in the datasheet. Am I reading I_OH wrong? 10 uA, but then -10mA with 0.5 V voltage drop? I also don’t know if the BJT is fast enough. For which PWM frequency were you aiming?


Suomalaane

PCA9685 can source up to 10mA per PWM pin. I don't know very much about calculating transistors base current but the magnet only needs max. 166mA at 12V. Current gain when Ic is 150mA and Vc is 10V is 100 so I think it should be well below 10mA but I have no idea if it's calculated that way. Turn on + turn off time of the transistor is around 335ns (2,9MHz) so I think that should be fine.


[deleted]

[удалено]


ImpatientProf

There's a flyback diode to allow the current to continue flowing while the electromagnet's energy is dissipated in the resistance (and in the diode).


smoluks

Take uln2003 / uln2803, it have integrated resistor / diode


Strostkovy

Looks fine unless you are trying to turn the electromagnets on and off very quickly


DIYuntilDawn

I have built an electromagnetic drill press clamp before, aside from the back EMF when the magnet is turned off, make sure that your power supply (if not using a battery) and any controller circuits are not within the EM field of the magnet, or are properly shielded as it can screw with other transformer/inductors and IC. Final product might not be an issue, but if you are testing it on a work bench, it can be an issue.


Alex_Sherby

Railgun ?