A few months ago, I began to obsess over AA NiMH batteries. So I've begun a ton of research into building my own battery tester. I mean, why buy one for $35 when I can build a much more expensive one with fewer features?

The TL;DR of a battery tester is to simply measure the amount of Amp-hours a battery has. All I have to do is discharge the AA battery against a known resistor, measure the voltage (which implies a specific current), and then keep time while doing so.

---------

Design Overview:

* Surface Mount design -- My first time. Oooohhhhh boy. Lets hope I don't screw it up too bad when the parts come in. I did a bit of chip research, and "good" chips are all surface mount. The newest ATmega328pb is surface-mount only. I can't even find a buck-converter with better than 80% efficiency unless I go surface mount. I'll aim for the larger 0805 American (2012 Metric) passives. I hear they're easier to solder.

I do a lot of coding at work. The code looks a bit tedious, but straightforward if I'm reading the AtMega's datasheet correctly. The most complicated part will be programming all of the I2C interrupts so that my 16x2 Character screen actually is useful.

So the vast majority of my worries was figuring out how to create a control-scheme to vary the voltage / current of the battery under test. I had to pull out a bunch of OpAmp books, but I think I understand how it works now. And thus, this analog simulation is my most proud accomplishment in this project:

I technically have a mixed-signal design: I have digital circuitry (the 16x2 screen, PWM, and a noisy buck converter!), and analog circuitry (filters, op-amps, and the ATmega's "analog side" with ADC converters measuring the various lines). Indeed, the ATmega328pb itself is trying to facilitate mixed-signal design since it has 3 Vcc pins! Two of them for the digital stuff, and an isolated "AVcc" for the analog stuff (AVcc feeds the ADC converter, and there's a sleep-mode that cuts off power to the digital-side of the ATmega).

So I've been learning a bit about ferrite beads, decoupling capacitors and whatnot, I'd like to do the best I can when I start laying out the board.

--------

Ultimately, this project is large enough to be non-trivial, but still looks simple enough for me to accomplish. 4-ICs (Buck Converter, The 16x2 Screen, the ATMega328pb, and the OpAmps), approximately 3 buttons, and a bunch of passives. Should be good enough for a beginner, right?

I've come to the conclusion that getting rid of the 5V rail and using a Rail-to-rail Output OpAmp (LMV358l) will be a superior design. I'm still thinking of using the Buck Converter because batteries "run out of voltage" as they deplete. 4xAA gives 4.0V to 6.0V depending on how "full" the batteries are. A buck converter to drop that down to 3.3V consistently would make a good chunk of calculations easier.

The ts27m2 doesn't go all the way up to the +V rail. With 3.3V supplying it, it can only go up to ~2.3V (3.3V - 1V dropout) on the output. With ~1V Threshold voltage and 1.5V on the resistor... I'd likely need ~2.5V or 3V maximum output voltage to be safe.

RRI is not needed. The highest voltage that will be on the feedback terminal is 1.5V (the AA under test).

--------

I've calculated the anti-aliasing filter assuming these specs for the ADC conversion: Assuming 2000 samples / second (aka: 1kHz Nyquist Frequency) and a 10-bit conversion... I'll want to therefore attenuate "aliasing error" above 1kHz by 1/2048. Solving for a simple RC circuit for 1/2048 at 1000Hz, that gives me an RC constant of 0.3258. That's... pretty awful. An RC circuit would have a response time of ~1.5 seconds and a -3db threshold of ~0.48Hz.

Still, its probably good enough for the purpose of the battery test. After all, a 2Amp drain would take over an hour with a 2300mAh battery under test, while a slower drain could take as long as 24-hours. So being "slow" for 1.5 seconds doesn't actually make a lot of error to the calculation. In contrast, if some noise (ex: I got a noisy Buck converter) caused a like... ~1000Hz ripple that aliased into +0.001V, that'd definitely contribute more to inaccuracy.

Ugggh, found this document online and now I feel like I have to read it over. I've made oscillations in my OpAmps through LTSpice before, and I understand the complications of building a feedback system without oscillations. The Max6106 claims its oscillation-free on any capacitive load however, so that's good.

The main power-line is the 3.3V output from the Buck Converter. Across a Ferrite Bead, there's another 3.3V rail that I'll keep isolated to the "analog-side" of my circuit. The direct ~5V output from the 4x AA batteries doesn't have any use aside from the uC periodically checking for low voltage.

The backlight switch, as currently designed, is giving me some shivers. The switch probably should be debounced somehow. The ATMega's internal pullup resistor is sufficient to make sure that the switch doesn't draw too much current.

The backlight switch just turns on the backlight for ~4 seconds, so that the user can read the screen. Then it turns off. This would be easy to implement in hardware, but also is relatively simple to implement as a software interrupt. I'm going back and forth whether or not to do this in hardware or software...

----------

The OpAmps are BJT-based, which means they only go to ~200mV of the rail. The output of the low-pass filter is therefore capped to a minimum of 200mV or so. I've added Q2 as a means to fully-turn off the battery-under-test, while the PWM will serve as a way for the ATMega to control the current of the battery-under-test.

I'm very close to just ripping up the whole Bessel-filter thing and using a crude R2R ladder as a DAC. Since the current design is PWM-based, I can't actually make the microcontroller go to sleep! I have to keep it on the whole time.

