I will answer what i can and say that the 12v supply is derived using a dc/dc converter module directly from the supply of the solenoid at 26 or so volts. The photo sensor is less than 5cm away from the trigger circuit and while the mosfet was working it did not run very hot (Keep in mind i was not able to monitor it constantly). Also i think it is important to know that the supply at the moment is 2 12v lead acid car batteries, I planned to change it after i could see that the system was working reliably.
Ahh... and I guess the converter is common ground, a three wire module more or less?
That sounds alright.
-Is there anyway to avoid avalanche/failure entirely?
Yes! Divert the excess voltage into a clamping device.
Technically, TVS diodes also avalanche; they're just more reliable at it. We could still dodge that, if we wanted to -- say by using a clamp diode into a large capacitor (this is called a voltage peak clamping snubber).
-If running at avalanche does cause lasting damage and thus the life span is temporary, would there be any way to extend it or reduce the risk of failure?
The MOSFET by itself, can dissipate a fair amount of power for a short time, at pretty much any voltage or current it can handle. Avalanche occurs when the voltage is pushed too high (avalanche breakdown), somewhere above 60V. This is a different sort of current flow (there's physics under there), and it cannot be controlled by gate voltage.
One way to avoid this type of current flow, is to make the transistor turn on, just enough to hold drain voltage below breakdown.
Which can be done with two diodes anti-series, one a zener. Zener points to drain, regular diode points towards gate. This is a common approach in "protected switch" devices (which are a MOSFET with a controller built in, powered by the "gate" terminal itself). See diagram here:
http://diodes.com/design/support/technical-articles/self-protecting-mosfets-deliver-improved-reliability-in-the-harsh-environment-of-automotive-applications/I'd still include the S-G zener, to protect against rapid changes, ESD and the like.
Another way is, since we know the load is inductive -- just don't turn it off as fast. Evidently, it's about 20 times too fast. If we slow it down 20x, the excess voltage will be manageable. This is easily done by increasing the pull-down to 2kΩ.
Downside: now the whole turn-off time (Miller plateau), spent with high drain voltage and full drain current, is 20 times longer, too. Which is 0.5us * 20 = 10us. If it's dissipating up to 50V * 40A = 200W for 10us, well, that's still well within the safe operating area, we can check that on Fig.11.
So this seems to be a fine option. Which echoes what some have said earlier in the thread, but this puts a number to it.
-When you said that the zener should go from GND to 12V, could it go directly across the input terminals of the board or does it need to be near the mosfet?
-Would the TVS diode and Zener diode fully protect the mosfet/how are they protecting the mosfet? (In my mind something would need to be directly across the coil, ie. GND to 26V not between GND and 12V)
The board is small, at the connector is fine.
The trick here is, the inductor doesn't care where its current is going, it's just a current coming down a wire. When the transistor turns off, that current just goes into, whatever it goes into. If nothing's there to catch it, it keeps going into the transistor (as avalanche breakdown). It's the transistor's fault that the voltage shows up -- it's the causative event.
Aside:
This is actually true to a deep level. If we do the same thing with faster transistors, we can see the event propagate through space (or at least along wires) at the speed of causality itself, i.e., the speed of light. A transistor that switches in 1ns for example, goes from off to on in but 30cm at light speed! You can imagine a spherical shell expanding away from the transistor, encompassing all space that can possibly know about its switching. Think of the shockwave from an explosive, made visible by the refraction of air; except in this case, instead of pressure, it's the...rather abstract idea of being able to tell an event has happened. Though conveniently in this case, at least, we can also measure something more concrete, like the change in voltage.
I suspect this is just more confusing than useful..... but the point is it's ultimately very fundamental to the universe itself, and the reason your transistor experiences a voltage peak is, in an overly basic but fundamentally true sense, because of causality at the speed of light. I think that's pretty frikkin cool.
I digress.
So, er, in any case, to close that causal loop, you need something to "cause" current to flow, soon after the transistor stops doing it. Which means putting the TVS beside the MOSFET, where it can "know about it" immediately. The inductance can't stop flowing current until it "knows" about it, and it's [this] *waves hands* far away.
Likewise, the clamp diode being at some distance, isn't helping as much as it could be. Yes, it's clamping the bulk of the solenoid's charge. Which is, by a huge margin, most of the energy in this system. But there's still some in the wires stringing everything together.
-Why is it that the mosfet can handle being in avalanche for any amount of time?
Because... slimey wimey semiconductor physics?
I actually don't know much about this myself. I guess that's no accident, according to this appnote?
https://www.infineon.com/dgdl/Infineon-ApplicationNote_Some_key_facts_about_avalanche-AN-v01_00-EN.pdf?fileId=5546d462584d1d4a0158ba0210977cdeSomething about "hot carriers", and I would assume dislocations and other stuff, in a sense causing breakdown of the semiconductor or insulator materials themselves, in a similar way as they would when just utterly blasted (with excess voltage and/or current), but a tiny bit at a time. Eventually I guess enough defects occur in some point to forms a conductive channel, or it aggravates localized heating or something, and then current draw starts increasing, and pretty soon it shorts out.
Also, this one from ON Semi seems to agree the avalanche curve is single only,
https://www.onsemi.com/pub/Collateral/AN-7515.pdf.pdf so it doesn't apply to repetitive avalanche.
(Huh weird, that link is also a .pdf.pdf. I never noticed that before, I wonder how many of their files are named like that...)
-Im assuming that while in avalanche as long as the breakdown voltage is not exceeded and it's not avalanching for too long it might survive, is this correct?
Not quite, avalanche
is breakdown. It seems it's more or less the case that a device can withstand a certain amount of avalanche, total. So, they're happy to give big fat single-pulse ratings, or even test them in production (as the appnote above says OptiMOS are?), but a few too many of those, or a few too many hundred or thousand or million or whatever of very brief ones, and...not so much.
But yes, if the voltage is kept below breakdown, avalanche does not occur, and operation should be reliable.
So, it does look quite likely that this is the problem, and it would be easy enough to verify with an oscilloscope, if one is handy. And the symptom should go away with a TVS installed, or any other change that avoids MOSFET breakdown.
TVS diodes do not suffer from the reliability issue, as far as I know. The problem is that MOSFETs are complicated, they have a bunch of stuff in them that....transists. Probably, the same wear mechanism occurs in diodes, but the only insulator that could fail, is around the edges of the diode, and stuff getting blasted around there can't really cause problems, partly by careful design I'm sure, and partly because it's just a thin surface around a big fat lump of semiconductor. (That's another thing that MOSFETs are: surface area. MOSFETs work purely on a surface effect. It's all surface, millions of tiny structures etched into the silicon provide enough surface area to handle huge currents.)
Tim