Advice wanted for measurement of low ohm coils with microcontroller ADC. Negative voltage protection needed.

MisterBill2

Joined Jan 23, 2018
28,690
This has become rather confusing: What I get is that the goal is to regulate the wattage rather than the temperature. If that is a correct understanding then it is quite different from temperature control systems.
If that is not the case, then I have become confused.
 
Last edited by a moderator:

Thread Starter

farm_tinker

Joined Nov 20, 2025
37
Thank you!

U2 (MCP1640D) is my 5V switcher. It gets me 5V from the single cell lithium. When disabled it goes into passthrough and the 5V rail drops to battery voltage. That's why I labeled the supply +5V(3V3). As the microcontroller spends most of its time asleep, for battery life, the 5V rail is actually at battery voltage and buck-boost is disabled. U4 has the 4.2V lockout and enable pin tied in. I can probably just tie U4 enable to +5V, but the pin was there and I already had the signal. U1 (ATtiny 3224) enables U2 and U4 and waits for the voltage to come up before increasing its clock and starting the PWM. I do need to make sure that I have enough current to prevent sag when this thing is fired for both U1 and it's clock as well as the U4 and its UVL0.

Is labeling that supply +5V(3V3) wrong or is there a standard way I should label it?

As for SW/GNDA: my error caused me to think I could also combine the decoupling for VDDA and VDDB and save a couple of caps. I now think I have to decouple the output supplies separately. Can I decouple to GND or do I need to do it individually with VDDA to GNDA(SW) and VDDB to GNDB(Negative rail)?

U4 is a pretty neat chip and I'm totally hunting rabbits with an elephant gun, but it will allow me to play with the high and low side signals/deadtime. My final version will likely use TI TPS28225 and a single PWM signal. I planning on proto boarding both versions.

What I get is that the goal is to regulate the wattage rather than the temperature. If that is a correct understanding then it is quite different from temperature control systems.
Right, the output is in no way critically toleranced or tightly regulated. It's an ecig and the user literally just adjusts the power level to taste. This project is really me teaching myself about SMPS. There are simpler ways to do what I'm doing. It has forced me to get a much better understanding of inductance/coils/MOSFETs/negative voltage/etc. It has totally been worth it as well.
 

MisterBill2

Joined Jan 23, 2018
28,690
OK, and interesting! My take is that the load is a single heating element that probably does not change resistance much or often. So a simple voltage control should be "good enough." What I don;t see is any mention of the unregulated voltage that powers it. Is it a small battery?? or some sort of mains operated supply??
Does the desired temperature change?? or not??
 

Thread Starter

farm_tinker

Joined Nov 20, 2025
37
@MisterBill2

Load is a single heating element, it's referred to as a "coil" because it's a tiny heating coil and the inductance of it would only matter if it affected operation, which it shouldn't. We've used the same resistance heating elements for years (1.6ohm @ 14.5-14.8watts), but I'm reproducing as much of the function of the original as I can. It reads the coil resistance and shows it on the display. It claims an output of 7-50W (with some doing 75W), coils from 0.3-1.6ohm. Has three buttons on the face, two for wattage +/- and one for fire. Temperature isn't measured even though heat is doing the work. While the display is in watts, it is quite possibly not accurate. It could be in units of bananas for all it actually matters, just gotta be able to turn it up and down.

This is not one of the ecigs that creates giant obnoxious clouds and is the size of a hand grenade. It's small and discrete.

What is actually critical for the design is that the form factor and UI be very similar. If not, my wife will never accept it and it won't fit in my shirt pocket the same. This thing is literally always with me, and I stick it under my pillow at night as does my wife. (I've made peace with my nicotine addiction, and this is the best harm reduction route I see, my pipes and cigars are for when I want real flavor.)

I will be putting the switches on daughter boards so that when they die, I can just change out for another daughter. Especially the main switch. I will likely put the adjustment switches inside the battery bay and add a switch so that I have +/- and an additional menu or set button. Since the ATtiny 3224 supports a watch crystal, I'm going to add a clock to the display, that would be real handy. I'll probably also add a click pattern on the main button that turns it into "flashlight" mode such that the entire screen lights up white. I already use it to navigate at night and it would be nice to have more light that stays on longer.

The form factor requires that my supply be a single 18650 lithium battery. The board is a little bigger than a 1/2" wide and 3" long. USB charging like the original would be nice to have, but we rarely use it. I'm considering adding a small super cap so that it doesn't lose time when the battery is changed.

So, 18650 single lithium gives a supply of 4.2-2.7V. The ATtiny can run at all of those voltages. Most of the time it will be sleeping on the battery voltage. When activated, it enables the 5V switch IC. When it's up to 5V, it sends drive PWM and rectifier PWM to the drive IC. That drives a couple logic level MOSFETs working from battery voltage across an inductor. 1.5uH in the original, not sure what inductance I'll end up on. I've got a 6uH inductor that can handle the amperage, but I may use 1.5uH. Need to study it more. This is an inverting buckboost, so it's negative voltage, but it doesn't matter for a heating coil.

