Breaktru Forum
eCigarette Forum => Modding => Topic started by: norcalreballer on November 26, 2014, 04:22:57 PM
-
I'm using a 3.3v atmega328p(arduino pro mini)for this project. Mosfet is IRLB3813(fully saturates at 2.5v). 2.5v 0.05% external voltage reference(lm4040 2.5v). I'm working with it at the default 480hz.
My original idea was to use an N channel MOSFET and get the average atty voltage using a filter. Well, that's bogus due to the low side being switched and the MCU references ground that's constant. Next, I used an NFET to switch a PFET that handled the load. I couldn't get the Pfet by itself to work, but that's another story. The PFET I'm working with works, and I can parallel them, but there's another issue. I added the filter and calibrated the average against the scope reading of the average.
Problem here is the mean isn't what the atty is putting out, it's much higher, especially at lower duty cycles. After talking to people, I learned that RMS voltage is what we need. I figured I can ditch the analog input for the atty and use this idea I had. I mapped the 8 bit 0-255 for analogWrite to 0-100 for duty cycle. I'm using a voltage divider(2s iput)to get battery voltage. Since the battery voltage is the peaks, I tried this:
rmsVoltage = peak * sqrt(dutyCycle / 10)
The idea works. :) To control the rms voltage at the atty, I tested with a few simple if statements. Not code, just for the idea.
If attyVoltage < rmsVoltage dutyCycle = dutyCycle + 1
If attyVoltage > rmsVoltage dutyCycle = dutyCycle -1
if attyVoltage = rmsVoltage dutyCycle = dutyCycle
What happens now is the battery voltage is jumpy due to sag. To fix this, I'm averaged the analogReads to the point where it regulated the rms voltage pretty well. :) It is a bit slow, but it can be worked out. I'm using 2 18650's, so sag does seem to cause an issue. I think a 2s lipo would be much better, since it wouldn't need so much averaging due to less sag.
The final real issue is that it sure doesn't seem like it's putting out 5.5v when it says it is. If I have time before my next job today, I'm going to check it out on the scope to see what's going on. Do you see anything wrong with my math or anything else? I'm thinking about using much higher PWM frequency. I would think that would really smooth it out.
I'll look into hacking the frequencies on this little 8mhz MCU.
-
RMS power is peak voltage squared over resistance times duty cycle (Vp2/R*D). RMS voltage is peak voltage times the square root of duty cycle (Vp*D1/2). I don't understand where the divisor of 10 is coming from in your equation.
You should flag a low battery at a voltage measured under load. For example, if you flag a low battery at 2.5V per cell and that's measured no load, then voltage could drop as low as 2V per cell under load which would over-discharge the battery. Keep in mind voltage sag greatly increases as the battery approaches a discharged state.
For a battery fuel gauge you can use the battery voltage measured with no atomizer load. It's going to be more accurate than gauging the battery under load since load can vary and thereby voltage readings will vary.
In terms of how you obtain voltage readings, you need a filter of some kind or you'll get jumpy readings from your ADC. You can use a hardware filter or a software filter (averaging). Either will work, but I prefer a hardware filter since it also reduces sensitivity to sample and hold times for the ADC.
Also as the load is cyclic, you need to consider that as well. You need to time your ADC samples to occur toward the end of the pulse rather than trying to average readings over several PWM cycles (which would be ridiculously slow anyway). It shouldn't be a problem, a typical ADC can take samples orders of magnitude faster than the PWM frequency.
-
I'm not worried about under voltage protection yet. This is an extra parts build and to try to control the mosfet + PWM. I'm also not adding any way to measure resistance in this build.
The divisor of 10 is because the map function will only work with integers. I get the wrong value without it. That wasn't actual code there. I have a different variable and divide the duty cycle by 10 so the calculation comes out correctly.
I upped the frequency and it doesn't help all that much. I'll know more when I get the scope on it. :)
I'm using software averaging now, but I have plenty of capacitors. I'll have to look into timing the reads. Thanks!
-
I understand that now. When using an MCU that does not have a floating point ALU (most of them), it's a good way to eliminate the need to handle decimals in code. I do that myself all the time. So yeah, it's a nice trick to eliminate a lot of extra coding. However, I usually multiply by some factor of ten then simply shift the decimal point in the display.
A hardware filter for the ADC eliminates the need to average in code so you only need to take one sample instead of many. This can be helpful when measuring cyclic outputs, but then the down side is you need to consider the time constant of your filter. If your filter time constant is too big, the reading won't settle within the pulse length. If the time constant is too small, it won't filter well enough to stabilize the readings. It can be a bit tricky to work out.
In terms of PMOS versus NMOS, for some cases an NMOS is perferable to a PMOS, but in your application peak voltage is always high enough to provide a gate-source voltage that minimizes on-state resistance for the transistor. Typically N-channel MOSFETs have lower on-state resistance than P-channels, but a PMOS should work well if there's a reason you need to use one. It just takes more careful selection for a PMOS since it's harder to find ones with really low on-state resistance.
Also as P-channel MOSFETs have higher gate charge, you should be using a driver for one. Alternately you can slave it off a small power MOSFET having minimal gate charge. The I/O pins on the MCU have about 50 Ohms resistance so they are limited in how much capacitive loading they can drive. The gate-source connection for a PMOS with very low on state-resistance is like a 10nF capacitor, but it varies depending on the transistor, some lower some higher.
-
Oh, I got a little off track.. This design is only using an nmos. I'm going to try a hardware filter. :)