Microcontroller, DAC and Mosfet to control TEC? - Page 1
Forum section: electronics / beginners

author: moonie223
author_rank: Contributor
timestamp: February 01, 2019, 04:14:01 am
content: Hello everyone!I am looking to control a small TEC to keep ~200mW of laser diode at a set temperature. I do not need super accurate temperature control, I am just looking to keep a diode near room temperature. I do not need full bridge control, just cooling. This particular TEC has a forward voltage range around 0-2V from 0-2A with both plates near room temp.I have a super simple circuit consisting of a IRF540, a thermistor, and a potentiometer. While it does roughly work, it's pretty dang inefficient due to the low forward voltage of my TEC compared to the voltages needed from a divider to make the mosfet work.I'm about to instead try using an arduino to control a DAC with a buit in opamp to switch the mosfet. This will allow me to keep the mosfet voltage much closer to the TEC voltage range. Since I am using a thermistor for feedback with some kind of PID running on the arduino I think I might be able to get away without any kind of current feedback to control the mosfet. Does this seem a reasonable plan? I don't mind having an arduino or similar in my project, I can use it for other things as well.I would prefer to avoid full PWM control of the TEC, I hear it's bad for them although it would be a heck of a lot easier to set up!I wouldn't mind more reading on current feedback control of a mosfet, though, if anyone has any good links or google searches they're willing to share! I've drawn a few in LTCspice, but I'm just copying application specific work without understating how it really works.Thanks for reading!

author: MarkF
author_rank: Super Contributor
timestamp: February 01, 2019, 04:47:40 am
content: The devil is in the details.Show us you current circuit. Part/model numbers would help.Which TEC are you using?Do you already have an Arduino or MCU you would like to use or are familiar with?I was just looking at a pic12f1840 8-pin MCU for a solar panel battery charge controller that sounds like it would be a good fit.

author: Ian.M
author_rank: Super Contributor
timestamp: February 01, 2019, 06:49:24 am
content: The problem with TECs and PWM is Joule heating, which is proportional to the square of the current, therefore 10% PWM at the TEC's max rated current has ten time the self-heating losses vs running it at a steady 10% of its max current.Its easy to solve - simply filter the PWM well enough to get DC with only a few percent ripple. A large choke in series with the TEC may be sufficient, rated to carry the max current without saturation, + a path for the current to continue to flow through both the choke and the TEC during the PWM off period. If you are driving it with an H-bridge so it can heat or cool it may already have suitable anti-parallel diodes, but if you are using a single transistor, you'll need to add a free-wheeling diode.What TECs really don't like is 'bang-bang' control - the thermal cycling and resulting differential thermal expansion and contraction can mechanically fatigue the thermocouple elements and junctions till they go high resistance or even open circuit.

author: Kleinstein
author_rank: Super Contributor
timestamp: February 01, 2019, 11:36:38 am
content: A 2 A TEC is still relatively small. So one could use linear control, even starting from a 5 V supply. Linear control is no perfect but still much better than direct PWM or on/off to the TEC. With 2 A and only 2 V at the TEC the worst cast heat for the controlling transistor would be at about 6 W - so it would need quite some heat sink, but not too much. For linear control the IRF540 MOSFET is however not that suitable. The more suitable part would be a NPN Darlington in TO220 case (e.g. TIP120 or similar).The setup could be something like PWM from the µC - Filter (RC) and than the NPN as a emiter-follower to drive the TEC.