----------

The 15uA of current draw on the 4xAA battery limits the lifespan of this device (even when off) to ~30 hours. I think I should stick a MOSFET there which senses the "on" line and only enables current flow when the buck-converter is on.

BTW: I'm not even sure if accurate 2.2uF capacitors exist in 0805 form factor. All that I've found so far are some X7S inaccurate +/-20% crap. Which is important for the low-pass anti-aliasing filters I've put into the front of the ATMega pins. NP0 (maximum accuracy and temperature stability) only goes up to 0.047uF. I might be able to make due with +/-20% accuracy on those pins however.

I've done a pass-over and switched to E3-series in every conceivable location (hell, I use the number "1" as often as possible). I've chosen 0.1uF to be the decoupling capacitor, made sure to copy/paste that everywhere I could.

Sooooo... I made a picture and am already seeing things wrong with the design. Lol. Well, I'll work on it later again... the date at the bottom is accurate, I started sketching out this schematic in October 2016, but back then it was blatantly obvious that I didn't have the skills to complete the project. A few months later, I've sketched out this design that I mostly understand.

BTW: I'm not even sure if accurate 2.2uF capacitors exist in 0805 form factor. All that I've found so far are some X7S inaccurate +/-20% crap. Which is important for the low-pass anti-aliasing filters I've put into the front of the ATMega pins. NP0 (maximum accuracy and temperature stability) only goes up to 0.047uF. I might be able to make due with +/-20% accuracy on those pins however.

You won't be able to find NP0/C0G capacitors that high, but you can definitely do better than 20%. X7R is typically the best option for high-ish value capacitors that aren't completely crap. link

BTW: I'm not even sure if accurate 2.2uF capacitors exist in 0805 form factor. All that I've found so far are some X7S inaccurate +/-20% crap. Which is important for the low-pass anti-aliasing filters I've put into the front of the ATMega pins. NP0 (maximum accuracy and temperature stability) only goes up to 0.047uF. I might be able to make due with +/-20% accuracy on those pins however.

You won't be able to find NP0/C0G capacitors that high, but you can definitely do better than 20%. X7R is typically the best option for high-ish value capacitors that aren't completely crap. link

You'd be surprised how crap X7R is across various DC voltages:

Capacitance changes based off of the voltage with these high-value capacitors in small packages. Those particular chips have a capacitance anywhere from the rated 2.2uF to 2uF (+/- 5%), on top of the initial accuracy of +/- 10%

Although... now that I think of it... I'd be operating entirely within 0V to 1.5V, which means there's actually no accuracy loss with those capacitors. So maybe I was over panicking. There's probably no issue in this case.

arbiteroftruth wrote:That's why you go with a much higher voltage rating than you really need. A 25V X7R should be pretty good at 0 - 5 V.

Nope. Notice how the low-end is now as high as 2.4V and yet the dropoff to 6V is as bad as the 6.3V capacitor.

Fortunately, I'm only working from 0V to 1.5V. So... its sufficient actually. In any case, this capacitance-change across DC voltages is a problem innate to the X7R chemistry. Fortunately, it doesn't matter in this case... but you can't get around this issue by buying "higher rated" X7R capacitors.

Basically, you only use X7R for decoupling applications, and other situations where accuracy isn't too important.

Ah, upon a little checking, it's a larger package size that helps (which usually corresponds to a higher voltage rating at a given value, hence my mistake). So if you use a 1206 capacitor rather than an 0805, you should get better performance.

arbiteroftruth wrote:Ah, upon a little checking, it's a larger package size that helps (which usually corresponds to a higher voltage rating at a given value, hence my mistake). So if you use a 1206 capacitor rather than an 0805, you should get better performance.

Lol, duh. If I need a bigger capacitor, I should get a bigger capacitor.

I'm going to do more through analysis of my OpAmp. I personally think that my methodology of controlling the oscillating MOSFET is "ugly". I'm basically taking a hammer to the oscillations by destroying the gain of my OpAmp. However, OpAmp gain leads to better accuracy. Perhaps with good "frequency-dependent" feedback compensation, I can stabilize the MOSFET feedback without destroying the gain / accuracy of the OpAmp circuit.