Hoping to end up with at least a 25w SMPS. Like I said above, I probably will use a different driver IC ( TI TPS28225), than what's in the circuit now. It just needs a single PWM signal and handles deadtime.

However, I've managed to torture the ATtiny into producing dual signals with 50ns deadtime at 315kHz and the ADC is overclocked to double its rating at 615ksps or so. I've bench tested it and have a compensation function working for the ADC. Much of the signal generation is handled by twisting the programmable logic, event channels, and internal propagation delays. I produce most of the waveform from a single channel of the TCA0, with the TCB0 timer in single shot mode doing deadtime. Signal generation is autonomous from the CPU when running. The ADC is freerunning. The CPU is only grabbing ADC samples, doing a quick check, and adjusting the duty if needed. I'm able to adjust the output within 32 cycles (1.6us) of a change on input.

I think I'm almost to the point of working up my BOM and soldering up a proto test board. I've been working on this for about 6mo? Maybe longer.

So, I just really want to see if this thing will fly before I use a simpler drive IC and save another pin on the 3224.
 

Thread Starter

farm_tinker

Joined Nov 20, 2025
37
Back to the original topic. Why doesn't this work? Q1 collector never sees the negative voltage or am I missing something about the nature of transistors?

1792145640449.png

1792145411799.png

1792145431781.png

1792145452339.png

1792145464363.png
 

MisterBill2

Joined Jan 23, 2018
28,690
What I do not recall is seeing actual component information, especially leakage currents. Perfect components are terribly costly, so in the real world we are using those parts that are not exactly perfect. That switch is niether zero ohms in the on condition nor a true open circuit in the off condition. and if it is using the same power supply as the processor board there is a snaek path for leakage current. ALSO, one-terminal voltage measurements are ALWAYS suspects, as I see it.
 

Thread Starter

farm_tinker

Joined Nov 20, 2025
37
So let Q1 be a 2N3906 and the switch contains an elf with a very small knife switch. He's hooked up a tiny light bulb to the control signal and ground and throws the switch to -5V when it's on.

The PNP can switch the divider no problem if it's done in that order. Hopefully the elf isn't leaking or he's going to be in big trouble.

If the switch is actually a SMPS such as my earlier schematic, I would need to puzzle on what a fluctuating negative voltage does up stream to the PNP. Not much, I think, but I haven't looked at it deeply.
 

MrAl

Joined Jun 17, 2014
13,933
Wasn't sure if this belonged in Power Electronics, Sensor Design, or here. Please move if I put this in the wrong forum.

I'm puzzling over how to measure my load resistance in this part of my circuit:

View attachment 371798

in the above schematic is a SMPS that produces up to -10V or so while in operation. Control lines and most of the rest of the circuitry is omitted. When the the SMPS is not in operation, I need to be able to take a reading on the load and determine its resistance for power calculation.

I'm leaning towards a LM1117 (low dropout LM117) or similar IC setup as a constant current source of around 50mA. I might be better off with a pnp/diode current source, not sure what the prevailing wisdom is on this.