author: moonie223
author_rank: Contributor
timestamp: February 02, 2019, 01:59:43 am
content: Here's a very rough schematic for a very rough circuit. Due to VGs being around 4V, I have to run this circuit at ~7.2V to get any real current from the mosfet. I don't do this long, I doubt there's a heatsink big enough!I am familiar with a wide range of micros, I've built a few PCBs that actually work. My latest contains a 328PB that reads serial data from a wideband controller, data from a 3 axis accelerometer, a MAX31855 for EGT and a few ADCs. It sends all this data to an aftermarket ECU in realtime via a custom canbus protocol. I built a logic analyzer from a cypress chip and sigrock, I wrote my own bits of code for serial data from the wideband controller, the thermocouple over SPI, and the accelerometer via i2c. I tried to leave enough space to run a OLED display I made that fit in place of useless instrument cluster gauges, but RAM is too tight and I only halfway know what I'm doing to fix that! I need to move from the MCP2515 library and write more dedicated code, but still don't think it'll be enough. I have another more complicated board that uses a teensy 3.6 that runs that display great, though! I've enough knowledge to map pins on that thing, plus use a few of the modules like the FTM to read wheel speed sensors in a language ECUs understand, although that's cheating as much work as Paul's put into that whole kit.I think I can handle the microcontroller part, and would probably build a custom board that ran on a 328PB since they're so dang cheap! I might try and seed the TEC current PID control by reading an average of the last analog voltage that relates to laser output power, plus I'd be able to shut the laser off completely if either the hotside heatsink or coldside diode got too hot. All of this is going into a custom built laser projector, so I'll have three of these little TECs to drive. I'd like to do it independently, mainly because I want to run the red diode as cold as I can while the other diodes can stay at room temperature. I'd also run a fan off a little PWM circuit, to keep the hotside cold and quiet as possible.Since I'd like to make this a compact projector, I'd like to avoid large inductors for filters. I don't know squat about analog, but I've ran a few online calculators and think I'd need quite large inductors right, if I wanted a smooth 3-4V to power a mosfet? I guess low setting time won't hurt much in this application, though, can I just use a large capacitor instead?The TEC I am using is a 12x12mm TES1-1704, described as 4A max and Vmax of 2.05V, TC max of 67c, QCmax of 4.8W. The block these TECs will be cooling is a small lump of brass, 12x12x15mm. The hotside will be a relatively large aluminum plate, with a finned extruded heatsink mounted underneath. I think this arrangement should work well, and shouldn't stress these TECs too hard. Another reason I'd like to avoid unfiltered PWM or worse bang-bang is because these TECs will be under laser diodes, I've seen what bang-bang does to 3d prints and I don't want anything like that with my laser alignment!!I've ran these things off a constant current bench supply using massive aluminum plates for heatsinks to try and maintain equal temp on both sides of the plate. I've measured the operating voltage to be around 0V to ~2V at 2A. At 4A, they jump to 3.6V. I am not sure how this changes with temperature, but I am sure it does.Also, a mosfet should be able to switch voltages lower than the control signal right? Within reason of G-S ratings, at least? So if I manage to build a switching supply that runs much closer to 2V, my mosfet won't waste as much heat, letting the more efficient switching supply do that.I also have no real reason to use a IRF540 other than I have some here, either!Thanks for reading everyone, and for the tips! Sorry for writing a book!

author: Ian.M
author_rank: Super Contributor
timestamp: February 02, 2019, 05:33:10 am
content: If you use PWM, at 62.5KHz, (fastest possible for 8 bit PWM on an ATmega328P @16MHz clock), you only need 1mH of inductance to get the TEC ripple current under 1%. That's assuming you run everything from the 5V rail.You can do that with a 9.5mm dia, 8.5mm tall choke e.g. Kemet SBCP-87HY1R0H. If you need it magnetically screened however, the choke will be larger and more expensive. I wouldn't bother unless your application is excessively sensitive to stray magnetic fields.If you need more bits of PWM resolution (for finer control) that will drop the max possible PWM frequency by a factor of two for each extra bit so you'll have to double the inductor value for each bit as well to keep the ripple under 1%. However you should be able to do 10 bit PWM without needing an excessively physically large inductor. I'd certainly bet on it being smaller overall than a linear solution as you can avoid the need for a switching preregulator and the MOSFET wont need heatsinking.N.B. when you choose a MOSFET, as a rule of thumb, its max. threshold voltage needs to be less than half the gate driver supply voltage, and, if you want to use a simple BJT complimentary emitter follower gate driver, the min. threshold voltage needs to be 1V or greater to be certain it will turn off properly.LTspicesim including a driver stage for the MOSFET attached.Its got two .tran commands, run.tran 10mto see how fast the TEC current settles, or run.tran 0 10.05m 10mto see waveforms and take measurements. View the spice error log to see the measurement results for the ripple current.Hint: When you run a sim with multiple sim commands, LTspice comments out the sim command(s) you didn't select by replacing leading . with ; so either edit the next one you want to run back to . so you can select it, or remember to 'Undo' after every 'Run' which reverses the commenting out without affecting the run results.

