Breaktru Forum

eCigarette Forum => Modding => Topic started by: Breaktru on February 10, 2012, 07:34:34 PM

Title: 1st Attempt w/ a Microcontroller
Post by: Breaktru on February 10, 2012, 07:34:34 PM
Just received my micro-controller parts and slapped together a circuit and a program for a mod. Got it all working with a Basic LCD display as a prototype.
I will attempt to use the OLED display shown which is real small and thin which would be perfect for a small box mod.
The controller is also tiny. The photo shows it hooked up to a FTDI breakout board which is need ONLY for programming. Once completed, the FTDI and cable will not be needed.
I am also looking into a MCU chip which is ¼ of the price of the controller used ($5). I can program it from the MCU shown in the photo.
I can't believe I pulled it off with only one day of experience with a micro-controller. Anyway it's a nice toy to play with.  :laughing:

(http://breaktru.com/ecig/mcu1.jpg)(http://breaktru.com/ecig/mcu2.jpg)(http://breaktru.com/ecig/mcu3.jpg)(http://breaktru.com/ecig/mcu4.jpg)(http://breaktru.com/ecig/mcu5.jpg)
Title: Re: 1st Attempt at Microprocessing
Post by: fsors on February 10, 2012, 08:05:51 PM
Very Cool Dave! Congrats! I look forward to seeing what you create with it! :applaude: :thumbsup: :rockin smiley:
Title: Re: 1st Attempt at Microprocessing
Post by: Dznutz on February 10, 2012, 08:51:02 PM
hmmm dang you Break now I feel I n eed to play as well.  :laughing2:  but good job looks good so far  :begging:
Title: Re: 1st Attempt at Microprocessing
Post by: Dznutz on February 10, 2012, 08:53:58 PM
Did you use the code from the site I posted or did you write your own?
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on February 10, 2012, 09:07:01 PM
Did you use the code from the site I posted or did you write your own?

No Dz. Got some ideas from Goggling and had to edit/add what I needed. I have a little "C" programming knowledge from years back. Mind you I said a little. Can only do basic stuff in "C". Also know a little "C+" and "C++". Mostly do Visual.Net Basic with my other software. All self taught from books. I was a DUNCE in school. Went to a Vocational/Trade High School
Title: Re: 1st Attempt at Microprocessing
Post by: Dznutz on February 11, 2012, 01:35:14 AM
Yeah well me 2  :D but still looks like it is coming together for you  :yes"
Title: Re: 1st Attempt at Microprocessing
Post by: fsors on February 11, 2012, 04:35:15 AM
I do not care wHAT SCHOOL YOU WENT TO YOU ROCK!!!! :rockin smiley: :rockin smiley: :rockin smiley:
Title: Re: 1st Attempt at Microprocessing
Post by: Dznutz on February 11, 2012, 12:23:29 PM
I cant wait to see what you come up with because you make some kick ass mods
Title: Re: 1st Attempt at Microprocessing
Post by: CraigHB on February 11, 2012, 05:39:37 PM
Very nice, should be able to come up with something really cool using that.

I'm also programming my project right now, though I'm using assembly.  C is actually easier and faster, but there are still some of us old assembly die hards out there.
Title: Re: 1st Attempt at Microprocessing
Post by: Breaktru on February 11, 2012, 07:27:13 PM
Very nice, should be able to come up with something really cool using that.

I'm also programming my project right now, though I'm using assembly.  C is actually easier and faster, but there are still some of us old assembly die hards out there.

Wow Craig that's fantastic. Looks real cool. Can't wait to see it in a mod. Man that's a lot of circuitry. Is that the Boost circuit that you've been working on? I guess you'll be using the Li-Po 20c cell with that.
Title: Re: 1st Attempt at Microprocessing
Post by: CraigHB on February 11, 2012, 10:03:42 PM
Thanks Dave,

The board sits on top of this (http://www.hobbyking.com/hobbyking/store/__18558__Turnigy_2200mAh_1S_20C_Lipoly_Single_Cell.html) 2200mAh 20C LiPo.  The cell tabs bend around and solder to the board on the left next to the USB charging connector. 

Unlike Arduino, programming for the 16 bit PIC I'm using is done though a 5 pin header and a PICkit2 programmer/debugger.  Hard to make out in the photo, but the programming header is right under the red clip.  My photos suck because my camera is on the fritz and I still haven't replaced it.

The extra chips on there are things like small signal mosfets to isolate controls from the MCU and voltage detectors for safety features.  It senses a lot of different stuff for safety features like over-discharge protection, over-current protection and atomizer short-circuit.  It also has charging onboard with a full suite of safety features like battery temperature sensing and transient voltage suppression.  I tried to keep the parts list to a minumum, but the component counts always grow fast when you start adding features, and I have just about every feature I can think of.

I use the boost circuit that I emailed to you in that schematic before.  It can put out 30W.  Let me see if I can get a photo of it at max output.  It's tricky to photograph because my home-made load bank overheats at that output so I can't leave it on too long, though the booster itself can output 30W continuous without getting too hot.  I call it my Powerblock.  Of course my wife calls it the "stop going to bed so late e-cig".

Okay here we go. 
Title: Re: 1st Attempt at Microprocessing
Post by: Breaktru on February 11, 2012, 10:45:59 PM
Thanks Dave,

The board sits on top of this (http://www.hobbyking.com/hobbyking/store/__18558__Turnigy_2200mAh_1S_20C_Lipoly_Single_Cell.html) 2200mAh 20C LiPo.  The cell tabs bend around and solder to the board on the left next to the USB charging connector. 

Unlike Arduino, programming for the 16 bit PIC I'm using is done though a 5 pin header and a PICkit2 programmer/debugger.  Hard to make out in the photo, but the programming header is right under the red clip.  My photos suck because my camera is on the fritz and I still haven't replaced it.

The extra chips on there are things like small signal mosfets to isolate controls from the MCU and voltage detectors for safety features.  It senses a lot of different stuff for safety features like over-discharge protection, over-current protection and atomizer short-circuit.  It also has charging onboard with a full suite of safety features like battery temperature sensing and transient voltage suppression.  I tried to keep the parts list to a minumum, but the component counts always grow fast when you start adding features, and I have just about every feature I can think of.

I use the boost circuit that I emailed to you in that schematic before.  It can put out 30W.  Let me see if I can get a photo of it at max output.  It's tricky to photograph because my home-made load bank overheats at that output so I can't leave it on too long, though the booster itself can output 30W continuous without getting too hot.  I call it my Powerblock.  Of course my wife calls it the "stop going to bed so late e-cig".

Okay here we go. 


That's simply amazing. What more can you ask in a mod. You covered all the bases. Great work indeed.
Title: Re: 1st Attempt at Microprocessing
Post by: fsors on February 11, 2012, 11:52:05 PM
Wow Craig That's Fantastic! :popcorn: :popcorn: :beer-toast:
Title: Re: 1st Attempt at Microprocessing
Post by: pnguin on February 13, 2012, 04:23:11 AM
BAM! That's the sound of my jaw hitting the floor. You guys are amazing. :rockin smiley: :thumbsup: :applaude:
Title: Re: 1st Attempt at Microprocessing
Post by: Chaos on February 14, 2012, 02:35:48 AM
I'm seeing more and more modders getting into microprocessors lately. Evolv's even coming out with a 'Modder's kit' that uses Darwin electronics and a variety of add-on modules. Future's looking really cool!
Title: Re: 1st Attempt at Microprocessing
Post by: CraigHB on February 20, 2012, 02:52:22 PM
Hey Dave,

How's it going with this, making any progress?
Title: Re: 1st Attempt at Microprocessing
Post by: Breaktru on February 20, 2012, 04:00:01 PM
Hey Dave,

How's it going with this, making any progress?

Right now I have it on the bench. Removed the 16x2 and replaced w/ an LCD 8x2 display and calculates Vout, Amps, Resistance and Power. I double checked it w/ my multimeter and it seems very accurate, which surprised the hell out of me. Particularly the ohms readings.

The OLED is on hold, I bought several 27 pin FFC / FPC connectors and all were half the size I needed. Can't find any to fit. I may have to directly solder but I'm holding off from doing that for now.

Also did some more research and this OLED requires 3.3v and 7v-15v which would be a pain. I can tap the 8.4v battery out but have to make another regulator for 3.3v unless I make a voltage divider circuit (not very efficient I believe.)
Not sure if all Micro controllers are like Arduino but I can feed 8.4v to raw in and it will regulate to 5v out at VCC. This takes care of powering devices such as LCD's. Perhaps I can voltage divide it here or at the battery out for 3.3v.
And.......... the code for OLED and SPI ....... this is where I may have some trouble. The LCD's are a piece of cake.
Title: Re: 1st Attempt at Microprocessing
Post by: CraigHB on February 20, 2012, 04:52:33 PM
It sounds like that OLED is a bust.  It really is so much easier to use a 16x2 or 8x2 text mode display.  The main objective is to deliver numeric information.  Do we really need anything other than a text mode display to do that?  My feeling is that a graphic mode display is just overkill in this instance, though I've used them before, but for projects that actually require graphics.

The logic for most displays is 2.7 to 5.5V, but the display itself can require much higher voltages to drive the contrast.  Most have a built-in charge pump that covers it for you.  A charge pump is a simplistic capacitive booster that only works for very low currents.  When a COG (chip-on-glass) display has one on-chip, you just need to add a few external capacitors.  Personally, that's a requirment for me in any display.  There's just no reason to go with a display that requires an external charge pump when the vast majority have them built-in.

I get my displays from these guys (http://www.newhavendisplay.com/), have been for a long time.  They have a wide product range and prices are reasonable for onesy twosies.  You can also find their stuff at places like Mouser and Digikey.

Your Arduino module has an on-board regulator which is handy.  Some MCUs have a pretty wide operating range, but you often want to regulate supply voltage to act as a voltage reference for your analog to digital converters.  Some controllers have a built-in voltage reference independant of supply voltage, but that's not a common feature.  I have no idea if that's the case or not for the ATmegas used on the Arduino boards.  You can also use a separate voltage reference chip if you need one.

On my project, I just finished the program last night.  I ended up with about 2500 lines of code (in assembly) so I'm only using about half the available program memory.  I'm pleased about that.  You just never know how much program memory you're going to need until you're done.  I wanted to use a part with minimal space.  You don't want to pay for more than you need.  I still have plenty of room for expansion if need be too.  Pretty happy I'm done with that part.  Programming is not my favorite part of electronics.  Now I'm on to the mechanical.  Need to come up with an enclosure.  I have a guy locally that can do 3D printing with high impact plastic so I'm going to give that a try.  Need to do some mechanical drawings, again not my favorite aspect of electronics.
Title: Re: 1st Attempt at Microprocessing
Post by: Breaktru on February 20, 2012, 05:59:39 PM
That amazes me that you program in Assembly. Very impressive. My hats off to you. Your amazing Craig.

Yeah this OLED is not worth the trouble, thought I was going to add a graphical bar-graph (battery life) or logo image but text is really all we need. Bar-graphs can be accomplished with characters but being I'm using an 8x2, no room left.

I've seen this tiny display w/ a built in charge-pump reasonably priced:
(https://www.adafruit.com/images/ID661parts.jpg)

Bi-directional communication would be nice, tuning into a Wattage or amperage via the controller. Maybe way down the line.
Title: Re: 1st Attempt at Microprocessing
Post by: Breaktru on February 20, 2012, 06:44:34 PM
I think the size of the 8 x 2 LCD display will fit nicely in a small box. The results are tight. No room for a space between values.
Note: have to look at my math code on rounding the numbers. the power calc is slightly off. Should have been 6.71w. The resistor, amps and voltage are dead on. Compared against my MultiMeter.

(http://breaktru.com/ecig/mcu6.jpg)
Title: Re: 1st Attempt at Microprocessing
Post by: CraigHB on February 20, 2012, 09:18:38 PM
Well, I don't know if programming in assembly is worthy of any compliment, but thanks anyway.  Most people use C.  Assembly is repetitive and tedious but what I like about it is you can write really tight code since you're working at the machine level.  You have absolute control over what's happening in the processor.

I like the looks of that little display from what I can tell in the photo.  Looks like it has a low pin count which is a good sign.  Any more info on it?

I use bi-directional SPI comms on the digital pot to verify its setting before engaging the converter.  I use mono-directional SPI comms on the display.  I haven't had any issue treating the display as a dumb device.  Usually, you can take for granted your display is producing what you tell it to.  Though there's nothing wrong with error checking and of course, you have to have it with a touch screen.  It frees up a pin on the controller without it.  I have a 28 pin controller and I'm using all 28 pins.

I actually did a hack to get around driving the display's reset pin because I don't have a free pin on the MCU for it.  I'm driving my display with only 4 of the MCU's pins.  I use SPI out, SPI clock, register select, and display power.  The display hasn't glitched once since I got the timing nailed down for my reset pin hack.

I ran into the rounding issue as well.  Initially, I was truncating, but found it's kind of weird when your resistance indication shows you should have more current than you do.  So, I added a little quip to round up the least significant digit on resistance and wattage. 

A bar graph for battery level is about the only useful graphic that comes to mind, but I don't think it's a particularly noteworthy feature.  You can see how I handled battery level in the photo, with percentages.  I would have liked to use a voltage reference on my ADC's low side to get higher resolution, but it would increase the part count too much.  So...I just go in jumps of 10% and then go in jumps of 1% when capacity is in the single digits.  It works out since battery voltage starts spreading a lot below 10%.  That's where it gets into the steep part toward the end of the discharge curve.
Title: Re: 1st Attempt at Microprocessing
Post by: Breaktru on February 21, 2012, 08:22:13 AM
This is the Display: http://www.mouser.com/ProductDetail/Newhaven-Display/NHD-0208AZ-FL-YBW/?qs=3vk7fz9CmNwp%2fv8qN8rgVQ%3d%3d (http://www.mouser.com/ProductDetail/Newhaven-Display/NHD-0208AZ-FL-YBW/?qs=3vk7fz9CmNwp%2fv8qN8rgVQ%3d%3d)
Title: Re: 1st Attempt at Microprocessing
Post by: CapeCAD on February 24, 2012, 08:35:37 PM
You might also be interested in the pc1602K-Y4 http://www.powertip.com.tw/products_2.php?product_id=1171043916&area_idbk=1170985616 (http://www.powertip.com.tw/products_2.php?product_id=1171043916&area_idbk=1170985616) 16x2 LCD from Powertip. Code is the same as your larger 16x2.
Title: Re: 1st Attempt at Microprocessing
Post by: CraigHB on February 24, 2012, 09:14:31 PM
That link didn't work, here's (http://www.powertip.com.tw/products_2.php?product_id=1171043916&area_idbk=1170985616) what I got on a search.  That one is 53mm wide, still too big for me.

I'm seriously scrounging for a smaller display.  The smallest one I've found that isn't a segmented LCD (which I'm not interested in) is the one I'm already using (seen in the photo I posted).  It's 41mm wide and is available from Newhaven in both a character mode and a graphic mode, pick your poison.

I'm looking at doing another mod that requires an even smaller display, about 35mm wide instead of 41mm and I'll be damned if I can find one.  I actually saw one on alibaba.com which is that Chinese wholesale site you always end up getting directed to, but they only sell in large quantity.

I can't believe demand is so small for tiny graphic and character FSTN displays that nobody stocks them for sale in small quantities.  I even asked Newhaven and they said no, but they could make one for me, if I want 1000 of them.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 07, 2012, 01:33:59 PM
Been playing around with an Atmel's ATMega328 Processor in 28 pin DIP package. Chip came pre-loaded with the Arduino Optiboot (Uno 16MHz) Bootloader. Installed it on a Programmer breadboard I made which I plan to also use for loading my own bootloader on future chips.
Chip worked fine and loaded simple sketches on it several times. The second day, I loaded a new sketch and received an error: Avrdude: stk500_getsync(); Not in sync; resp=0x00. Did some googling and found several people having similar issues. Seems to be communication problems. Tried every possible means unsuccessfully to get it working.
Finally this morning with changing devices to write to and com ports as I did yesterday, it worked  :banana: . Must be buggy Arduino software because the settings are the original settings.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on March 07, 2012, 04:39:04 PM
Ah, the joys of software bugs with embedded systems.  I can't tell you how many times I've run into issues with something like that.  A lot of times, I think to myself, "there's no way I'm ever going to figure out the problem, " but I haven't been permanently stumped yet.  A person can usually figure out anything given enough time and determination.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 07, 2012, 04:59:30 PM
Ah, the joys of software bugs with embedded systems.  I can't tell you how many times I've run into issues with something like that.  A lot of times, I think to myself, "there's no way I'm ever going to figure out the problem, " but I haven't been permanently stumped yet.  A person can usually figure out anything given enough time and determination.

You got that right Craig. Many times I've been perplexed with a problem from programming to mechanical issues. The best solution... for me is to walk away and come back to it a bit later. That always works.

Got the chip driving the 8 x 2 LCD and the ecig modding circuitry. The calculations and sensor readings are a bit higher than when I had it hooked up with my Arduino Pro Mini. Must be a timing difference between the chip and the Pro Mini. Guess I'll have to tweak it a bit.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on March 07, 2012, 05:19:58 PM
I'm sure you'll get it dialed in. 

I have a similar issue with my latest e-cig mod.  I use an operational amplifier chip to amplify the signal from the current sense resistor.  I do that so I can use a low value current sense resistor.  That minimizes power loss.  The op amp is required to put the signal level in the correct range for the MCU's ADC. 

Every assembly has a different op amp with a different input offset.  That's normal, but I have to tweak the code to compensate for it.  The idea was to make the code generic so it doesn't have to be tweaked for every assembly.  I'm thinking I'll have to add a calibration routine at some point.  Fortunately, I've only used about half my MCU's program memory for a fully functional program which is much less than I initially thought it would take.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 07, 2012, 05:41:41 PM
Can I run this by you Craig?
I'm calculating for Battery life. 8.4 volts is 100% and for the low voltage I went with 6.6 volts and would be 0% battery life.
That's only 1.8 volts between 100% and 0%. I have it all mapped out and working good. Just looks weird looking at something like 20% battery life and still having sufficient vaping time left.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on March 07, 2012, 06:47:47 PM
Not unusual.

Li-Ions have a wierd looking discharge curve.  It starts out steep then goes more flat then falls off quickly.  You get differnt shapes depending on cell chemistry.  For example, the LiPos I typically use are less steep at the front of the curve than other cells I've used.

The best thing to do is to manually plot the discharge curve for the particular cell or cells you are using.  You can make a simple load bank with some high power wire-wound resistors.  Just mount them to a metal plate for additional heat sinking.

Once you've plotted your curve, you can associate voltage levels to state of charge using a table in code.  What I do is take a sample when the cell is NOT under load.  That's how my table is based.  The MCU checks cell voltage when the cell is not under load.  The reason is that load may very which could invalidate your state of charge table.  Your table would only be good for the load under which that data was gathered.  So, checking under no load gives you a reference that is fully independant.

I think it sounds more complicated than it is.  Once you've done one, it's really pretty simple.  Here's the one I'm current'y using.  The first column is the sequence of 30 second discharge intervals.  The second column is voltage with no load.  The third column is the 10 bit ADC reading in hex.  The fourth column is the state of charge in percentage with the associated ADC reading.

Code: [Select]
01  4.17  3C8 - 100 (968)
02  4.16  3C5
03  4.15  3C3
04  4.14  3C1
05  4.13  3BF
06  4.12  3BD
07  4.11  3BB
08  4.10  3B9
09  4.10  3B7 - 90 (951)
10  4.09  3B5
11  4.08  3B3
12  4.07  3B0
13  4.06  3AE
14  4.05  3AC
15  4.04  3AA
16  4.03  3A9
17  4.03  3A7
18  4.02  3A5 - 80 (933)
19  4.01  3A2
20  4.00  3A0
21  3.99  39E
22  3.98  39B
23  3.97  399
24  3.96  397
25  3.95  395
26  3.94  393
27  3.94  392 - 70 (914)
28  3.93  391
29  3.93  390
30  3.92  38E
31  3.91  38C
32  3.91  38A
33  3.90  389
34  3.89  387
35  3.89  386
36  3.88  384 - 60 (900)
37  3.87  383
38  3.87  382
39  3.86  380
40  3.86  37F
41  3.85  37E
42  3.85  37D
43  3.84  37C
44  3.84  37A
45  3.83  379 - 50 (889)
46  3.83  378
47  3.82  377
48  3.82  376
49  3.81  375
50  3.81  374
51  3.80  373
52  3.80  372
53  3.79  371
54  3.79  370 - 40 (880)
55  3.79  370
56  3.78  36F
57  3.78  36E
58  3.78  36E
59  3.78  36D
60  3.77  36C
61  3.77  36B
62  3.76  36A
63  3.76  369 - 30 (873)
64  3.76  368
65  3.75  367
66  3.75  367
67  3.75  366
68  3.75  366
69  3.74  365
70  3.74  364
71  3.74  364
72  3.74  363 - 20 (867)
73  3.73  362
74  3.73  361
75  3.72  360
76  3.72  360
77  3.72  35F
78  3.71  35E
79  3.71  35D
80  3.70  35C
81  3.70  35B
82  3.69  35A - 10 (858)
83  3.69  359 - 9  (857)
84  3.68  358 - 8  (856)
85  3.68  357 - 7  (855)
86  3.68  356 - 6  (854)
87  3.67  355 - 5  (853)
88  3.67  353 - 4  (851)
89  3.66  351 - 3  (849)
90  3.63  34A - 2  (842)
91  3.59  341 - 1  (833)
92  3.54  336
**  3.50  32C - off (812)
93  3.47  326
94  3.39  312
95  3.24  2F0
96  2.70  ---   
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 07, 2012, 07:44:06 PM
 :thankyou: Excellent Craig. Plotting the curve is a great method.  :beer-toast: I'll have to give it a go.

What I was doing was calculating as mentioned here:

Battery Life Calculation for two 3.7v Li-ions in series (fully charged 8.4v)?
Two Li-ion batteries are 8.4 volts when it’s fully charged and about 6.6 volts when it is fully discharged. That’s a total of 1.8 volts that represents the full range of charge on the two batteries. To make a good guess at how much charge your battery has left, you can assign a percentage of charge remaining that is directly proportional to the battery voltage.
If the battery voltage is 7.5 volts, how much charge is left? Beginning with 6.6 volts representing no charge or 0% charge available, subtract 6.6 volts from the voltage that you read. So 7.5 – 6.6 = 0.9 volts. Since there are only 1.8 volts above 6.6 volts that represents the full range of charge, we can divide the difference that we just calculated by 1.8 volts to get the percentage of charge remaining. 0.9 volts / 1.8 volts = 0.5 or when expressed as a percentage, multiply by 100 and get 50%.
Here’s the procedure written as a formula that is applicable to 8.4 Volts total Battery reading:

OPEN CIRCUIT BATTERY STATE OF CHARGE CALCULATION

% Charge = SOC

% Charge = ((Measured Battery Voltage – 6.6 volts) / 1.8 volts) x 100
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on March 07, 2012, 08:18:58 PM
Well, you can use a linear calculation for battery capacity.  It makes coding much easier since you don't have to implement a table in code and you don't' have to do any discharge testing on your cells.  However, because voltage changes with state of charge in a non-linear fashion, you will see an obvious difference in the time it takes to go from say 90% to 80% compared to say 50% to 40%.  In other words, the accuracy of your meter will suffer obviously by using a linear calculation. 

Setting up a table is much more work, but it's your device and your call.  Personally, I think a table is required.  I prefer to have my battery capacity meter as accurate as possible and I think it's worth the extra effort.  If that's not as important for you, then the much simpler method may be in order.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 07, 2012, 08:26:53 PM
Yes your way is definitely the better way to go. I did notice rapid changes in percentage during my testing.
Still have a lot of work to do with it and only devoting minimum time on it. If I find some time I will try your method. Thanks again..
Tomorrow I have to change out 4 shocks on my truck. Just received 4 shocks in the mail today. So doing it tomorrow is out of the question.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on March 07, 2012, 08:50:47 PM
Yes, it does take quite a bit of time to see through projects like this to the end.  It's quite involved.  I started my current project around six months ago and I'm only now to the point where I can start thinking about an enclosure for it.  Lots of mechanical drawings to do and that's still going to take a while yet.

Hope things go smoothly with your automotive work.  I do my own maintenance on my truck, but the car goes in to the mechanic.  That thing is just way too hard to work on.  Every time I try, I end up with a bunch of busted knuckles.  I think my skin is worth the labor costs.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 09, 2012, 10:02:25 PM
Have it all wired up on 3 breadboards patched together and put together this attached Schematic made with Eagle Software. The Schematic was harder than the actual wiring which I had hand sketched on several separate circuits. WHEW!
Now if I can put the actual circuits in the washer and dryer on HOT setting, I'd have it made.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on March 09, 2012, 10:46:59 PM
Don't know if that's intentional or not, but the schematic is too small to read.

I actually do have mine on three different CAD drawings.  I skip the schematic part in Eagle.  You don't have to start with a schematic to design your PCB in Eagle.  I find it easier to do my electrical drawings in CAD, though it's probably not what most people would do.  You have to manually create the "nets" when using Eagle's board editor without a linked shematic.  It's a pain, but I find Eagle's schematic editor more of a pain.

I watched a re-run of Iron Man the other night and was thinking how much I wish I had that computer to do my assembly for me, so yea, put it in the HOT cycle.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 09, 2012, 10:59:27 PM
I've done only one other schematic with Eagle before and started w/ the PCB first. I just wanted to put all the circuits together because I had bits and pieces of it on separate sheets. I'm sure yours is way more sophisticated than what I have here. I know you build yours from the ground up and I'm mainly using components.
Yes there is a reason the schematic is scaled down. I don't have to tell you why.

Yes Eagle was a pain and the resulting PCB that was created from the schematic is a mess. I won't be using it. Best to make it separate like you said with CAD, you're right it is much easier that way. It took me forever to match devices to use. The LCD is too big. Couldn't find an 8x2 in the library. Yada, Yada, Yada...
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on March 09, 2012, 11:53:53 PM
That's what makes Eagle a royal pain.  You can define your own devices and put them in a personal library, but with a linked schematic, you also have to define and link a schematic symbol.  Eagle has a pretty clumsy device editor.  You can define devices for the board editor quickly when you don't have to do that.

The intention with Eagle is to start with a schematic and the suite is designed to be used that way.  In fact, pretty much every PCB design suite is meant to be used that way.  However, it's just so much easier to define your own devices than to hunt for hours on end in the truly overwhelming number of canned devices for one that may or may not fit your needs.  Even when I find the library device for the exact part number I'm using, it's never what I want.  For one, I need the pads about 50% longer because I hand solder everything.

One thing that can be done to make things easier is to find something close, copy it into a personal library, then edit as required.

Another issue I have is with the "ratsnest" you start with when designing your board.  That's the actual terminology, it's called the ratsnest.  It can become unmanageable when you have higher pin counts.  When designing a board without a linked schematic, the ratsnest is built one connection at a time.  I find it much easier, though it's not the way you're supposed to do it.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 22, 2012, 06:19:21 PM
Finally received my PCB boards:

(http://breaktru.com/ecig/avr_pcb1.jpg) (http://breaktru.com/ecig/avr_pcb3.jpg)
Title: Re: 1st Attempt w/ a Microcontroller
Post by: geothee on March 22, 2012, 10:48:42 PM
Friggin' awsome. Can't wait to see it in action mon
Title: Re: 1st Attempt w/ a Microcontroller
Post by: banshee on March 23, 2012, 09:51:18 AM
I love the whole concept of a micro-controller mod breaktru. Nice going.
and I love what Craig has done. Excellent guys..  :begging:
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 23, 2012, 10:09:49 AM
Thanks guys. I'm just a beginner when it comes to micro-controllers/processors. Craig is the man. He is a real Tech. Real professional designer.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: rrtwister on March 24, 2012, 10:39:53 PM
To read an output voltage from the 08100w with a micro-controller such as the Arduino, can I just send it to any analog input pin?
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 25, 2012, 08:24:09 AM
To read an output voltage from the 08100w with a micro-controller such as the Arduino, can I just send it to any analog input pin?

Not to get into too much detail:
No! Sending in voltage above VCC to an analog pin will damage your MCU. Make a voltage divider to bring down the voltage to less than VCC (5v or 3.3v)
                  R1             R2
   GND ----/\/\/\----*----/\/\/\---- Vin (6.0v or Max reg. output voltage)
                            |
                            | Vout
                            |
                            v
                   ANALOG PIN

I use R1=15k and R2=15k.

You will use the AnalogRead function. It reads the value from the specified analog pin. AnalogRead will map input voltages between 0 and 6.0 volts into integer values between 0 and 1023. (I used 6.0v as my max reg voltage)

  value = analogRead(pin);

  vout = (value * 6.0) / 1024.0;
  vin = vout / (R2/(R1+R2));
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Madmanmacguyver on March 30, 2012, 04:21:04 PM
so Breaktru hows the microcontroller thing going...kinda curios myself as I have a project myself involving one and some Nixie tubes...mine won't be to portable as Nixies require a High voltage power supply which makes it kindof bulky and a power hog...
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 30, 2012, 04:53:21 PM
Got about a half a dozen more wires to solder to the PCB. Waiting on several different boxes to put it in. Can't find anything nice. I did get a Hammond this week that was pretty cool but if only it was a bit deeper. I spent days looking through literally thousands of models.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on March 30, 2012, 08:48:54 PM
I hear that.  Enclosures are always the hardest part for me.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on March 30, 2012, 08:54:46 PM
I know what will probably happen... It'll end up in some crappy box
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 01, 2012, 04:41:26 PM
I completed wiring up my Micro-Controller mod on a custom made PCB I designed.
When I had it on 3 separate breadboards it worked great. Didn't have the charging circuit or the internal power supply for powering the MCU.

Right now I have it all wired up w/ charging circuit as shown at: http://breaktru.com/smf/index.php/topic,543.0.html and the internal power supply.
The vaping is powered by an OKR-T/6 and is putting out 3.6v to 6.0v. The internal power supply is outputting 5v for VCC.
The Charging circuit is working great so far. Running (vaping) w/ batteries in Series and charging in Parallel.
Being it's the first test run w/ charging I cut a piece of my Welding Blanket (fire blanket) and covered the batteries with it and a Halon Auto Fire Extinguisher placed over. I know.. I'm paranoid after the near explosion the other day w/ an Ultrafire.
I also didn't want to jeopardize my laptop USB ports if something went wrong so I am using a 1amp output wall adapter to power the USB charger:

(http://dlnmh9ip6v2uc.cloudfront.net/images/products/10217-01.jpg) (http://shop.vaporheads.net/images/12947838268432097728947.jpeg)

Still looking for a good box to house it all. Got 5 yesterday but I'm not excited about them. Waiting on another.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 01, 2012, 09:33:50 PM
Being it's the first test run w/ charging I cut a piece of my Welding Blanket (fire blanket) and covered the batteries with it and a Halon Auto Fire Extinguisher placed over. I know.. I'm paranoid after the near explosion the other day w/ an Ultrafire.

Hehe, that's pretty paranoid, but I've never actually had a Li-Ion burst into flames on me, well not unintentionally.

I always use a wall wart.  I'm not willing to make my PC an expensive power supply.

Anyway, good to hear it's all coming together.  Should be interesting.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 01, 2012, 09:41:25 PM
It was a so-called Ultrafire 3000mah. See: http://breaktru.com/smf/index.php/topic,289.msg3456.html#msg3456 (http://breaktru.com/smf/index.php/topic,289.msg3456.html#msg3456)
Title: Re: 1st Attempt w/ a Microcontroller
Post by: jester on April 02, 2012, 05:52:08 AM
i got 2 of those batterys you  got my trustfire 14500 last long alot of them on ebay i will only be using tusted suppliers. :thankyou:jimmy
Title: Re: 1st Attempt w/ a Microcontroller
Post by: asdaq on April 04, 2012, 02:15:58 PM
Great projects guys! Tru, what size 'box' do you need to house this? In other words, what are the sizes of everything you need to fit inside?
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 04, 2012, 02:33:41 PM
Great projects guys! Tru, what size 'box' do you need to house this? In other words, what are the sizes of everything you need to fit inside?

Craig's board is amazing, ain't it Asdaq.
I have several in the approximate size. Just not impressed with them. Waiting for an Extruded Aluminum case that may have to do.
The project got a little out of control, size-wise.
If I go with the deeper box, 1¾" I can probably fit it in a 3¼" x 2¼"
Title: Re: 1st Attempt w/ a Microcontroller
Post by: asdaq on April 04, 2012, 02:41:57 PM
Most certainly. What if it weren't a box, but a tube or two? Any chance?
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 04, 2012, 02:48:37 PM
The hardest part is making things small.  You get better at it the more you do it.  The one I show in this thread is a product of all the ones I've done before it.  The first one I did was quite a bit larger.

I've kind of stalled on this one.  I've had a bunch of things come up that have kept me away from the project.  Haven't touched it for a while now.  I need to build a couple more PCBs, do some mechanical drawings, and go to a local guy that does 3D printing for a custom enclosure.  There's pretty much no way I'll be able to find something off-the-shelf for it.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 04, 2012, 06:06:07 PM
Most certainly. What if it weren't a box, but a tube or two? Any chance?
Craig's right. Gets better each time. Perhaps the 3rd or 4th version will be more manageable. I would have to use all SMD parts. My PCB traces are critically close already though.
No way can this fit in any tube type. Maybe 2" pipe....  :laughing2: I know Asdaq would steam punk it  :rockin smiley:. Though the LCD would contradict the steam punk effect.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: asdaq on April 04, 2012, 07:04:32 PM
Hey, I've got a length of ~36mm ID  :rockin smiley:
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 04, 2012, 07:38:40 PM
How's are the Micro-Controllers coming? They Looks awesome some far.  :thumbsup:

Does it measure current flow under load?
Does it measure voltage under load?
What other features does it have?

When can I buy a kit from Breaktru? !   :begging:

I have some pic MCU experience and surface-mount experience and had conceived building something like after seeing a Lava tube and  before discovering this thread...now I think I would just be reinventing the wheel.

Incredible work....I love what we can do these days with programs like Eagle and short run circuit board fabrication.

are you guys soldering the surface-mount under a magnifying light (as I do) or doing the soldermask / solderpaste / toaster oven technique? Just curious?
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 05, 2012, 04:24:56 PM
I suppose you think of it as re-inventing the wheel since production VV and VP mods are available, but it's also a matter of building something yourself and making it to your own specifications.  When I build my own devices, they have all the features I want and none that I don't.  The feature set is unique to my device.

I do all my soldering by hand under a stereo microscope, 10x mainly, but I'll use 30x for inspection sometimes.  Though, that's not to say it's the best method, it's just how I do it.

A lot of people use reflow soldering for SMD stuff.  It can be done with a simple toaster oven or hot plate.  You do need to add a temperature probe of some kind to avoid over-heating.  Pretty do-able actually.  It's way faster than hand soldering.  I've just been soldering electronics for a very long time and have always done it by hand.  Electronics have gotten smaller over the years and I've just been adjusting my hand soldering methods as required.  I really need to have a go with reflow myself.

For hand soldering, it's all a matter of scale.  There's no difference between soldering a thru-hole resistor and the smallest SMD component other than the tools and supplies you use.  The smaller you go, the finer the wire solder, the finer the tip, and the more magnification.  You need a good set of very sharp tweezers to handle the components.  A steady hand helps a lot too.

One note about PCBs and vaping.  You need to ensure the PCB is well protected from vapor as well as juice.  The vapor can condense on the PCB over time and short things out.  I've encountered that already myself.  Though, it's nothing a little cleaning with rubbing alcohol can't fix.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 05, 2012, 05:25:46 PM
Craig I hear ya. I have done just a few surface-mount projects using a lighted 5x magnifier  ...My girl won't loan me her Gemological stereo-micro scope for soldering  >:( Although I can use it for inspection and have.  :D

I love building things my-self or in collaboration with a good team for exactly the reasons you mentioned...unique feature set and self satisfaction and for experience.

I have a Weller WES51 that a love that does a good job on just about everything with the right tips (very fine to chisel)

Well, you guys rock. :rockin smiley: I hope these device are available soon I finding PV's are like other fun toys, you can't have too many devices

 
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 05, 2012, 05:54:18 PM
Sounds like you're all set up.  Time to hit the drawing board, eh?
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 09, 2012, 04:23:03 AM
Been hitting the drawing board pretty hard. Its hard to not have the feature set snowball when using a micro controller.

My Design so far:
3.7 volt single Li-On cell powered
2x8 back-lit display
Variable voltage using a DC-DC booster  3.80v - 6.2v at  0.05v steps.
3 button interface.
display shows Volts, Amps, Watts, Resistance & battery SOC on demand.
device senses Shorted Atty, Open Atty
user can change voltage, display contrast, back light on/off via the 3 button interface.
user can change if display is on or off during vaping.
measures amp, volts, watts under load.
Low battery warning via display.
Over current warning via display.
USB charging.

Initial schematic finished.
Initial Software flow chart finished.
Initial Software psedo-code finished. (I forge out the psedo-code so I have a template used as a blueprint for multiple micro - controller platforms. All my past experience is with Microchip 8bit controllers. May go with one of their 16bit units or switch to ATMEL

Creative juices flowing for a possible tube-mode solution as enclosure, without being overly bulky.

Parts on order.














Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 09, 2012, 09:45:10 AM
Been hitting the drawing board pretty hard. Its hard to not have the feature set snowball when using a micro controller.

My Design so far:
3.7 volt single Li-On cell powered
2x8 back-lit display
Variable voltage using a DC-DC booster  3.80v - 6.2v at  0.05v steps.
3 button interface.
display shows Volts, Amps, Watts, Resistance & battery SOC on demand.
device senses Shorted Atty, Open Atty
user can change voltage, display contrast, back light on/off via the 3 button interface.
user can change if display is on or off during vaping.
measures amp, volts, watts under load.
Low battery warning via display.
Over current warning via display.
USB charging.

Initial schematic finished.
Initial Software flow chart finished.
Initial Software psedo-code finished. (I forge out the psedo-code so I have a template used as a blueprint for multiple micro - controller platforms. All my past experience is with Microchip 8bit controllers. May go with one of their 16bit units or switch to ATMEL

Creative juices flowing for a possible tube-mode solution as enclosure, without being overly bulky.

Parts on order.

Looks like we have another killer mod in the works. Fantastic! Between you and Craig you guys have posted some interesting concepts.

I spent several hours yesterday bench testing. I have found mine a bit buggy on start-up. I went with an 8bit processor.
Perhaps I should keep my processor powered all the time and make it go into sleep mode when not needed. Shutting pwr completely off and on doesn't seem to be the way to go.
Funny though, when it was on a bread board, it worked consistently well every time. From complete power down to powering up.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 09, 2012, 02:40:27 PM

Perhaps I should keep my processor powered all the time and make it go into sleep mode when not needed. Shutting pwr completely off and on doesn't seem to be the way to go.
Funny though, when it was on a bread board, it worked consistently well every time. From complete power down to powering up.

Sleep mode is usually the way to go rather than killing the power to chip and have to redo all  that startup initialization each time.

Can wait to see more of your design.

I'm adding two more functions: (software based so easy to add  :))
1) Restricted upper Volt limit based on ATTY ohms.
2) User adjustable draw limit time.
        Two safety features that ensure the device doesn't melt down.


Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 09, 2012, 02:49:17 PM
This is getting interesting now that we have another MCU guy on-board. 

I power my MCU full time.  I use the wake on "port change" interrupt to wake the MCU when a button or the trigger is pressed.  If you use an LDO regulator with an ultra-low quiescent current, you can get draw pretty negligible in sleep mode.  My total sleep draw is only 7.5µA.   Of that, 3µA is for the MCU, 3µA is the quiescent load of the MCU's regulator, 1µA goes to the digital pot, .25µA is for a voltage detector, and the rest is leakage.

In any case, you should have a stable power-up.  Here's some things that can give you trouble;

Do you have decoupling capacitors on all your power pins for the MCU.  It's standard practice to put a .1uF capacitor between all the MCU power pins and ground as close to the pins as possible.  The same is true for any chip that utilizes digital logic.

Do you have adequate input and output capacitors on the MCU's regulator as close to the regulator as possible?.

Do you have any heavy capacitive loads on any of the port pins.  That can cause a power spike and over-load for the MCU on power-up.

Is the dc-dc converter's ground plane isolated from the MCU's ground plane?

Is there anything in your code that is switching a heavy load too close to power-up?
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 09, 2012, 03:58:11 PM
Very good Craig. Very useful info, thanks.

Yes to the .1uF (100nF) on the VCC pin. I have 3 VCC pins tied together w/ (1) .1uF to ground.

My regulator is using the recommended caps but maybe too high drain for continuous power on (LM317).

I suspect the Amperage Sensor may be causing a capacitance problem. The very 1st time powering on after wiring up the PCB, I had to
remove the sensor for it to work at all.

The DC-DC conv is sharing the ground plane. o'boy. This will be hard to fix.

I have a 3 sec banner display on power up before code calculations begin.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 09, 2012, 06:38:44 PM
Each VCC pin should have it's own decoupling capacitor located as close the pin as possible.  Believe it or not, the additional trace length that results from tying all three pins to one decoupling cap can make a difference.  It's because you want to minimize ESR.  Trace resistance acts like additional ESR for the capacitor.  ESR reduces the effectiveness in which the capacitor smooths the supply.  That's also why decoupling capacitors are always ceramic, they have the lowest ESR.

You can probably go as high as you want on the regulator's input cap, but don't go over the recommended value on the output cap.  It's because the higher the capacitance on the output cap, the longer it takes for voltage to ramp up.  MCUs have a certain tolerance for ramp-up.  If it's too slow, it might not power-up properly.  Also, regulators have a limit on the in-rush current they can handle.  More output capacitance means more in-rush current which can cause unstable start-up characteristics for some regulators.  Some LDO regulators call for electrolytic or tantalum capacitors for proper stability.  Make sure the data sheet says ceramic caps are acceptable if that's what you are using.

You don't need to go so far as to use active isolation for your ground planes.  Just put a slot in there to separate the converter plane from the MCU plane with a common connection at battery negative.  What you're doing is mitigating cross-inductance by routing high return currents away from sensitive digital circuits.  Routing return currents under their positive counterparts makes induction cancel.  When high currents flow in the ground plane under traces carrying low voltage signals to high impedance inputs, it can induce considerable voltages in those circuits which plays hell with them.

If you need to power up something with the MCU that has a capacitive load, isolate it with a complimentary MOSFET pair.  You can get them in very small packages like SOT-23 or even SC-70 if you want to go that small.   They're usually good up to an Amp and can handle any in-rush currents.  I use this one myself;

http://www.fairchildsemi.com/pf/FD/FDG6332C.html
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 09, 2012, 08:14:42 PM
I'll try adding a couple of more decoupling caps and breaking the ground plane. If that don't work I will remove the DC-DC conv off the board.
I'm thinking of also replacing the LDO reg with an ultra-low quiescent. I roughly calculated the out put need to be 136.2 ma because of the LCD backlight.
Looking for a 5 Vout, 150 ma or up to 1a. Found some 3.3v. Still looking.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 10, 2012, 05:31:43 PM
Yeah Craig is bang on with all the theory and best practice(s).  :yes"  Everything mentioned I have been heard from other digital  engineers. (one of them worked on space-shuttle, B2 stealth, and various spy satellites).

I planing a using 3v LDO reg with an ultra-low quiescent, as well and all 3v components:
Digi-pots, sensors, & MCU

Since I am using only a 3.7 volt battery, I don't have much overhead to play with. Hopefully the battery voltage won't drop off too much under load. I found some pretty good 3v and Adjustable LDO's than can source up to 500mA.  I have calculated that about 300mA would be highest possible amp demand for my particular setup.  (on the digital side) and typical less than 100mA during normal  operation and just micro amps when sleeping.

It will be interesting to see what the actual amp draw is compared to the calculated.


Some of the LDO's were in the SOIC8 package, which I find pretty easy to deal with. I have some SOIC8 to bread board adapters that I use during the prototyping phase and SOIC8 is NOT too high on the P.I.A. scale for soldering.

Will post some pics soon.


Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 10, 2012, 05:36:12 PM
Yeah Craig is bang on with all the theory and best practice(s).  :yes"  Everything mentioned I have been heard from other digital  engineers. (one of them worked on space-shuttle, B2 stealth, and various spy satellites).

I planing a using 3v LDO reg with an ultra-low quiescent, as well and all 3v components:
Digi-pots, sensors, & MCU

Since I am using only a 3.7 volt battery, I don't have much overhead to play with. Hopefully the battery voltage won't drop off too much under load. I found some pretty good 3v and Adjustable LDO's than can source up to 500mA.  I have calculated that about 300mA would be highest possible amp demand for my particular setup.  (on the digital side) and typical less than 100mA during normal  operation and just micro amps when sleeping.

It will be interesting to see what the actual amp draw is compared to the calculated.


Some of the LDO's were in the SOIC8 package, which I find pretty easy to deal with. I have some SOIC8 to bread board adapters that I use during the prototyping phase and SOIC8 is NOT too high on the P.I.A. scale for soldering.

Will post some pics soon.


Being you are using a single battery, wouldn't it be possible to for-go the regulator and power just from the battery? I read that somewhere on a site.
I need 5v so I couldn't go that route.
Title: Re: 1st Attempt at Microprocessing
Post by: freelinuxer on April 11, 2012, 03:00:03 AM
I think the size of the 8 x 2 LCD display will fit nicely in a small box. The results are tight. No room for a space between values.
Note: have to look at my math code on rounding the numbers. the power calc is slightly off. Should have been 6.71w. The resistor, amps and voltage are dead on. Compared against my MultiMeter.

(http://breaktru.com/ecig/mcu6.jpg)

Hello, Breaktru, would you tell me the input power requirement for that 8x2 lcd ? (and possibly site that I can buy one from as well)...
I am searching for one operates with low power.
I am trying to use TI launchpad, and the MSP430 chip's power limit is ~3.3v I believe.
It was a good way of approaching MCU world .. (price). Plus I liked the fact that it consumes the lower power so TI MCU could be powered up all the time until the device turned off.
( I could be wrong.. it's still my day1 in this fun MCU programmin' world).


Another question.. if you don't mind.
I thought that arduino operates with 5v input volt. How do you operate the arduino board from 3.7v batt ?
Are you using stepdown regulator in this project ?

Your previous reply opened me a whole new way of enjoying this modding hobby.
Really appreciate it.
-freelinuxer
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 11, 2012, 04:17:03 AM
Being you are using a single battery, wouldn't it be possible to for-go the regulator and power just from the battery? I read that somewhere on a site.
I need 5v so I couldn't go that route.

I have not check the upper volt limit on the all devices...some may not be happy at 4.01 volts, the upper limit of a fully charged Li-On battery. I believe the main reason for a volt regulator is the vRef for the D to A. I am so use to using regulators it didn't even cross my mind to go without one.. Plus I want the voltage stable when the during vaping, I am pretty sure the battery volts will drop off sharply when the current kicks in. I don't have a scope., so I have no way to measure this. Since I have never really tried it....I have no idea what problems a non stabilized voltage may cause. However, I have made some LED flashers using PIC 's that ran fine from a 3V button cell with out a regulator, but nothing as complex as this.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 11, 2012, 04:36:24 AM
Here is some shots of my LCD - not the final one, just one I had on hand...still waiting for parts so started flushing out some of my coding and display screens.  No doing any D to A yet. I want to get all the displays working and the math working correctly.

 Thank god for 16bit floating point math! I would have hated to do this in 8bit.

 I will be measuring only the output volts, the output current and the battery volts. Right now I am just plugging in the Hex values where code would normally get them for the D to A.  Then I calculate the power = V * A, the Resistance =  V / A,  the maximum recommend voltage level = Square root (max watts / R).

Some pics:
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 11, 2012, 03:56:19 PM
Some MCUs have a really nice feature of having an internal voltage reference for the ADC.  This allows you to avoid the use of  a voltage regulator as long as the MCU and peripherals can operate within the supply range.  However you still need to regulate voltage for any LED indicators and the LCD backlight.  Otherwise, they will start out brighter and end up dimmer as the battery discharges.  It's probably just easier to regulate the supply for the MCU and all its peripherals.  Though, it may be possible to avoid using a regulator.

MCUs that require a 5V supply are not as common anymore.  Ten years ago, they were the standard.  The MCU I'm using has an operating range 2 to 4V which is probably more the norm anymore.  My LCD has an operating range 2.7 to 5.5V.  So, I run everything at 3V.  That allows me to run the cell all the way down to a fully discharged state with no change in supply voltage.  The MCU calls a low a batt condition at 3.5V (measured open circuit) and a voltage detector shuts down the regulator at 3V which drops draw down to 200nA as over-discharge protection.  Of course, this is for a single cell.  For a dual cell mod, 5V would probably be a better supply voltage.

Battery impedance can be a considerable factor.  My device uses a high drain LiPo flat cell with about 10m Ohm DC resistance.  Even at maximum output, voltage sag is well within tolerance.  However, when using a cell like a NCR18650A, cell resistance is up around 75m Ohm which could result in voltage sag out of tolerance for the system.  You have to look at what you're using and account for any dips in voltage due to load.  In my case, it's why there's a half volt difference between a low batt indication (3.5V open-circuit) and supply voltage (3.0V).

That half volt margin would not be enough for a single ICR 18650.  I would have to run two ICR 18650s in parallel or one IMR 18650 to get battery DC resistance down low enough.  I'd also have to use a 2.7V detector for over-discharge protection.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 11, 2012, 06:43:36 PM
 :begging: (not begging, bowing down in Awe) Thanks again Craig! once more your vast knowledge and willingness to share has improved my design yet again. I have decided to ditch the LDO and go with the MCP1601 Synchronous Buck Regulator which is designed to power things like cell phones and PDA's from a single 3.7 Li-On cell and I will go with a single IMR 18650.   Double checked all the voltage ranges all my devices:       
                          min typ  max
Current Sensor   3.0   3.3   5.5
MCU                  1.8   3.3   3.6
Digi pots            2.7   3.3   5.5
LCD                   2.7   3.3   5.5
Above all on regulator


DC - DC booster   straight of battery requires - 3.3v to 5v
Battery is 4.01 to 3.2

Hey I guess everything but my MCU is within tolerance. I'm sure I can find on from the same manufacture in the same family that is 2.7 to 5.5

I still go with the MCP1601 or similar for the over discharge protection and voltage stability it provides.
Sure it will take up real estate on PCB board with all its required analog components, but were talking a PCB board the size of a stick of gum with a medium component and pin count already.

I am still at the breadboard stage so I can play with a lot of options right now.

Thanks Again!!!!



Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 11, 2012, 10:32:56 PM
I had actually thought in terms of a DC-DC converter for the MCU supply at one point, but it causes more problems than it solves.  For one, a single chip buck-boost solution involves a much larger package than a linear LDO regulator.  Then you need an inductor and much higher value capacitors.  There's usually a few additional components for selecting options as well.  All that stuff takes up space.  Another issue is converters are not particularly accurate and they have a lot of ripple.  That means you need a well decoupled voltage reference for the ADC or your measurements would be unstable.  Again, that's more PCB real eatate.  There's also the quiescent draw to consider.  It's much higher for a converter.

If space is not a concern, a converter does avoid the problem of battery fade allowing you to run the MCU and peripherals at whatever voltage you want.  I don't think it's worth the trouble though.  Easier just to run the whole thing at 3V with a linear LDO regulator (or 5V for series cells).
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 11, 2012, 11:50:53 PM
ALL good points. I can see how the switching frequency can generate noise that has to be dealt with.
Seem like the with an LDO, if the Vin is from a battery, the Vout is not really going to have hardly any ripple.
Not like a transformed / rectified AC source.

I am not planing on powering the ATTY with this buck converter.
I am powering the ATTY with a separate DC-DC booster I wondering if its going to create a bunch of noise as well...I had already planned on decoupling the MCU & the Amp sensor, I guess now the Digi-pots.

I foresee a scope in my future  :wallbash:


From the Data sheet -
The MCP1601 is a synchronous Buck (step-down) switching regulator that can continuously supply 500mA of load current. This DC/DC converter can provide output voltages of 0.9V to Vin with an operating efficiency that can exceed 92%. Although ideally suited for a single Li-Ion, or 2 to 3 cell NiCd, NiMH, or alkaline battery operation, the input range of 2.7V to 5.5V is also useful for converting bus voltages to standard system requirements.

Requires 3 caps (2x 10uF, 1x 47pf)  and 2 resistors and the coil (10uH - 20uH) so that is only two extra parts over an adjustable LDO. Comes in 8MSOP.  most of the LDO's I have look at are 8SOIC or Dpack 4 pin or Dpack5pin

I have plenty of luck with LDO's so I may yet stick with one....I try to keep my projects with the KISS philosophy...but that it is counter productive when using a micro controller for an e-cig project... when you can get a good vape straight off the battery with an LM350  :laughing2:
Title: Re: 1st Attempt w/ a Microcontroller
Post by: freelinuxer on April 12, 2012, 03:43:36 AM
That half volt margin would not be enough for a single ICR 18650.  I would have to run two ICR 18650s in parallel or one IMR 18650 to get battery DC resistance down low enough.  I'd also have to use a 2.7V detector for over-discharge protection.

Is this a good alternative ?
http://www.orbtronic.com/batteries-chargers/protected-3100mah-18650-li-ion-battery-cell-is-panasonic-ncr18650a-protection-ic-made-in-japan-top-button/
it has 2 layers of protections : cell, protection pcb. also has max discharge current of 8.5A, Max. working discharge current of 6.2A, Discharge cut-off voltage at 2.5A.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: SolarRay on April 12, 2012, 05:18:18 AM
I could not find the spec for the internal resistance of the cell...What Craig and I are discussing is providing a 3.3 volt stable supply to the micro controller and its peripherals....when the atomizer is fired up...where it be powered by a DC-DC booster, A Linear voltage regulator or direct tap....what happens is there is a surge of current and on most batteries the voltage sags.....

Let say I'm using an LDO's that is trying to provide 3.3 volts to my micro-controller and sensors and it has a drop out voltage of 200 milli-volts, 3.3 + 200 millivolts = 3.5 volts required.


Let say the battery is full charged at 3.9 volts and the battery voltage sags under the atty load to 3.5  that is a difference of 0.4 volts which = 400 milli-volts  everything would be ok

So let say the battery has discharged down to 3.8 volts and under load it sags 0.4 volts and now only have 3.4 volts supplied to the LDO
3.4 volts - 200 milli volts = 3.2 volts would be the output of my LDO....which is below the target low limit of 3.3 volts..........  in my case I need to keep the output above 3.0 volts because of the AMP sensor I am using require 3.0 volts minimum (the rest of my devices can below this)  so I would still be ok

Luckily
There are some LDO that are 100 milli volts at their current maximum output and lower if you are not maxing out the current capacity of the LDO.

Which means I could have a battery discharge all the way down to 3.1 volts and still keep things up and running.
at 3.0 volts the battery needs to be re charged.

I might be able use a 4v 3300uf tantalum capacitor as "power reservoir"   to power the sensor during the 5-20 second sag period:

but my calculations say:
10 milliamp typical current draw on the sensor
3.3 volts
= 300 Ohms ESR

a 4v 3300uf Capacitor charged up to 3.3v with will drain in 0.1 second trying to provide 10mA .so in theory I would need a capacitor with 100 times greater capacity to solve the problem that way.

When it comes to IMR and ICR 3.7v cells:
I don't know how good is is to run them all they down  to 2.5v...Ithey certainly won't give a good vape below 3v  no matter what you attach to it.  :laughing2:

But thanks for the suggested link...Those battery may work very well in some other simpler mods I have been working on....3100mah, 6.2amp working discharge current, max charge 1C = 3amps recommend charge (.3c) =1.1 amps is ALL pretty good from my limited experience in these type of cylindrical cells. I am more experienced in working the flat high discharge packs used in R/C

I don't think any of my mods would ever trigger the 8.2 amps current protection or the 2.5V cut off 
So would be buying that type of cell for the mah, and charge / discharge C rating




 



 
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 13, 2012, 06:38:25 PM
I'm about ready to stuff it all in an enclosure that came today. Perhaps tomorrow.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: michamer on April 13, 2012, 08:16:28 PM
 :rockin smiley:
Don't forget to post some photos.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 13, 2012, 09:47:43 PM
Seem like the with an LDO, if the Vin is from a battery, the Vout is not really going to have hardly any ripple.  Not like a transformed / rectified AC source.

That's normally true, but the transient currents the converter draws put a lot of ripple on input power, especially for buck.  Boost converters are noisy on the output end.  Buck converters are noisy on the input end.  Isolating the ground planes and using decoupling capcitors on the Vcc pins should cover it.  It's also a function of battery impedance.  The higher the battery impedance, the more input ripple.

If you look at supply voltage with a scope, you'll be able to easily see how much input ripple ends up at the MCU as a result of the converter driving the atomizer.  It's probably going to be as much as 50mV, but that's acceptable.  The power supply doesn't have to be perfectly flat.  The main thing is to get the edges off the ripple.  It's those sudden transients that play hell with digital circuits.  Smoothing the edges is mainly what isolated ground planes and decoupling capacitors do.

@freelinuxer, the Panasonic NCR18650A is probably the best 18650 LiCo cell out there.  However, the internal impedance is too high to run a booster.  You either need to run two in parallel, or use a CGR18650CH which is Panasonic's high drain 18650.  It has half the internal impedance and almost double the drain limit.  It comes at a cost in charge capacity, 2150mAh peak for the CGR18650CH versus 3100mAh peak for the NCR18650A. 

The other option is to use two of the NCR18650A cells in series with a buck converter.  A nice thing about buck converters is they also work nicely with a couple 14500 cells in series.  It's because buck is the opposite of boost.  Buck has half the input current of boost because input voltage is double.  As a result, input current is within tolerance for a couple protected 14500s.  It's because DC-DC converters conserve power, power out equals power in barring a small loss.  It's what differentiates them from linear regulators.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 13, 2012, 11:00:27 PM
I had noticed my MCU regulator dipping when I fired up the OKR-T/6 that I had mounted on the same PCB. I did what Craig suggested by separating the ground plane for the DC-Conv and added the extra de-coupler for VCC to mcu but it didn't help.

I removed the OKT-T/6 off the PCB and NO dip in regulator voltage at all... Rock Solid output now.
When I cram it all into an enclosure I will keep the Converter away from the MCU circuitry and leave the converter separate.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: freelinuxer on April 14, 2012, 12:09:43 AM
...You either need to run two in parallel, or use a CGR18650CH which is Panasonic's high drain 18650.  It has half the internal impedance and almost double the drain limit.  It comes at a cost in charge capacity, 2150mAh peak for the CGR18650CH versus 3100mAh peak for the NCR18650A. 
...
@ CraigHB
Thank you, Craig, for the advice. Those CGRs are what I have now. I will use those panasonic ones in another step-down regulator mod.
It's always fun to learn new knowledge. :+)

@Breaktru, I can tell another cool mod's coming soon. Don't forget to mention here if you're  going to start another new thread for it.

I am just glad to know all these good knowledgeable people here. 
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 14, 2012, 05:21:40 PM
I had noticed my MCU regulator dipping when I fired up the OKR-T/6 that I had mounted on the same PCB. I did what Craig suggested by separating the ground plane for the DC-Conv and added the extra de-coupler for VCC to mcu but it didn't help.

I removed the OKT-T/6 off the PCB and NO dip in regulator voltage at all... Rock Solid output now.
When I cram it all into an enclosure I will keep the Converter away from the MCU circuitry and leave the converter separate.

Well, that's good to hear you were able to resolve the issue. Don't feel bad, a lot of times you run into weird issues that seem like FM (f'ing magic).  That's why there's an acronym for it.  Sometimes, all you can do is things by the book and hope no weird problems rear their ugly head.   When they do, you sometimes have to use weird solutions.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 14, 2012, 05:35:10 PM
Yeah Craig weird. ya think it is the 600khz frequency of the OKR?
Everything is running stable now. I can even power down completely and power backup with no problem. Before, the code would freeze at different points of operation.

Right now I'm charging the batts in parallel mode. I ran the batteries down to as low as I can go. I'm monitoring them constantly. No heat felt. The batts are cool as ice. I put them in my tin can with the fire blanket over the can and a Halon auto fire extinguisher over that.  :laughing:
Crazy I know but the batts were out of balance. One measured 2.81v and the other 1.7v. Sounds dangerous.
Before I plugged in the charger, I put the 3PDT switch in parallel position for about 15-20 min, thinking maybe they would equal out without power and by just being connected in parallel. I know, sounds stupid right. So far so good.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 14, 2012, 06:15:33 PM
Actually, the higher the switching frequency the better to a point.  It's because the reactive component of impedance increases at higher frequency which mitigates ripple.  600kHz is like the optimum switching frequency for performance and efficiency.  That's why they select it.  It's low enough to minimize switching losses and high enough to reduce component size and ripple.  I actually run my own booster at 550kHz to save a little on switching losses with a trade off in ripple.

With your cells in that depleted state, it doesn't take much of a charge differential to see those big voltage differentials.  When the cells get down that far, it only takes a slight change in charge to result in a big change in voltage.  So it doesn't surprise me that you'd see that.  Now, if you were seeing something like one cell at 3.7V and one cell at 3.2V, that would indicate a major problem since at that level, it takes a big difference in charge to make a small difference in voltage.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 25, 2012, 05:33:15 PM
This did the trick filtering the ripple caused by the OKR (see attached):
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on April 25, 2012, 10:10:06 PM
That's a good way to handle it.

If you use a 1uF cap and increase resistance to 2.2k and 6.8k, the filter will work exactly the same and you'll get less current draw.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on April 26, 2012, 09:36:15 AM
That's a good way to handle it.

If you use a 1uF cap and increase resistance to 2.2k and 6.8k, the filter will work exactly the same and you'll get less current draw.

Yes Craig, I should have added the zero's to my 220 and 680 and made them 2200 and 6800 for less current. DOH!
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on June 05, 2012, 08:30:25 PM
Been playing around with an Atmel's ATMega328 Processor in 28 pin DIP package. Chip came pre-loaded with the Arduino Optiboot (Uno 16MHz) Bootloader. Installed it on a Programmer breadboard I made which I plan to also use for loading my own bootloader on future chips.
Chip worked fine and loaded simple sketches on it several times. The second day, I loaded a new sketch and received an error: Avrdude: stk500_getsync(); Not in sync; resp=0x00. Did some googling and found several people having similar issues. Seems to be communication problems. Tried every possible means unsuccessfully to get it working.
Finally this morning with changing devices to write to and com ports as I did yesterday, it worked  :banana: . Must be buggy Arduino software because the settings are the original settings.

I have found that the buggy-ness is caused by the additional pins to read inputs. So I found the best solution is to have a test board with only the bare necessaries (no inputs). I came to this conclusion writing to the chip after adding additional inputs.
I pop out the chip from my mod and pop it into the test board to load code and it works flawless this way.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Haileah on July 07, 2012, 07:28:53 PM
Wish I had the know how to build one for myself  ;bow;
Title: Re: 1st Attempt w/ a Microcontroller
Post by: sterling101 on July 25, 2012, 03:35:38 PM
I (hopefully) should have something working soon based on a PIC MCU and using PWM for driving the atomizer itself.

Got a few scribbles put down on some paper but now it's a case of finding the best components to drive everything reliably and safely.
It will be put together in a tube mod too so space is a definite concern for me as heat will be too but expect a post to turn up soon asking silly questions about which component would best suit what etc as I start to fine tune things.

I've done a lot of work with PIC processors before and have used them to build an auxiliary ECU for controlling fuel on a turbo charged car so I understand the methods for reading signals and using the MCU outputs to control auxiliary outputs.
One thing I've not used is MOSFETs though as I've not had the need in the work I've done with MCU's but I can't see them causing too many issues :)

Will start a new thread once things start taking shape and get some pictures uploaded but for now I'll just give the heads up that there's another MCU mod on the horizon :)
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on July 25, 2012, 04:02:52 PM
The hard part with PWM is measuring equivalent voltage since input voltage is a factor.  It would be tricky for a closed loop regulated system or to provide user feedback for an open loop system.  The other thing is it requires series cells.  Though, it's an interesting concept and does lend itself to very high efficiency.

It should actually be a pretty simple thing to do, just a micro-controller and a MOSFET really, would need a couple tactiles and a display as well.  I suppose user feedback could just be a matter of indicating duty cycle.  You would get battery fade though.  For example 50% duty cycle with fully charged cells at 8.4V would not be the same power output as 50% duty cycle with heavily discharged cells at 7V.  Regulating the duty cycle to avoid battery fade opens a pretty big can of worms.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: sterling101 on July 25, 2012, 04:11:09 PM
Yeah that's the one thing I'm still mulling over - how to keep the voltages stable.
I was thinking of using a closed loop system that can measure the battery voltage, and using a look up table to control the PWM adjustment.
But like you say, it's a definite can of worms!!

The other option is to use it to cross drive a 4050 to try and keep the voltage to a maximum at all times, but that's still on the drawing board as I could just as easily use the MCU to just monitor things and use a digital pot to sort the rest out...
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on July 25, 2012, 04:31:49 PM
Should be able to do it with a formula.  Measure input voltage with the ADC then with the user setting, derive a duty cycle from it.  Since duty cycle would be regulated, you would have to indicate equivalent voltage to the user.  You could also measure current and indicate equivalent power.

It's not a simple program that's for sure, lots of math you would have to do in code, but it does benefit from very high efficiency and a simple hardware design.   The only losses are the MOSFET and the wiring.  With a good MOSFET, you're looking at efficiencies no lower than 98%.  You also have very high output capability, limited only by the MOSFET and the max drain on the cells.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: sterling101 on July 25, 2012, 04:47:52 PM
So I suppose the question would be what would be the ideal mosfet to use?
I have got a 5v sub mini relay that I can use for the test work until I get the mosfet set up though which, although not perfect would allow for some test work on the breadboard at least.

I'm thinking of trying to set up a regulated output using the PWM from 3v up to 6v so using two cells in series should give enough headroom between full charge and low charge to still keep the MCU running and if I use the display to signal when charging is required at say 10% headroom I can then disable the output to prevent the cells from being discharged too much.

The discharge rate *should* be relatively even so the formula for controling the PWM adjustment should be relatively straightforward to set up all being well - although I've probably just completely jinxed that idea lol
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on July 25, 2012, 05:05:32 PM
It should be easy to find a good MOSFET.  Since you can run at a fairly low frequency, I would imagine in the low KHz, you dont' have to worry about gate charge.  Pretty much any ol' MOSFET will work well.  Just pick the one with the lowest RDS(on)

Finding a MCU with a wide voltage range and a built-in ADC reference would be ideal.  That way, you can drive the MOSFET gate with battery voltage which yields the lowest RDS(on) and does not limit you to a low VGS(th).  If the controller does not have a built-in ADC reference you can use an external one.

It might be hard to find an MCU with an 8.4V tolerance.  Probably 6V would be the highest you can readily get.  You'd have to use an LDO regulator to power it.  In that case, just use a precision regulator so you dont' need a voltage reference for the ADC, you can just use VDD.

The lowest voltage you would have to deal with is 6.6V because a 3.7V Li-Ion cell is pretty much fully discharged at 3.3 Volts.  3V is typically the threshold for over-discharge protection.  You could set up a voltage detector circuit, possibly driving the enable pin on the MCU's regulator, to cut out the power supply when voltage drops below 6.6V
Title: Re: 1st Attempt w/ a Microcontroller
Post by: sterling101 on July 25, 2012, 05:12:38 PM
The (numerous) PIC MCU's I've got are all 5v so will need to use an LDO to get the voltage for it, but the ADC should only need a simple potential divider to bring it into the range that the ADC can cope with.
I was considering an external current sensor for checking the ohms of the atomizer but wondered if a voltage divider could also work for that as with a known resistance and a set voltage across the divider it should be a very simple piece of math to calculate the atomizer ohms.  I'd guess I'd need to have the atomizer on the ground side of the divider though and use another MOSFET to switch out the rest of the circuit from the actual atomizer driving circuit to make sure it's not going to fry the ADC channel when actually triggering the atomizer.  The only thing I need to play with is the lowest voltage I can output through the atomizer without actually triggering it which will probably be a trial and error thing I'd guess.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on July 25, 2012, 05:33:20 PM
The (numerous) PIC MCU's I've got are all 5v so will need to use an LDO to get the voltage for it, but the ADC should only need a simple potential divider to bring it into the range that the ADC can cope with.  I was considering an external current sensor for checking the ohms of the atomizer but wondered if a voltage divider could also work for that as with a known resistance and a set voltage across the divider it should be a very simple piece of math to calculate the atomizer ohms.  I'd guess I'd need to have the atomizer on the ground side of the divider though and use another MOSFET to switch out the rest of the circuit from the actual atomizer driving circuit to make sure it's not going to fry the ADC channel when actually triggering the atomizer.  The only thing I need to play with is the lowest voltage I can output through the atomizer without actually triggering it which will probably be a trial and error thing I'd guess.

You can power the MCU at 5V or even 3.3V, then use a complimentary MOSFET pair to drive the power FET at battery voltage.  That will give you the lowest possible RDS(on).  With the low frequency, the propegation delay of a complimentary pair should not be an issue.  If it is, lower the frequency.  I use a MOSFET pair in my current mod to control input voltage to the converter.  The MCU drives a small signal N-channel MOSFET at 3V that in turn drives a P-channel power FET at battery voltage. 

You'll get a better reading on resistance if you measure current and divide it into voltage.  It's much simpler hardware wise to measure current than to build an ohmmeter into your design.  Measuring current is cheaper, simpler, and way more accurate.  Just use the current sensing chip Dave uses in his mods.  It will work well.  Since you know when the MOSFET is active, you know when to measure current.

You dont' have to, but I would use a P-channel MOSFET as the PWM switch.  That also makes it easy to put your current sense on the low side.

Use a simple resistor dividor to drop the ADC input for battery voltage within tolerance for the MCU.  In my current mod single cell mod, I run the MCU at 3V, so I use a divider with a 4.7k and 10k resistor on the ADC input.

Since you'll be running the MCU at 5V, you can do a low battery detection at whatever voltage you like.  A low voltage cut-out would be optional and possibly desirable if using unprotected cells.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: sterling101 on July 25, 2012, 07:04:53 PM
Some good ideas there Craig!

Guess my first job will be to get some MOSFETs in and start testing code.
Might be worth seeing if I can get some LDO's and MOSFETs from TI on sample as they delivered the power reg boards incredibly quick from their base in the US to the UK - 2 days all in!

Any other hints on stuff I may be able to get while I'm there will be a great help too :)

Leigh
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on July 25, 2012, 07:40:24 PM
TI makes good stuff.  They make good LDO regulators and and good charger controllers.  I've never even looked at their MOSFETS.  Every time I do parametric searches on vendor sites, it's always the Fairchild MOSFETs that have the best specs and pricing.  So now I just head straight to Fairchild's web site.  They'll send you free samples for the asking. 

http://www.fairchildsemi.com/search/tree/power-management/mosfets/discrete-mosfets/

Microchip makes LDO regulators with really good precision if you want a solid voltage reference. They have 0.5% accuracy where most are 2%.  They won't send me samples anymore though.  Not sure what I did to piss them off or if they just aren't sending them to anybody.

I don't use any of the Microchip LDOs right now because I need ultra low drop-out and ultra low IQ for my mods.  On Semiconductor makes the best LDO regulators for that kind of thing.  I'm using an NCV551.  They offer samples, but you have to pay shipping and handling which can make them cost more than if you buy them from Mouser or somebody.  Though, if I can't find stock, it's a way to get the parts in small quantities.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: sterling101 on July 25, 2012, 08:16:59 PM
I tried ordering a few samples earlier from Fairchild but it wouldn't let me do it.  Said something about it not meeting their sample order criteria.  I'm guessing it's because I'm in the UK they don't want to ship overseas :(

Still, if I can find some adequately suitable stuff from TI it'll be a good starting point to populate the breadboard!

I've started a new topic so I can put bits on there instead of filling Dave's thread up too much as I'll be working on some block diagrams tomorrow prior to transferring onto a schematic so I should have something worth looking at within 48 hours :)
Title: Re: 1st Attempt w/ a Microcontroller
Post by: TubeWatts on July 25, 2012, 10:15:04 PM
Ok well first off this is a TON of information to take in for someone who has never done anything like this before but i like a challenge haha. I am planning on making a box mod but start out with it just hanging out to get it down. Im going to be using:

Arduino Mini Pro 3.3v
FTDI Breakout 3.3v
Serial enabled 16x2 or Basic 16x2 LCD
      With 2 display settings via button
          Display 1, Line 1
             Volts, Current
          Display 1, Line 2
             Battery Guage(4 bar like cell phone or percent), Watts
         
          Display 2, Line 1
             Battery Volts loaded and unloaded
          Display 2, Line 2
             Ohm's for atty, and i cant think of anything for a second reading yet. (i might put the battery percent here)
Ok so now for the questions.

I am going to be using 1 18650 aw imr. Which is unprotected because i want to code in a 3.0V power cutoff but i havent been able to find how to do it.
 or would it just be better to get some protected batts.

Also i am a bit confused how i am going to get the current reading. I have heard of people using something like a current meter of something like that. I know i can get the voltage reading with the arduino but i need current so i can use the arithmetic to get watts and ohms.

Lastly i have heard of circuits used to measure discharge rate of batterys because i want to get accurate battery life. Do any of you know how to do this. I did a quick search on candle power but didnt find much about the actual circuit for it.

Thanks guys this has got to be one of the most inspiring forums. I have got so many ideas bouncing around i have a hard time keeping the organized haha.

Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on July 26, 2012, 02:48:25 AM
Hehe, I know what you mean about project overload.  I had three going at one point, but I finished one and put the other on the back burner.

For a single cell, you can make a cut-out pretty easily with a voltage detector and MOSFET.  If using an MCU, you can use a voltage detector to drive your LDO regulator's enable pin.  That will shut down the MCU and drop current draw close to zero on low voltage detection if you set things up right.

http://www.onsemi.com/PowerSolutions/product.do?id=NCP300

The other option, like you said, is to use a protected batt.  The only time you really need an IMR cell or other high drain cell is if you are driving a booster or using a low resistance atomizer with a smaller cell like a 14500.

To get a current reading, you use the MCU's ADC (analog to digital converter).  You need a signal proportional to current flow.  You can get it with a current sensing chip or with a current sense resistor and differential amplifier.  You can use a higher value current sense resistor to eliminate the need for an amplifier, but it wastes a lot of power.  The current sense chip is the easiest, most efficient way to go.  One you have a return value from the ADC for current sense, you just do a little math in code to convert it to an actual amperage value.

Voltage is set by the user so it's known unless you are using variable wattage.  With a current measurement, you can calculate resistance and power in code by dividing or multiplying voltage and current.  You could use an ohmmeter circuit to measure resistance prior to energizing the atomizer, but that's the hard way to do it.

To set up your battery capacity indicator, you measure cell voltage with the MCU's ADC.  Then you use a table in code to assign battery levels to ADC measurements.  You need a discharge curve for the cell.  You can plot that manually with a stopwatch and a load bank.

A load bank can be made easily and cheaply with 1/2 Ohm 50W wire wound resistors in series.  You just use test clips on the connections between them to get various loads.  You'll use the hell out of it in testing.  You can mix up the values a little if you want particular resistances.  For example, throw a 1 ohm in there and a couple 1/4 ohm ones.  Bolt the resistors to a heavier gauge aluminum plate.  Some heatsinks glued on to the plate with heatsink epoxy are helpful as well.

Another thing you can do for a makeshift load is buy a 10 ft length of 16 AWG nichrome wire.  You can just put test clips at various points on the wire coil to get exacting loads up to 3 Ohms.  Though the wire can get pretty hot and melt your test clips if using the little plastic ones (speaking from experience).

Okay, hope that helps.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on July 26, 2012, 08:17:20 AM
Boy there has sure been a lot of interest in building MCU mods here and on other forums.
I hope in a couple months when the vapers community are dominated with MCU mods by the new breed of modders  :thumbsup: , Craig and I are not forgotten... Craig who??? breaktru who???   :laughing2:
Title: Re: 1st Attempt w/ a Microcontroller
Post by: poorboy on July 26, 2012, 10:55:32 AM
Iam learning a lot just by reading your threads breaktru and craig. Im also reading this http://www.ladyada.net/learn/arduino/ . The only thing thats bothering me is how to start with my own sketch. :( i really hate math!
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Pantera on July 26, 2012, 11:24:30 AM
Iam learning a lot just by reading your threads breaktru and craig. Im also reading this http://www.ladyada.net/learn/arduino/ . The only thing thats bothering me is how to start with my own sketch. :( i really hate math!

If I'm not mistaken, math will have some relevance in programming at some point.  :Thinking:
Title: Re: 1st Attempt w/ a Microcontroller
Post by: poorboy on July 26, 2012, 11:33:23 AM
Yes it is i guess i'll be using a calculator once again. :)
Title: Re: 1st Attempt w/ a Microcontroller
Post by: TubeWatts on July 26, 2012, 04:09:07 PM
Thanks Craig tons of useful information.

Alright well i spent a good 6 hours last night trying to figure out this problem and find the right chips to use so check this out and tell me what you guys think about this.

I was looking at this for the circuits. http://breaktru.com/smf/index.php?action=dlattach;topic=244.0;attach=449;image

And i noticed that you only have power going to your D.P. when your actually firing the device so how do you change voltage when your not firing?
Well i thought about it and i found a new DP that might work AD5112 its a I2C 64 tap that im going to use connected to the Arduino instead of using buttons straight off the DP. I know ill still need buttons but changing the voltage by serial seems easier.

Then i still have the problem of the MOSFET firing both chips at once. So what i was also thinking is using a Switch connected to one of Arduino's I/O's that whenever i press a UC or DC it turns the AD5112 on for about 5 sec then shuts it off. But when you fire the device it powers up both. I think i could also use the INHIBIT pin on the 08100 but i dont know how that one works. Or would it be fine to leave the DP on all of the time (current draw?)

Then i noticed at the top of the same schematic it says V1 is 7.4-8.4v. I plan on using all 3.3v boards and equipment so what would i need to change?
Title: Re: 1st Attempt w/ a Microcontroller
Post by: CraigHB on July 26, 2012, 05:00:26 PM
A pot with 64 taps is probably not going to be good enough resolution.  The pot I use is 256 taps.  I used 128 taps on my first attempt at a mod with a digital pot and still had trouble getting the accuracy I wanted, though 128 taps is probably okay if you're not picky.

My solution to the problems you are discussing is to run the MCU full time and just put it to sleep when it doesn't need to do anything.  All MCUs have a low power sleep mode.  An LDO regulator (for the MCU) with low quiescent current draw can get idle current consumption down quite low, in the tens of micro-amps.  You set up the MCU so it wakes up when a button is pushed.  Then run a timer in code that puts the MCU into sleep mode after a time of inactivity.
Title: Re: 1st Attempt w/ a Microcontroller
Post by: TubeWatts on July 27, 2012, 06:21:29 PM
Hmmm.. i thought anything bigger than a 64 would be too many. Im a definite electronics noob!! Which one would you recommend?
Title: Re: 1st Attempt w/ a Microcontroller
Post by: Breaktru on July 27, 2012, 06:26:22 PM
Hmmm.. i thought anything bigger than a 64 would be too many. Im a definite electronics noob!! Which one would you recommend?

The more steps the better/finer the adjustment. If you take the number of steps and divide them into the DP total resistance you can figure out how many ohms each step would increment/decrement.