The primary issue is that the MOSFET has a gain of 75 (Well... 75 transconductance from the datasheet. With the 0.4Ohm resistor, that's going to be ~30 gain), and a capacitance of ~1000pF. The OpAmp's datasheet claims a ~60 degree phase-margin on a ~200pF load... and a 10db gain-margin. The MOSFET wipes out both the phase-margin and gain-margin of the OpAmp, which leads to oscillations (in LTSpice anyway. I haven't built a "real" version of the circuit yet).

I'd like to potentially "systematically erase" the high-frequency oscillation through capacitors and resistors... somehow. But I think I need more research before I understand that methodology. I've thought about using a BJT instead (which have much less capacitance), but BJTs have higher gain. So I'd probably still get oscillations anyway.

I like the "resistor-like" effect that MOSFETs get at low-voltages and low-currents. BJTs act more like a diode with a "voltage drop"... I don't have much voltage on the battery-under-test (1.5V at best). So I'd prefer a MOSFET. But... if the capacitance issue remains a headache... I might be forced to use a BJT instead.

In your configuration the transistor should be pretty benign for stability. The transistor will behave as essentially a unity-gain voltage buffer, with an offset due to the gate-to-source threshold voltage. The transconductance gain is gain from gate-to-source voltage to drain-to-source current. But as that current increases, the source voltage also increases, so the gate-to-source voltage decreases. The end result is a voltage gain of slightly <1 from gate to source. It's the same principle by which your high-gain opamp becomes a unity-gain buffer thanks to feedback. I doubt the transistor the source of your problem.

If that 1 Meg resistor is still included in the unstable version of your circuit, I'd suspect that to be the problem. The opamp's input capacitance can cause stability issues if you have a huge resistor in series with the input.

arbiteroftruth wrote:In your configuration the transistor should be pretty benign for stability. The transistor will behave as essentially a unity-gain voltage buffer, with an offset due to the gate-to-source threshold voltage. The transconductance gain is gain from gate-to-source voltage to drain-to-source current. But as that current increases, the source voltage also increases, so the gate-to-source voltage decreases. The end result is a voltage gain of slightly <1 from gate to source. It's the same principle by which your high-gain opamp becomes a unity-gain buffer thanks to feedback. I doubt the transistor the source of your problem.

I've thought about this significantly, and as far as I can tell, your analysis is completely correct! I guess I was wrong in an earlier post about the transistor's gain being an issue.

You're just missing one key fact: the MOSFET has ~1000pF of capacitance on the Gate/Source. Most OpAmps are only designed to be unity-gain stable at 100pF of capacitive loads.

I need a big, power MOSFET because the circuit there will be 3.75 Amps worst case, with a worst-case voltage drop of ~.75V (1/2 the voltage of the AA under test). ~3W worst-case scenario for the MOSFET to dissipate.

All big MOSFETs seem to have ~1000pF or more capacitance. It comes with the territory of being able to handle ~3W of dissipation.

Big BJTs seem to have much less input capacitance; however, I'll need a lot of current gain... The OpAmp can handle 10mA-ish, so I need a gain of 375 for the worst-case 3.75Amp. Furthermore, the Vce drop of ~200mV will essentially cut out 15% of my available voltage / current. And power-BJTs still have ~100 to ~200 pF of capacitance anyway. The LMV358l claims 60-degrees of phase margin on a ~200pF load, so maybe the BJT-approach would be sufficient?

--------------------

I spent a lot of time last night using LTSpice to calculate my gain-margin and phase margin (without the compensating resistors). I'm basically 15db too much gain... OR my phase is ~20 degrees away from stability.

The 1Meg / 1k "compensation" resistors fix the problem. They cut the loop-gain by ~1000 (aka: subtract 60db), which puts me at ~45db gain Margin and the circuit is stable again. It probably would make more sense if I posted my analysis graphs... I'll do that later.

If that 1 Meg resistor is still included in the unstable version of your circuit, I'd suspect that to be the problem. The opamp's input capacitance can cause stability issues if you have a huge resistor in series with the input.

I did experiment with lower-value resistors and it does seem to give me more gain / phase margin.

There's a tradeoff however, I want the OpAmp side to be "isolated" from the circuit under test. The 1Meg resistor ensures that the "PWM current" from the ATMega is really small. In effect, the 1Meg resistor is there for isolation, not for preventing the oscillation.

KnightExemplar wrote:You're just missing one key fact: the MOSFET has ~1000pF of capacitance on the Gate/Source. The OpAmp is only designed to be unity-gain stable at 100pF of capacitive loads.

Yeah, but the gate capacitance isn't in the right spot to be considered a load, as far as that spec is concerned. And the fact that the transistor has a gain of nearly 1 from gate to source effectively cuts down that capacitance. If the gate-to-source voltage gain is 0.9, then for every 1V the opamp moves its output, the gate-to-source voltage only changes by 0.1V, so the gate-to-source capacitance has only had to be charged by 0.1V. This makes that 1000pF look like 100pF from the opamp's perspective. If the gate-to-source gain is 0.99, then 1000pF becomes 10pF. 0.999 makes it 1pF, and so on.

Am I correct in understanding that in the unstable version of your circuit, the 1 Meg resistor is a short-circuit and the 1k between the opamp inputs is removed? If that's the case, maybe the transistor is the problem, but not because of gain or capacitance. It might be slow to respond to changes in gate-to-source voltage, relative to the speed of the opamp. If that's the case, you might try making that 1 Meg resistor something like 1k, and add a capacitor (maybe 10nF or so) from the opamp output pin directly to the negative input. That should have the effect of slowing down the opamp without changing its gain at low frequency.

arbiteroftruth wrote:Am I correct in understanding that in the unstable version of your circuit, the 1 Meg resistor is a short-circuit and the 1k between the opamp inputs is removed?

Yes.

If that's the case, maybe the transistor is the problem, but not because of gain or capacitance. It might be slow to respond to changes in gate-to-source voltage, relative to the speed of the opamp. If that's the case, you might try making that 1 Meg resistor something like 1k, and add a capacitor (maybe 10nF or so) from the opamp output pin directly to the negative input. That should have the effect of slowing down the opamp without changing its gain at low frequency.

Tried it, doesn't work. Dunno why however.

Yeah, but the gate capacitance isn't in the right spot to be considered a load, as far as that spec is concerned. And the fact that the transistor has a gain of nearly 1 from gate to source effectively cuts down that capacitance. If the gate-to-source voltage gain is 0.9, then for every 1V the opamp moves its output, the gate-to-source voltage only changes by 0.1V, so the gate-to-source capacitance has only had to be charged by 0.1V. This makes that 1000pF look like 100pF from the opamp's perspective. If the gate-to-source gain is 0.99, then 1000pF becomes 10pF. 0.999 makes it 1pF, and so on.

That's a good point.

Then there's some other parasitic capacitance in that transistor that's causing the problem. Maybe the rarely considered Cds (Drain/Source Capacitance) ??

EDIT: I'll have to read up on MOSFETs: specifically "Output Capacitance" and "Input Capacitance". I definitely am completely mystified by what the hell is going on with this circuit. The "real world" specs are ~1000pF input capacitance and ~300pF output capacitance. I chose a large-ish MOSFET for the PSpice simulation... but probably should find the .subckt model for the Si2342DS I'm planning to use.

The "Reverse" capacitance (from the Gate to the Drain) is the important figure. The Drain is directly connected to the AA-under-test (1.5ish V), which means that there's a load capacitance. Its just not... to ground, but to 1.5V instead. Still, that load capacitance will prevent the gate from moving very much, and therefore its the most important parasitic to talk about.

But then I realized... I was using the LTC6087 and the BUK9219-55A in my simulation for some reason. I was trying various other OpAmps out, and the BUK9219-55A was just near the top of LTSpice. I figured that the BUK9219 was "representative" of MOSFETs... but I really should be more precise about these things.

-------------

So... redoing my analysis with the LMV358L and the Si2342DS

No expected oscillations at all. Phase margin of 40-degrees, Gain-margin of 6db.

----------------

However, for whatever reason, I kept using the LTC6087 last night. The LTC6087 has some exceptional specifications... but then I look at the phase margin: 45-degrees on 45pF of load capacitance.

Uh-oh. Erm... lets hope the application notes have some better news?

LTC6087/LTC6088 can drive capacitive load up to 100pF in unity gain.

Erm... well... there's my problem.

So tldr: the LTC6087 is just barely unity-gain stable, and the ~250pF "reverse input" capacitance of the MOSFETs I've been simulating was enough to cause oscillations on LTC6087. Read the docs, and be sure to simulate the right parts...

----------------

arbiteroftruth wrote:If that's the case, you might try making that 1 Meg resistor something like 1k, and add a capacitor (maybe 10nF or so) from the opamp output pin directly to the negative input. That should have the effect of slowing down the opamp without changing its gain at low frequency.

I managed to get your advice to work btw. Let me first demonstrate the issue:

Spoiler:

And here's how I solved it, without fucking over the gain:

Spoiler:

Your idea about the 1nF capacitor made sense, what I was missing was a smallish-resistor to "separate" the feedback lines.

I played around with some values, and was liking this final setup.

Spoiler:

------------

So as of this post, I think all of my analog issues have been solved. I go over the ATmega328pb and I'm not 100% sure about the RST pin (I'm pretty sure I need to hold that pin high...)

* Ferrite Beads look wondrous at the 100MHz+ range. However, my goal is to isolate the ~8MHz noise (from the ATmega) and the ~1MHz noise (from the Buck Converter), and ~100kHz (from I2C bus) and prevent that from entering the "analog side" of my circuit. True, this ferrite bead looks effective (~4uH of inductance and 250kOhm resistance at 100MHz), but a straight decoupling inductor has more inductance in the same package, and will therefore be more effective at 1MHz and 8MHz.

The decoupling inductor has very large parasitic capacitance, so it begins to lose effectiveness at ~18MHz and probably isn't useful for 100MHz or higher designs. But... I'm not making a high-frequency design, so the ferrite-bead's superior 100MHz+ behavior is irrelevant.

* I picked the decoupling inductor by: estimating ~100mA worst-case current draw (wayyyyy above what I'm expecting). The ATmega requires Vcc and AVcc to be within 0.3V of each other, so at 100mA worst-case current, that's 3Ohms DCR worst-case. Then I pick the largest inductance to affect the lowest frequencies as much as possible.

* I was considering designing an active filter for the ADC of the ATmega. However, active filters have error: input offset error, input bias current, input offset bias... lots of errors that add up. Furthermore, even rail-to-rail OpAmps have a bit of trouble going all the way to their negative rail (I looked up like 3 or 4 more OpAmps). Unless I buy a more expensive "beyond the rail" OpAmp (which have internal DC-DC converters to charge-pump the output down to 0V), I don't think I'll get a clean "zero". Therefore, I'm sticking with a passive design and just gonna deal with the overall poor-specs of an RC-filters.

Sure, they don't drop-off very much and they don't have a flat passband... and they don't have a flat phase shift. But I don't care much about that. I mean... I sorta care, but I'm willing to sacrifice all that and instead get good absolute accuracy.

For some actual numbers: I've whipped up a simple 2-pole RC filter in LTSpice, and I've got the -3db point to like... 9Hz with -70db at 1000Hz. -66.2db (aka: 1/2048 attenuation) at 1000Hz (the Nyquist of 2000Hz sampling) is necessary for anti-aliasing. I still find it annoying that I'm sampling at 2000Hz on a signal that takes 1/20th of a second to move.

Pull-up resistors on the dW/(RESET) line must not be smaller than 10kW.

Tested it out with a multimeter myself today. The "ATMega328pb Xplained Mini" has been the reference design of that I've been copying so far. Sooooooo.... I guess a 3.3kOhm resistor is fine to use, despite what the documentation claims.

BTW: How often do you see a resistor that's THIS in spec? That's like.... within +/- 0.01% or something ridiculous.

-----------

Anyway, my current design doesn't have any pull-up resistor so... the ATMega328pb would have just reset-looped. So... good thing I'm double-checking the reference design. In any case, I'm gonna use a 10kOhm resistor like the docs say. Hopefully it won't cause any issue to follow the docs (instead of the reference design)...

This 20W resistor is derated by 50% by ~90-degrees Celsius. Granted, that's pretty hot, but I still need to ensure that the resistor doesn't go above 115-degrees (0r +90 degrees over ambient). Spreading out ~7W of heat with only a 90-degree change is looking to be rather difficult. A lot of standard heatsinks have a thermal-resistance of like... 20C / W (so +140C at 7W)... I may actually need active cooling to keep this thing safe.

The transistor on the OpAmp will likely need a heatsink as well. (The On/Off transistor will never really have much of a voltage drop, so its probably safe). A .75V drop with 1.5 Amps is still 1.125W, which is rather significant. Uggghhhh....

Assuming the 20W resistor earlier, the internal thermal resistance is ~6C/W, so the "internal" heat of the resistor will rise to +42 degrees before the ambient temperature even goes up. That leaves 48-degrees that the heat-sink (and heat-sink connection) must handle, over 7-Watts. That's a thermal-resistance of ~7C/W or better (with a perfect connection, which are never perfect). So maybe 6C/W once I factor in inefficiencies.

KnightExemplar wrote:This 20W resistor is derated by 50% by ~90-degrees Celsius. Granted, that's pretty hot, but I still need to ensure that the resistor doesn't go above 115-degrees (0r +90 degrees over ambient).

Why? The rated max temperature of the resistor is 155C. The derating by ~50% at 90C is referring to a 90C ambient temperature, not the internal temperature rise. The power rating is determined by how much headroom you have between ambient and 155C, because the power rating originates from needing to keep the internal temperature under 155C.

KnightExemplar wrote:Assuming the 20W resistor earlier, the internal thermal resistance is ~6C/W, so the "internal" heat of the resistor will rise to +42 degrees before the ambient temperature even goes up. That leaves 48-degrees that the heat-sink (and heat-sink connection) must handle, over 7-Watts. That's a thermal-resistance of ~7C/W or better (with a perfect connection, which are never perfect). So maybe 6C/W once I factor in inefficiencies.

If your heat sink is exposed to the true ambient of a well ventilated room at 25C, and you're designing for a 7W worst case, then you have an internal resistor temperature of 7W*(6 C/W(resistor to heat sink) + X C/W(heat sink to ambient)) + 25C < 155CSolve for X, the thermal resistance of the heat sink, and you getX < ~12.5 C/W

KnightExemplar wrote:This 20W resistor is derated by 50% by ~90-degrees Celsius. Granted, that's pretty hot, but I still need to ensure that the resistor doesn't go above 115-degrees (0r +90 degrees over ambient).

Why? The rated max temperature of the resistor is 155C. The derating by ~50% at 90C is referring to a 90C ambient temperature, not the internal temperature rise. The power rating is determined by how much headroom you have between ambient and 155C, because the power rating originates from needing to keep the internal temperature under 155C.

Hmm, makes sense.

KnightExemplar wrote:Assuming the 20W resistor earlier, the internal thermal resistance is ~6C/W, so the "internal" heat of the resistor will rise to +42 degrees before the ambient temperature even goes up. That leaves 48-degrees that the heat-sink (and heat-sink connection) must handle, over 7-Watts. That's a thermal-resistance of ~7C/W or better (with a perfect connection, which are never perfect). So maybe 6C/W once I factor in inefficiencies.

If your heat sink is exposed to the true ambient of a well ventilated room at 25C, and you're designing for a 7W worst case, then you have an internal resistor temperature of 7W*(6 C/W(resistor to heat sink) + X C/W(heat sink to ambient)) + 25C < 155CSolve for X, the thermal resistance of the heat sink, and you getX < ~12.5 C/W

Thanks for double-checking the math. I've never done heatsink stuff before, so this is all new to me. That's a lot more headroom, 12.5C/W heatsinks look smaller and simpler to use. 7W is a bit conservative (LTSpice says 4.5W is the worst-case), but being a bit over-specced probably won't hurt anybody. I've found materials that are ~1 C/W connection (the screw that connects the TO-220 and the Heatsink is probably insufficient... I understand the importance of a thermal pad for a good thermal connection).

I'm liking the design of DPAK heatsinks btw. TO-220 (and other DIP packages) seem like the best from a heat-dissipation point of view, but DPAK is directly soldered on the board, and the heat-sink therefore don't need grease or thermal pads: solder is about as good as it gets anyway.

I'm designing for 2W of dissipation on the MOSFET (1.5W worst-case according to LTSpice). 15°C/W heatsink (EDIT: Looks like 15C/W is for some amount of air-flow. 25C/W might be sufficient... depending on the MOSFET I get)

If you're comfortable with circuit theory for electronics, there's a good metaphor to use for thermal stuff. Power dissipation in watts translates to an ideal current source in amps, thermal resistances translate into literal resistors, ground is ambient, and voltages in volts translate to temperatures above ambient in degrees C.

So here, your 7W dissipation in the resistor, with 6 C/W to the heatsink, and X C/W from heatsink to ambient, translates to a 7A current source driving a pair of series resistors, one 6 ohms, one X. Finding the maximum X to keep the temperature below a certain value is then the same as finding the maximum resistance that keeps the voltage below a certain value.

And if you ever have need to work it out, heat capacity in Joules/Kelvin translates to literal capacitors in Farads.

arbiteroftruth wrote:If you're comfortable with circuit theory for electronics, there's a good metaphor to use for thermal stuff. Power dissipation in watts translates to an ideal current source in amps, thermal resistances translate into literal resistors, ground is ambient, and voltages in volts translate to temperatures above ambient in degrees C.

So here, your 7W dissipation in the resistor, with 6 C/W to the heatsink, and X C/W from heatsink to ambient, translates to a 7A current source driving a pair of series resistors, one 6 ohms, one X. Finding the maximum X to keep the temperature below a certain value is then the same as finding the maximum resistance that keeps the voltage below a certain value.

And if you ever have need to work it out, heat capacity in Joules/Kelvin translates to literal capacitors in Farads.

I might need to use that analogy in reverse actually. I've been trying to find a way to explain voltages and currents to non-engineering laypeople, and this analogy seems super useful.

Heat only travels "down" towards cooler temperatures. I've been using the water / downhill analogy but I still get a lot of blank stares.

------

But that seems like a useful way of measuring out heat-sinks and stuff.

I've figured out the 7W and 2W heatsink problems to some extent. The last MOSFET will take the ~4A of current across its 0.04 resistance for ~640mW worst case.

According to TI, a 1cm x 1cm copper pad has ~1000 C/W thermal resistance to the ambient air. This suggests ~7cm^2 is needed to cool down the 640mW on the last MOSFET. However, the SMD-heatsink only takes up 2cm^2 of boardspace. So it actually makes more sense for me to just attach the 2W heatsink on the last MOSFET... at least from a space-saving perspective.

Its going to be a tight fit. The bunch of 0805 components on the left are the 17 resistors that the board uses. The big yellow-splotches are representative of the three heat-sinks I'm going to be using (under the yellow splotches are two "control" NMOSs Q1, Q2, and 0.4 Ohm R1). I'll have a more reasonable silk-screen representation of the heatsinks later, but for now I just wanted to get a general idea of the size of them.

Ah crap, I forgot to place my push-button on the board. But I think there's room enough for the push-button. I'm just hoping that my layout skills can accomplish this. Beyond that, the TO-220 Heatsink (the 0.4 Ohm Resistor) is so large it needs some "support holes". It probably would do me good to CAD out the TO-220 and the Heatsink so that I can get a good estimation on where those support-holes will be.

BTW: yes, the LCD screen is sticking out of the board. I need every inch of space I can get. All of a sudden, I feel like I should have used 0603 components instead of 0805. It does look like I'll be able to make it all fit... but I need to be efficient with my routing and placement.

While laying out the board, I noticed a couple of errors on my schematic (again). Always be fixing the design... right? I figure that I'm going to have a major mistake in the first prototype, but I want to get it as "correct" as possible nonetheless.

I just really want to make sure that those PCB-holes are in the right place. I CAD-ded out those designs myself, it is relatively simple when you have the documentation. Its all "representative"... I'm really only interested in figuring out where the holes go. In any case, I have a good idea what the footprint should look like.

EDIT: And... of course it ain't legit. First try to this thing and of course I fuck it up. I was double-checking some things and it looks like I messed up a measurement or two here and there. The fixes are minor (you wouldn't notice them by just looking), but I'm like 0.05" off... which is enough to make things "not fit" in practice.

Spoiler:

I'm thinking this new footprint is the "most correct" one.

-----------

EDIT2: Actually, I probably should just order the damn Heatsink and then measure it. Lololool. The only way to be 100% sure. I can design with my calculated footprint while the parts are getting shipped.

Edit3: Holy crap. The Heatsink isn't in stock at Digikey. It won't ship until mid-April... uggghhhhhh. This is fine, I'll just continue designing the board, take some measurements when the Heatsink comes in and verify the results then.

This process is far more annoying than I initially thought it would be.

I'm quite inefficient at this. I've laid out a bunch of things, only to realize that there were components (the X1 crystal specifically) that needed to go close to the Microcontroller. Then I needed to shift everything over to "make room" which caused a whole bunch of issues somewhere else on the board. Etc. etc. etc.

Long story short, 2ish hours and I'm only in this far. A lot of components to lay out still. Fortunately, it looks like I have a bit more room than I initially thought, but at the moment... a lot of components are uncomfortably close to each other.

"Fortunately", I have plenty of time. The Digikey shipment for my Heatsink won't come until mid-April, which is necessary for final measurements before I order the PCB.

A few more hours, and I'll tell you some mistakes that were in my original layout above.

Spoiler:

I probably won't catch every mistake, but I need to keep my eyes open for every mistake that I can catch on the first run. Each of these attempts will cost me $60 + shipping + hours to solder everything on... I'd love to get it right on the first try as unlikely as it is.

Here's my board design as it is now.

Spoiler:

Annnnnndddd.... crap. C5 is fucked up. Well, that's why I do this, to catch mistakes. Since the Heatsink won't come in till 4/9/2017, and I don't trust my CAD-skills enough... I'm going to basically be doing design checks between now and then. No point shipping this off before I verify the Heatsink actually has that size.

Well, none of that changes the final schematic! Lol. So might as well show that.

Well, that company seems like a pretty good US supplier. The other US suppliers are 4pcb.com and expresspcb.com. I haven't used any of these... I initially started my project on expresspcb because of the cheaper price ($61 for the Miniboard Pro). But similar specs on "Basicpcb.com" are $51 with free shipping... on a 1oz minimum board (slightly higher quality than the 0.5oz copper at ExpressPCB).

Considering the huge amount of copper I'm using as a heatsink, the 1oz (or more) board at "BasicPCB.com" will be beneficial. Bonus points for them supporting standard "Gerber" files, so I can switch over to the better long-term solution KiCAD.

I was thinking of good ways to test out my Heatsink calculations, now that I have my real heatsink in.

It turns out, that my printer is actually quite accurate. Paper-prototype ftw. Looks like my calculations were right

With that said, I'm going over my PCB design with a fine-toothed comb. I printed out a 1-to-1 scale of the placement of stuff. I've left no room for standoffs (oops) and other simple mechanical objects. In any case, it looks like a relatively tight fit. My next adventure will be soldering such tiny components.

Ah well, that's why I'm ordering 3 boards. If my first time soldering sucks, then I just try, try again. (There is no "try try try try" however... I gotta get it right within 3 tries.)

------

In the meantime, I've bought an ATMega development board and will be figuring out the software stuff with some basic I2C chips and such. Maybe I should hold off on the order until I get a few software tests / prototypes in with the development board...

I've been getting some cold feet on this project for a number of reasons:

1. I've come up with a few minor design issues: I want the board to be placed onto standoffs at very least, so I need to make room for some screws and standoffs. In addition, I want to replace the bare-wire solder point (for the power connector) with a Barrel Jack connector. There were a few more misc. errors but yeah, I got a little bit of work left on the board before I think its completely ready.

In any case, the four corners of the board are all "taken up" already. I'll have an awkward location for the 4th standoff (the LCD screen is too big regardless: its going to be hanging off the board a little bit). Overall, I just haven't thought of the 3-dimensional shape of the project at all. (I'm thinking standoffs + maybe a wood / cardboard base?)

2. My original plan to hand solder with an iron these SMT components has been met with exasperation at the tiny size of the SOT-23 parts. I know the 0603 parts and 0805 parts will be roughly the same size, so now I'm looking into Hot-Air rework stations. I am not going to drop $800 on a Hakko here, but the cheap crap from Amazon looks like they might literally kill me. So I'm going to compromise and go for maybe... this unit?

3. I've bought a number of parts (not all of them: but the Heatsink and stuff) and they're just sorta... lying around. I'm buying a new bookcase for my lab (aka: currently just a table with some portable storage bins by it) to organize things a bit better. Another note: I got a few order numbers fucked up with Digikey, wasting money and also giving me a few parts I don't need. So a decent storage location just needs to be figured out.

4. A couple of other projects are beginning to pop up that demand my attention in the short term. Hopefully I can get back into the swing of things here.

KnightExemplar wrote:I've been getting some cold feet on this project for a number of reasons:

1. I've come up with a few minor design issues: I want the board to be placed onto standoffs at very least, so I need to make room for some screws and standoffs. In addition, I want to replace the bare-wire solder point (for the power connector) with a Barrel Jack connector. There were a few more misc. errors but yeah, I got a little bit of work left on the board before I think its completely ready.

In any case, the four corners of the board are all "taken up" already. I'll have an awkward location for the 4th standoff (the LCD screen is too big regardless: its going to be hanging off the board a little bit). Overall, I just haven't thought of the 3-dimensional shape of the project at all. (I'm thinking standoffs + maybe a wood / cardboard base?)

I tried to make room for standoffs, but even #4-40 screws (Roughly ~Metric-3 Screws) took too much effort to find room for. So instead, my new plan is to simply create standoffs out of tape or some other simple material. It'd be crappy, but its all I really can do at this point. Next time, I'll be sure to include room for standoffs early in the project.

For the Barrel Jack Connector, all I have to do is make a wire-based one off board. I do have the + and - pins for what was going to be a battery attachment... but might as well make it a somewhat flexible design with a 5.5x2.1 barrel jack (the same barrel jack used by an Arduino).

Basically, its too late now for me to add these features on-board. I'll just have to keep those kinds of things in mind next time.

The transistor I designed this project is out of stock until May 25th on Digikey (and is out of stock until July in Mouser).

The MOSFET is marvelous. It has a guaranteed Vgs-Threshold under 1V, its in SOT-23 form factor and is specified to handle 8Amps of current (The heat is drawn out of 4-pins to the copper pad with a Thermal-Resistance of 30C per Watt). Most of the larget DPAK MOSFETs have higher Vgs-Thresholds (although far better thermal characteristics). In any case, its too late for me to change the design now... I've already ordered the PCB without realizing that the chips were out-of-stock for the next 10 weeks.

EDIT: well, crap. Looks like Vishay.com has an excellent filter / search for this sort of thing. I think I found like... 7 or 8 different transistors that have better specifications for this project. Uggghhhh... well, too late to change in any case.

Ah well. That gives me plenty of time to test out the rest of the board. I probably should have designed the whole circuit to work with a more common transistor, but live-and-learn I guess.

I decided to make the first board regardless of how fucked up of a job I was doing. I have to more tries... and I'm fairly certain I'm fucking up my first attempt anyway.

I don't have the MOSFETs, but it doesn't matter. I'm going to test the other parts of the design. I have two tries left. Lessons from soldering:

1. Tinning the pins by hand with a soldering iron sucks. Next time, I'm buying Solder Paste.

2. The Hot Air Gun, even on its lowest setting, blows parts around the board if I get too close. Blowing "straight down" prevents the components from flying off... but I bet that Solder Paste would be sticky enough to prevent the issue. (Going back to #1: I probably should have used Solder Paste).

3. Order matters: don't put plastic parts on first, since those parts will melt as the hot-air gun passes over them.

4. Surface Tension is awesome. Parts will automagically move into place to some degree.

5. 0805 and 0603 (Metric 2012 / 1608) parts are perfectly doable with a hot-air gun. But they're so small that they're easy to lose.

6. Buy additional parts: I fortunately only lost a few components I had plenty of spares of. But parts will fly off the board due to the hot-air gun... your shaky hands will accidentally throw those tiny parts off the desk and into the void (I'm never going to find an 0805 part hiding in my carpet...) and so forth.

Ouch. If I ever do something like this I'd carefully find all the through-hole parts left in the digi-key catalog and use them first. Then figure out what is left in [relatively wide pitch] SMT.

Solder paste is typically done with a solder stencil. Typically made (and with similar costs) to PCB. I doubt you would want to cut away one yourself with an x-acto knife. Hand painting the board with paste might be a possibility, but I'd consult someone who has done it.

I'd think twice before using a hot air gun. The only time I've seen this done used a toaster-oven [don't plan on using for food ever again even if you used lead-free solder, so check a few yard sales]. I'd expect it to be just has hard on plastic components. You should also get better control of temperature with said oven (although I think it had a thermocouple inside that fed into a voltmeter outside - this was then used to manually control the temperature).

wumpus wrote:Ouch. If I ever do something like this I'd carefully find all the through-hole parts left in the digi-key catalog and use them first. Then figure out what is left in [relatively wide pitch] SMT.

The plastic-bit was a through-hole part, and your thought process is exactly which is why I put it in first.

With more research, it seems like the prevailing theory online is to do the opposite. SMT devices are designed to withstand a reflow-oven at ~300+ degrees Celsius, and are therefore the first devices you are supposed to populate. Through-hole parts are generally designed for wave-soldering or hand-soldering. So they don't necessarily withstand the higher-temperatures.

Solder paste is typically done with a solder stencil. Typically made (and with similar costs) to PCB. I doubt you would want to cut away one yourself with an x-acto knife. Hand painting the board with paste might be a possibility, but I'd consult someone who has done it.

Yeah, that's my plan. I was going to just follow some youtube videos on the hand-done solder paste thing.

I'd think twice before using a hot air gun. The only time I've seen this done used a toaster-oven [don't plan on using for food ever again even if you used lead-free solder, so check a few yard sales]. I'd expect it to be just has hard on plastic components. You should also get better control of temperature with said oven (although I think it had a thermocouple inside that fed into a voltmeter outside - this was then used to manually control the temperature).

The hot-air gun technique was actually pretty easy overall. Now that I'm used to the quirks, I can definitely say its superior to soldering. A number of components "Tombstoned" on my first try. The surface-tension effect is quite strong, and may accidentally lift a piece sideways. The only way to correct these mistakes is to use a hot-air gun and tweezers.

So regardless, I needed to get the hot-air station. Because with ~40 components on the board, a few of them would have tombstoned (or otherwise become defective in some manner).

-------

In any case, the toaster-oven trick was part of my research, but my home lab is relatively small (Its also my workout room). I don't have the space to keep buying specialized tools and storing them. So if I can do this without a toaster oven, I think I'll do it.

With that said, if I were to buy a "cheap reflow oven", it'd be the electric-skillet with sand trick. (Cheap Electric Skillets from Walmart heatup unevenly. So you pour sand on the bottom to spread the heat around a bit better, and then put the PCB on top of the sand.) The skillet has the advantage that the top is open, so you can work on the PCB as it heats up (ie: push "tombstoning" parts back down with tweezers or whatnot).

Holy fucking shit. The programmer can actually talk to the ATMega328pb!

Not saying the whole circuit works: but clearly the buck-converter was correctly designed (what gives power to the whole board). Furthermore, the ATMega's debugging ports were set up correctly too.

That leaves the final parts of my design:

1. The LCD screen (the backlight works, but I'm going to have to program some routines to actually send something to the screen).2. The 32678 Hz Clock (I have no way to really calibrate the clock either. I'm just gonna have to hope that my estimates on parasitic capacitance don't skew the clock too off... or come up with some sort of calibration program)3. The MOSFETs (which aren't even on the board yet).