author: MarkF
author_rank: Super Contributor
timestamp: February 02, 2019, 06:19:23 am
content: Here are some ideas if you want to use a DAC and small display with SPI interfaces.I was thinking you might need to drive the MOSFET gate higher than 4V. So I added an Op-Amp.

author: moonie223
author_rank: Contributor
timestamp: February 02, 2019, 04:12:04 pm
content: Thank you both for the reply!Ian, thank you very much for the LTspice file! As usual, I was overthinking the simulation of the TEC, I should have just called it as a pure resistive load like this and continued trying things. I think this would be an acceptable level of output ripple, and it seems much more efficient as the mosfet only seems to waste watts during changes in output. I'm sure I'll be updating the output level at a pretty slow rate, that should work well.If I understand correctly, if I were switching this IRF540 with a 4V threshold I'd need 8V gate supply to be sure I get to the linear region, all the way to saturation? It looks like the IRF8910 you've used in this file has a 2.5Vgs, so better suited for 5V supply right?I think something just clicked on this driver stage, the transistors source and sink current when the input changes and that keeps the gate voltage closer to where you actually want to be, since the gate is a capacitive load, right? I think I might know why I killed some poor laser diodes now...Mark, thanks for the schematic! That's about what I was planning on doing, except I was going to try and use a MCP4725 to forego the extra opamp. I live pretty close to a micro center, and I think they have one of the adafruit boards in stock, I might pick one up and mess around with it a bit.Thanks again for the replys!

author: MarkF
author_rank: Super Contributor
timestamp: February 02, 2019, 04:59:50 pm
content: If you want 12-bits, the MCP4822 is available at a higher cost.It's a choice between SPI or I2C interface and extra cost.The Adafruit OLED displays are pretty expensive. They don't need MCU memory though and have logic level shifters and voltage regulators on board. There is also a 256x256 1.5" OLED with the same display chip (SSD1351).

author: Kleinstein
author_rank: Super Contributor
timestamp: February 02, 2019, 05:16:30 pm
content: The IRF540 may work, but may also fail to turn on with only 5 V supply.Just controlling the gate voltage can be tricky, as only a small range will change the current a lot and with temperature this voltage would drift. If the extra OP is used it would be better to have another shunt to measure the current and use to OP in a voltage controlled current sink - this way the OP would compensate for a changing temperature of the MOSFET. It will still need more than 5 V for the OP is the IRF540 is used.There is no need to turn on the FET hard - going beyond the nominal current is not a good idea: it gives less cooling and may damage the TEC.

author: spec
author_rank: Frequent Contributor
timestamp: February 02, 2019, 05:35:19 pm
content: Quote from: Ian.M on February 01, 2019, 06:49:24 amAre you sure about this. My calculations show that the losses are identical over integer periods of the PWM frequency. Take a theoretical example:Pulse PWM period 1 secPulse width: 0.1 secPWM signal 100W int load for 0.1 sec every sec (to give 10W average)Load= 10RSeries resistance (representing loss) = 1RAverage power required into load= 10WDC DriveWith a DC drive the current would be a constant 1A = I210 =10WThus energy into load = 10W* 1sec = 10W/secSimilarly the energy lost in the load is 1W/secPWM DriveFor duration of the pulse the current would be 3.16A, so power = 3.16A210 = 100W but only for 0.1sec, so the average power would be 100W/10 = 10W which is the same as for the DC signalThe same principle applies to the losses so the power in the 1R resistor would be 10W for the duration of the pulse but the average power would be 10W/10 = 1W.From the above you can see that the power loss is exactly the same for a DC signal or PWM.Of course, PWM would incur switching losses, but that is another matter.