(I've also looked at the LT3092 as a current source but I don't like the price tag of that chip. Not that the price of individual chips really matters for this design as I'll likely only ever make a few.)

Basically, I want to inject a few mA on the side of the coil opposite ground when the SMPS is not running. Then, I'll take an ADC measurement on the voltage to get the resistance of the coil. This would be a short duration event, on the order of a few hundred microseconds. My ADC has a gain amplifier and also does differential measurements. While I'm hoping to avoid differential, using some gain shouldn't be a lot of trouble and should get me the accuracy I need. Hoping for 0.05ohm precision but .1ohm is probably just fine.

I have a budget of 5V and 100mA for the current source. I'm looking at source and not sink as the coil will have a load of several amps in operation and isolating it from ground probably isn't practical. I want to be able to turn off the test current when not in use. What sort of circuit/IC should I be looking at for this?

As for the ADC, it will tolerate exposure to voltages from -0.5V to 5.5V. If I understand this correctly, the 0.7V drop of a signal diode will prevent me from measuring the low voltage produced by my current source and load. How can I protect my microcontroller and still take an accurate reading?
Hi,

One simple way is to pump 100ma through the resistive load, then measure the voltage across it and convert to Ohms.
[NOTE: Ron back in post #3 mentioned this also so check that out too].
Of course the voltage will be very low, so you need to amplify it before the measurement. You can do that with an op amp with a gain of 10 to maybe 25.
A short table of Ohms and readings with 100ma and no gain and with gain of 20, and approximate 10 bit ADC counts with a 5v reference:
0.25, 25mv, 0.500v, 102
0.50, 50mv, 1.000v, 205
1.00, 100mv, 2.000v, 410
2.00, 200mv, 4.000v, 819

That's not terrible, and a 12 bit ADC would be even better.
One of the main things is to use separate wires for current and voltage, and voltage is measured close to the leads of the device under test.
One of the other main things is to use a special type of op amp that has very low input offset. A chopper stabilized op amp is good for this.
Another thing is to use averaging, which is almost like oversampling which gives higher resolution if done right. Averaging means take as many readings as possible and divide by the number of readings. If you want a continuous reading, look into calculating a moving average. That's where after the first N samples you get continuous average voltage updates you don't have to wait another N samples to get the next reading.
 
Last edited:

Thread Starter

farm_tinker

Joined Nov 20, 2025
37
Howdy,

I think the above resistor divider is actually going to be pretty close to what will work. I need to understand a little more about the transients on my output. (I think transient is the right term.) I don't think they'll be big enough to hurt my microcontroller or mess up my ohm reading, but I'm wondering/guessing if I need a choke or decoupling caps on that divider out. I'm going to do some reading.

Using an ATtiny 3224. It has a pretty nifty ADC including a programmable gain amplifier, internal/external references, differential, etc. It also has hardware accumulation/17 bit oversampling. So, I shouldn't even need an opamp. It has an internal reference at 1.024V, between that and the PGA, I think I'll be able to get more precision than I need. (which is only 0.1ohm for 1.6 to 0.3ohms IIRC.)

Right now, the plan is to run a calibrated low duty pulse cycle on the SMPS and use that voltage to measure the resistance of the load. At run time, it will use the measured load resistance and feedback from the same divider to regulate the working output. That way I save pins and components. No need for a constant current source.

What's really been tripping me up is fluctuating negative voltage and interacting with it from a GND/5V system. I've had trouble really understanding it.
 

Reloadron

Joined Jan 15, 2015
7,982
Hi,

One simple way is to pump 100ma through the resistive load, then measure the voltage across it and convert to Ohms.
Of course the voltage will be very low, so you need to amplify it before the measurement. You can do that with an op amp with a gain of 10 to maybe 25.
Hi Ya Al. Back in my Post #3 I suggested doing that and mentioned an A/D which would work just fine since the thread starter mentioned uning a uC. My thinking was the thread starter wanted to measure the resistance of a heating element or similar. I finally gave up as I had no idea what the TS actually was looking to accomplish. I never saw mention of what uC the TS was using?

My ADC has a gain amplifier and also does differential measurements. While I'm hoping to avoid differential, using some gain shouldn't be a lot of trouble and should get me the accuracy I need. Hoping for 0.05ohm precision but .1ohm is probably just fine.
As I would always respond "Beats the hell outta me Lieutenant". :)

Ron
 

Thread Starter

farm_tinker

Joined Nov 20, 2025
37
It's an ATtiny 3224. Has an integrated ADC with PGA and all the other bells and whistles.

I had concerns about it being exposed to negative voltage that would fry it.

I'm trying to minimize components as much as possible. So I'm resistant to adding anything I don't absolutely have to. It's already a complex circuit and isn't finished.

I was originally thinking I needed a constant current source to run across the heating element. However, I already have to have a divider that measures negative voltage. I decided that to save components and complexity, I would just use the divider and the SMPS to measure the resistance. So, there's some confusion there probably.

I then was working on understanding negative voltage and being able to switch the divider on and off. I think I've got a good enough solution and I'll post it tomorrow if I have time.

Keep getting lost in the weeds, there were errors in the full schematic (work in progress) that keep blowing up the scope of the original question. So it got messy.

Not sure what the right way to handle it is. If I don't post the full schematic, I end up going, "yeah but" to a lot of responses. Which is understandably frustrating to folks nice enough to try and help.

I post the full circuit and it takes a machete and a map to get back to the question.

IDK. I really do appreciate the help and I swear I'm not trying to be a punk.
 

Thread Starter

farm_tinker

Joined Nov 20, 2025
37
PA7 is the ADC input. TLV70245 is 4.5V/300ma with an enable. Negative voltage not present when TLV70245 is enabled. Uses same enable signal that the 5V supply uses. I need to look at what happens when the 4.5V and 5V are enabled at the same time. R7 and R8 are 1/2watt. Should be good up to 25W with a 1.6ohm load.

I think this does it:

1792405668564.png
 

MrAl

Joined Jun 17, 2014
13,933
Hi Ya Al. Back in my Post #3 I suggested doing that and mentioned an A/D which would work just fine since the thread starter mentioned uning a uC. My thinking was the thread starter wanted to measure the resistance of a heating element or similar. I finally gave up as I had no idea what the TS actually was looking to accomplish. I never saw mention of what uC the TS was using?


Ron
Hi Ron,

Oh ok sorry, I would have mentioned that too, but I can add it.

[LATER] Added :)
 
Last edited:
Top