author: radar_macgyver
author_rank: Frequent Contributor
timestamp: February 02, 2019, 05:41:06 pm
content: Quote from: Ian.M on February 01, 2019, 06:49:24 amCould you provide a citation? I ask because I've used commercial TEC industrial coolers that use a standard 1/32 DIN PID controller to drive the TEC elements. I've seen the occasional failure and it would be great if going to a linear control helps.The choice of MOSFET used here might potentially present a problem - these are not designed for linear use.

author: spec
author_rank: Frequent Contributor
timestamp: February 02, 2019, 05:57:36 pm
content: UPDATE #1 2019_02_02 (corrected figures)Quote from: radar_macgyver on February 02, 2019, 05:41:06 pmThis has often been stated, but I can't see a problem using any MOSFET for linear applications. Could you describe what the problem might be?The worst case VGth of the IRF540 NMOSFET is 4V5 and with a 5V supply the OP did say that he could not get enough drain current, which you would expect.But the BCHE TES1-1704QT125 TEC has a resistance of 0R03 * 170 = 5R1 and a maximum current of 3A9, meaning that a minimum of 19V89 would be required to fully drive it. So a 24V supply rail would seem sensible. With a 24V supply rail there would be no problem turning the IRF540 fully on.http://www.huimao.com/about/show.php?lang=en&id=6

author: Kleinstein
author_rank: Super Contributor
timestamp: February 02, 2019, 06:12:04 pm
content: PWM does not work well with TEC: The loss is proportional to I², while the useful cooling effect is proportional to the average current.So efficiency really gets bad with PWM. Even with PWM control one would likely need a series resistor to limit the current to the nominal current and maximum allowed current.A second point that with slow PWM or bang/bang control there is thermal stress to the TEC that can lead to failure.Even simple linear control with a analog controlled transistor give better results: for the same average current, the PWM case has all the loss is in the TEC and thus about half effectively on the cold side, while linear control has some of the loss in the pass transistor, which does not interfere with the cold side.For low voltage operation (like starting from a 5 V supply) the limitations on linear operation are not that severe, even for more switching type MOSFETs. Unless one uses modern low voltage (e.g. 20 V or maybe 30 V) parts they are probably OK with only 3 or 4 V at the MOSFET. For only 2 A one could use old IRF510 or BUZ10 parts that are specified for linear operation - though might need more than 5 V for the gate.There is still the option to use a BJT (like TIP120) With 1.4 V needed for base to emitter and 2 V for the TEC there is enough headroom from a 5 V source.Switched mode operation with an inductor and diode and optional capacitor is also not that complicated.

author: spec
author_rank: Frequent Contributor
timestamp: February 02, 2019, 06:32:48 pm
content: Quote from: Kleinstein on February 02, 2019, 06:12:04 pmNot sure what you are saying here- see my reply #12. I suspect you are comparing bananas with carrots.The TEC is a resistor and so is the loss element. Unless you are now talking about switching losses all of a sudden. Taking your statement at face value, no PWR system would work.You can't get away from the consevation of energy law.

author: spec
author_rank: Frequent Contributor
timestamp: February 02, 2019, 06:49:58 pm
content: Quote from: Kleinstein on February 02, 2019, 06:12:04 pmThese are just general unsubstantiated statements. None of the losses that you mentioned are defined or quantified. Besides which, the losses in a linear approach would be far higher than PWM, so if half of the linear losses were dissipated in the TEC, that would indicate that PWM would heat the TEC less. In fact, the TEC is a resistor and has to have current to operate and that current causes I2R heating, however it is driven.By the way, you can use any MOSFET or any BJT for any function. It is just that some BJTs and MOSFETs happen to be optimized for switching. In all cases a BJT is a BJT and obeys fundamental physical laws and the same for MOSFETs.

author: radar_macgyver
author_rank: Frequent Contributor
timestamp: February 02, 2019, 08:11:50 pm
content: Quote from: spec on February 02, 2019, 05:57:36 pmSwitching FETs don't have an SOA that includes DC (see attached for IRF540), so while the data sheet might say Vdsmax of say 100V and Id of 10A, you can't do both at the same time which is often the case with linear applications. How much you can go is a function of the SOA curve, which in some switching devices does not include DC. This doesn't mean they won't work, they're just not specified and you could potentially end up with thermal runaway.Having said all this, at low currents you could get away with such devices.

author: RoGeorge
author_rank: Super Contributor
timestamp: February 02, 2019, 08:51:02 pm
content: Quote from: Kleinstein on February 02, 2019, 06:12:04 pmThis is correct. ^For the same cooling power, the radiator for the heating face will need to be way bigger with PWM than with a constant voltage.https://electronics.stackexchange.com/questions/28634/how-to-drive-a-peltier-elementhttps://www.meerstetter.ch/compendium/peltier-element-efficiency

author: Kleinstein
author_rank: Super Contributor
timestamp: February 02, 2019, 09:13:35 pm
content: Quote from: radar_macgyver on February 02, 2019, 08:11:50 pmIn this case we have a rather low voltage. For most MOSFETs thermal runaway is a problem mainly at higher voltage. It is less a problem at low voltage. The missing SOA curve for DC only indicates that they don't bother to specify it. Especially below 12 V linear operation may not be a problem.

author: Ian.M
author_rank: Super Contributor
timestamp: February 02, 2019, 09:45:19 pm
content: From the simulation or modelling viewpoint, a TEC is not a pure resistor. Its a resistor in series with a voltage source that's proportional to the temperature difference across it, representing the thermal EMF. To get it to cool one side and heat the other, one forces current through it in opposition to the thermal EMF. The cooling effect is, over the normal operating range, more or less proportional to the average current but the heating of its internal resistance is proportional to I2.Consider a current of 10% of its rating. Both steady DC and PWM at max current with a 10% duty cycle will have the same average current , but due to the I2factor, the losses (self heating) during the PWM on time will be 100 times greater, and when you average them over the whole duty cycle for an 'apples to apples' comparison with DC, will still be ten times greater.To correct a few other misconceptions - you need a MOSFET driver between the MCU pin and the gate if you are directly PWMing the MOSFET, because the MCU pin on its own typically can't provide enough current to slew the gate fast enough through its Miller plateau, where the MOSFET is in its linear region and dissipating power like crazy due to its load current multiplied by the Vds drop. across it.For small, low gate charge MOSFETs, and low PWM frequencies (or bang-bang control), you can often get away without a gate driver if the gate drive voltage requirements are within your logic supply rails.If you need more gate voltage than the logic supply one uses a gate driver that includes level shifting. This is usually a one-chip solution that saves a lot of faffing around with discretes.Most gate drivers are not suitable for linear operation, but unless you need a rapid step response, you don't need a gate driver anyway, as the OPAMP output current is sufficient to slew the gate fast enough. You do need a gate resistor to prevent parasitic oscillations and also isolate the OPAMP from the large gate capacitance which could case instability.From the point of view of the TEC, it doesn't matter if the PWM is filtered before a linear controller or in an inductor in series with the TEC, as long as it is filtered so it only gets low ripple smooth DC. Both avoid the evils of directly PWMing the TEC.I don't have a cite for TEC thermal cycling issues. I remember reading it at least a decade back in a TEC manufacture's documentation - either a data sheet or application guide.

author: MarkF
author_rank: Super Contributor
timestamp: February 03, 2019, 07:13:46 am
content: i'm not familiar with TEC devices. But, it appears from the discussion that you want to control the current and not the voltage?So let me offer a modification to my previous circuit.I stuck with the MCP4822 DAC because it has a SPI interface. Which if you use the Adafruit display with a SPI interface, it would save MCU memory by not needing both SPI and I2C libraries. (Assumption on my part. I have only done SPI on a PIC with my own lbraries.)

author: Ian.M
author_rank: Super Contributor
timestamp: February 03, 2019, 07:28:22 am
content: All that to save one choke to smooth the current!It is however worth it (with a higher resolution DAC) if you need *VERY* fine resolution for setting the current because you need to hold the temperature constant to a small fraction of a degree and don't want to have to mess around dithering the LSB of the PWM pulsewidth, as the choke requirements get ugly at lower PWM frequencies and with increasing PWM resolution.

author: RoGeorge
author_rank: Super Contributor
timestamp: February 03, 2019, 09:13:38 am
content: Another thing to mention is that many laser diodes (the OP doesn't say the model of the 200mW diode) have an internal fotodiode that can sense the optical power/temp. To drive the laser diode close to its maximum power (without melting the junction), the driving circuit must work in a feedback loop with the fotodiode. There are specialized CI drivers that can properly do that. Most of the DIY blogs or videos are made by absolute beginners that don't know what they are doing.Find the datasheet of the exact model of that laser diode, and read it. Look for application notes, too.A Peltier cooler might help, but this will not guarantee the safety of the laser junction.Another thing to mention is that 200mW can easily burn the retina forever. Even the reflections from the surrounding objects can do permanent damage to the eyes. Use laser protection goggles for the specified wavelength of the laser. Other goggles for other colors might not protect at all.Apart from that, here anything over 5mW can be used only with special permit.

author: moonie223
author_rank: Contributor
timestamp: February 03, 2019, 01:25:05 pm
content: This diode does not have a photodiode or NTC thermistor, simple oclaro 120mW 635nm laser diode. Although I have schematics for a photodiode feedback driver, it's not very common to do so with galvo XY scanners. Holography, oh yeah, you need that, a full bridge tec setup, a super heavy duty table, and no trains nearby, as least as far as I can understand.I am not looking to protect the laser junction with the TEC, just keep the diode cool. It will not be ran outside it's rated spec, and the only reason for active TEC cooling is to keep the wavelength as close to 635nm as possible as 635 diodes drift with heat, around 0.2nm/K. I have a setup running now that has all the same/similar diodes, no tecs, and it'll run for hours.Thanks for the laser safety info, but I think I've got that mostly covered! I've got a wide frequency range of goggles since I've been messing with lasers for long as I can remember, I was buying and ripping diodes out of the casio projectors a few days after we discovered what were really in those A-140s! I'm in charge of managing a 6KW disc fiber laser too, that thing is wicked fun! Used it to cut that temporary baseplate for my projector. I might also try and borrow some liquid nitrogen, see if I can make a 638nm diode blue shift all the way to yellow! I should have a 589nm DPSS hiding somewhere still, to compare against...And I intend to make this a legal laser projector, there are safety features that must be implemented to be legal. That's another reason I want an arduino in this project, I'll use it as the last device to control the output shutter, I might try and take a look at the galvo feedback as well, to see if I can implement a scan-fail check. I think I might need something faster than just a 328P, but I could add a few extra DACs and even run prerecorded shows off the micro instead off off ILDA software on a standalone computer. Regardless, I'm just making one of these. If anyone wants the schematic and code for what I come up with when I'm done, I'll share it freely! I do not want to sell projectors, deal with FDA, or any of that nonsense!It sounds like a faster PWMing micro would help me forego the extra OP and get me finer resolution with a smaller filter inductor, I've never messed with the SAMD21, but it seems it should get me to 187kHz pretty easy. I need to read more to figure what sort of resolution that would get me, but it should allow an inductor nearly three times smaller, right?Thanks again for all the help and discussion everyone!