gfxgfx
 
Please login or register.

Login with username, password and session length
logo
 
gfx gfx
gfx
19852 Posts in 1275 Topics by 5182 Members - Latest Member: charbuild March 28, 2024, 03:39:15 PM
*
gfx* Home | Help | Search | Login | Register | gfx
gfx
Breaktru Forum  |  eCigarette Forum  |  Modding  |  Topic: Beginnings of another MCU mod - but using PWM
gfx
gfxgfx
 

Author Topic: Beginnings of another MCU mod - but using PWM  (Read 107617 times)

0 Members and 5 Guests are viewing this topic.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Beginnings of another MCU mod - but using PWM
« on: July 25, 2012, 07:21:24 PM »
Having seen the post by asnider about using PWM to drive the atomizer and it's associated benefits pn battery life I thought I'd give it a go as part of a tube mod.

I've got a stainless steel cigar holder which is perfect for transforming into a mod and should have just enough room inside to fit a small display, a couple of buttons for settings and a main button for firing the atomizer.

I'll be using the MCU to drive the atomizer in a PWM pattern which should allow for a reasonable level of control over a simulated 3-6v range.  I'll be using two Ultrafire 16350 batteries initially but might move up to some 18350's if it all works out ok for even more capacity.

As yet things are very much in the design stage but I'll upload pictures and info as I progress through and don't be surprised to get the odd dumb question from me from time to time as it will be my first VV mod although I've got a few years MCU design/build experience under my belt :)

Leigh 

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #1 on: July 26, 2012, 03:44:35 AM »
Should be really interesting.  Look forward to hearing about it.

When I saw the post some time ago using a 555 chip, I thought, "that's kind of weak, should be using an MCU."  Good to see someone is going to have a go doing it the right way.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #2 on: July 26, 2012, 06:12:16 PM »
Well tonight I successfully made a button turn on a PWM driven light - oh how long it's been and how much stuff that used to be readily to hand has gone missing after a house move!

Still, have got quite a lot on the way from TI including MOSFETs, LDO's and Current Sensors so should have some fun times ahead!
Been measuring up too and think I may have to go with touch switches for the controls and a tactile I've got which is 12mm, but it seems to work well, for the actual main atomizer trigger.  I'm waiting on a 4 digit voltmeter to arrive which supposed to be very small (lavatube small) but that will decide my controls ultimately.  Space wise though I'm going to go with a PIC16F876 @ 20MHz as they're relatively compact, have all the inputs and outputs I need and most importantly I've got a few knocking about so it's a no cost option for me :)

Will try and get all the ideas I've got on paper into some kind of order and make a post up here with a schematic soon so you can get some idea of how it will all tie together.

But for now - light goes on.... light goes off.... light goes on.... light goes off....  :D

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #3 on: July 26, 2012, 06:40:52 PM »
Just took a few shots of the cigar tube - around 22mm diameter by 160mm long.

Online Breaktru

  • Administrator
  • PV Master
  • *****
  • Joined: Nov 2008
  • Location: NY
  • Posts: 3344
  • Karma: +792/-4
  • Gender: Male
  • PLEASE participate in this forum
Re: Beginnings of another MCU mod - but using PWM
« Reply #4 on: July 26, 2012, 07:07:05 PM »
Sounds like we have a winner in the mix  ;cheers;
Can't wait to see more photos as it progresses  :yes"
Nice going mate

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #5 on: July 26, 2012, 09:19:00 PM »
As the atomizer will be driven at battery voltage via the MOSFET I needed a way to compensate for the battery drain.  At full 8.2 volts for both cells it's a nice easy job of setting the PWM duty cycle to match the required voltage eg. 6.15v=8.2v/0.75 so a 0.75 duty cycle.  However at say 7v from the batteries the same equation would give 5.25v so to compensate for the drift a pre-calculation has to be made.
As I'll be using a 256 division duty cycle the formula is relatively straight forward.  As 0.75x256=192 the equation would look like this...
If the battery voltage is at 7v - (7v x 192) ÷ 256 = 5.25v
So to correct the output we take a ratio between the nominal voltage of the fully charge batteries and their current level so 8.2v ÷ 7v = 1.17 now use this ratio to multiply the duty cycle and we get 192x1.17=225.
Apply this in our original formula (7v x 225) ÷ 256 = 6.15v which is what we're after!

This works even at a random value say 6.82v - (6.82 x 192) ÷ 256 = 5.1v
The ratio between 8.2 and 6.82 is 1.2 so the PWM duty cycle needs to be 231.
Which gives us (6.82v x 231) ÷ 256 = 6.15v which is what we're after

There are a few floating point rounding issues that mean the final simulated voltage has about a 0.1v margin of error but that's not a drastic amount and I can definitely live with it.

Obviously if the batteries drop below the voltage out this becomes an issue so the battery range will be between full charge and the 3.7v lower end and the MCU will not fire and show a low battery indicator to prevent it from damaging the cells by running them too low.

Leigh

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #6 on: July 27, 2012, 02:28:26 PM »
Sounds like you got the math all worked out.  That's sometimes the hardest part.  Once you have a good idea how you want to do something, the rest often just comes together in a more simple way than you initially expected.

Accuracy is always a matter of the overhead you're willing to pay for in terms of expense and simplicity of design.  That's always a tough one to work out.  What you propose sounds resonable.

That's expected that you need to incorporate sanity routines into your program to protect your circuit.  Nothing unusual there.

It's going to be interesting to see a working circuit.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #7 on: July 27, 2012, 02:45:15 PM »
Well as I'm waiting for components to arrive I started coding the first part today, mainly the battery voltage detection and compensation formula for the PWM outputs.
Next stage is testing the closed loop section.  Still not sure whether to get the values when you press the trigger, or do it say every second or so and process the correction while you're still vaping.
Another first for me as well will be using the MCU's sleep mode and wake up on external trigger - should be nice and easy though all being well :)

I've also been doing a few measurements on the cigar tube and found the 12mm tactile switch that I have which I thought was far too big actually will look ok when mounted.  There should be enough room then to mount the display and switches on one side of the board and have the chips on the other side.  I've decided as well that I should make the longer portion of the tube the main upper body, and the shorter end to house the batteries as it gives me a chance to lop the end off and sleeve it before mounting everything inside and will make the battery negative terminal much easier to mount too.

I'm hoping to get the stuff from TI on Monday so I can get a breadboard set up with the components working, about the only thing I might shout for help on is the MOSFET connections as it's not something I've played with before :)

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #8 on: July 27, 2012, 04:43:19 PM »
I think you'll find that waking and sleeping the MCU is not a big deal.  I think you said you're using a PIC?  Just use the "input change notification" module for the button inputs.  Handle waking in an ISR block of code that disables the interrupt.  Put it to sleep checking a timer with a block in normal code that enables the interrupt.  For user input, you can just poll the buttons like you would if the MCU was not waking and sleeping.

You might need to filter your AD inputs.  A simple low pass filter is usually sufficient.  You'll probably want to sample output in sync with the PWM.  Just read the output bit for the MOSFET gate and take the sample with a small delay on each pulse.  Though careful with that, it can be tricky reading output ports.  If there's an MCU register you can query for the PWM state, that would be better.
« Last Edit: July 27, 2012, 04:55:42 PM by CraigHB »

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #9 on: July 27, 2012, 05:29:09 PM »
I noticed you did a similar thing on your Powerblok 2200 - so it will wake the display for a period while adjustments are made but not when the atomizer is fired.
Do you have a routine in place which actually switches down the MCU into sleep after a period of time or are you running a sleep command as soon as the trigger is released?

I was thinking of having the PIC sleep after 5 seconds if no activity is detected.  Then it could be woken with either the main trigger or voltage adjust buttons.  Or the other option is similar to how you did it with a long press on a button to shut it down.

Do you mean sampling the output from the PWM pin for the closed loop?  I wasn't considering that at all, only reading direct battery voltage at intervals then adjusting the PWM values to suit.

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #10 on: July 28, 2012, 03:21:07 PM »
My device wakes whenever user input is applied, either pushing a button or firing the atomizer.  It logs the event and adjusts the sleep timer accordingly.  For a button push, the sleep timer is set to 10 seconds.  For a trigger push, the sleep timer is set to 1 second.  The delays are fairly arbitray and a matter of preference.  The reason for the short sleep delay after a trigger push is so the charger is not disabled any longer than it has to be.  With my design, the charger goes into standby whenever the MCU is awake.

The rate at which you take your ADC samples is determnined in code.  It's common for MCUs to have max sample rates as high as 500K samples per second.  You'll decide how often to sample in code.  For battery input, you could just sample once before the atomizer is energized.  That might be better since you will have less noise interference when there is no load, no filter required.  Heavy current flow means noise which can interfere with sensitive circuits.

For output, you'll want to monitor current so that's what I was referrring to whan I mentioned taking samples in sync with the PWM.  You'll probably want to filter that AD input since the circuit will be noisy when powering the atomizer.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #11 on: July 28, 2012, 03:40:14 PM »
Yep, that makes sense to me now.

I have a current sensor on the way from TI to try which hopefully should work ok to interface to the PIC.  I'll test that and see if it's going to need filtering as it may or may not depending on how it's output comes through.

Been scribbling stuff down for the circuit today and think a 50/50 split divider for measuring battery volts should work ok.  I can then keep the range as if for one cell so from 4.2 down to 2.7 in 10bit resolution.
And I came to the same conclusion too - take a sample when pressing the trigger then let the PWM run from that sample.  I'll put a max trigger time of 12 seconds in place too which should prevent over-drain on the cells in one go.

And if I do the next stage of adjustment in a completely separate section there shouldn't be any issues about time slicing to fit it all into the CPU cycles.  So basically if you press the trigger, you can't adjust anything.  Likewise if you're pressing the adjustment buttons you can't fire the trigger.

I've chosen a default of 50us sample time on the ADC which should be enough to get the voltage in from the battery ok.  I just need to have a play to get the right frequency on the PWM output as I've got a range of frequencies I can play with on that side of things.

As far as the sleep timer goes I'm still not sure whether to try and include a cold shutdown mode so it's not possible to fire by accident if in a pocket etc.
I agree with your settings of 10 seconds on adjust and 1 second on trigger then wake on any input.  But would definitely like a hard shutdown system, say press the down adjust button for 3 seconds and it will power the system down until the same button has been pressed again for 3 seconds.

I suppose another method would be to include a system like the 5 click on/off on the ego using the trigger.  Might need a bit more work with that though as it needs to know when it needs to be woken up fully.  My first guess would be to go into sleep if the trigger is pressed 5 times within a 2 second period and have it ignore all other inputs except for the trigger to wake.  Then check for the same sequence to get back into the main program loop.

Need a bit more thought on that though before I can say definitely how I'll be able to do it...

Oh and the last thing I thought of while saving the source code file is the mod's name - I called it the PICVari :)

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #12 on: July 28, 2012, 04:35:20 PM »
I can see the gears are turning :)  I know the feeling well.  There's always different ways to do something.  The main thing is that it achieves the end result in an efficient manner.  The only limit is your imagination.  The design is is definitely the most fun part of a project.

A shut down mode is not a hard thing to implement.  I just use a long button press, up button for on, down button for off.  It puts the MCU in a mode where it does not respond to anything but the long button pushes.  It wakes on a button push, sees the off flag, and then rolls over and goes back to sleep without responding.  It's certainly not a master power switch, but it does the same thing in effect.  I'm sure there's other good ways to handle it, but that's how I do it.

Hehe, my files have had different names.  When you settle on a file name, you know you've named your device.  My files are all prefixed with Powerblok.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #13 on: July 28, 2012, 05:36:35 PM »
Now that's a good idea - + for on and - for off.  And I was thinking of storing the default value in the on chip eeprom on change so if the batteries are removed it will remember the last setting.

Only a small thing, but just means if I've found a sweet spot I don't need to dial it in every time :)

I've been looking for a small display for it too.  I've got one of these on the slow boat from China - http://tinyurl.com/cebbn9y which is quite small but for me not really small enough considering what I've got to fit in.  Ideally I'd want a 2 digit display about 15mm wide by 7-10mm tall.  Can't find one though sadly, so I might have to make do with the larger one from ebay :(

It's a shame nobody's come out with a super-sub-minature 4x1 LCD display that would work.  Got one on my watch, but I kinda need that to tell the time :D

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #14 on: July 28, 2012, 07:18:44 PM »
Yes, everyone who builds e-cig mods wants a small numeric LED display.  Haven't seen one yet and everybody has been looking.  You can get pretty small numeric SMD LCDs from the usual supects like Digikey and Mouser, but you need to drive them which is more trouble than they are worth.  Best solution is always going to be a text or graphic display with a serial interface like SPI or I2C.  They're bigger, but they're also much more flexible and can display a lot more information.  The trick is figuring out how to fit one in your enclosure.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #15 on: July 28, 2012, 07:26:15 PM »
Yeah with a tube that's pretty much exactly 20mm diameter it's a tight old squeeze!
Will see what this volt meter looks like when it arrives - might actually fit ok and just need to pop a cover over the hole in the tube.

Found a PIC18F2550 built into a USB stick earlier which I though was a great idea - except it's about 4mm too big for me :(

http://tinyurl.com/c9o2bym

Would make for a great project board though!

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #16 on: July 28, 2012, 07:59:05 PM »
With a 20mm tube mod, you're looking at some serious miniaturization.  Better invest in a good stereo micorscope if you don't have one already :)

Check these out.  Many of them will fit with room to spare.  Since you're running an MCU, you're going to want to drive the digits yourself anyway.

I kind of had a brain fart on that.  The first battery mod I did used an LED display and I put a couple of these together.  Though, I think I ordered the singles only because they were out of stock on the doubles.  No big deal, just harder to assemble.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #17 on: July 28, 2012, 08:09:10 PM »
This (http://tinyurl.com/cvby6kx) looks absolutely perfect size wise!

Just been considering the format for lining things up and I think having the main PCB centered in the tube which will at least give me room above and beneath the board to apply wiring and components.
I know it's going to be tight, but I think it should be just about doable - just may have to cut back on features in favour of practicality :)

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #18 on: July 28, 2012, 09:39:05 PM »
That should do it.

My suggestion would be to sandwich the boards in there.  If you use SMD components each board will only be 4mm thick.  You could easily stack three of them.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #19 on: July 28, 2012, 09:48:55 PM »
Even without using SMD components the main board won't be too thick.  I do have the advantage of having about 3 inches of length to play with until it gets too tight at the battery end so I can spread things out a little if needed.
My main thing though is going to be component placement and ensuring there's no chance of shorting against the sides of the tube.
I might give the inside a gentle spray of paint to assist with that part though :)

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #20 on: July 29, 2012, 09:29:51 PM »
OK stupid question time...

I bought my LC16340 batteries with a charger that was thrown in for free.  All the info is right and it has charge lights for each battery which are red when charging and green when done.

However, if I take a battery that has been on charge for a while and is green on the charger I only see 3.7v not 4.2v as i'd expect.
This is why my ADC calcs looked so far out lol

So, the question is, should my chargerbe outputting 3.7v which it does or I need one that puts out 4.2v for the extra charge?  I've had a look at my old cig-a-like and SD keyring chargers and they both output 5v so I'm proper confused now lol

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #21 on: July 30, 2012, 02:21:12 AM »
LiPo, LiCo, and LiMn 3.7V cells all come off the charger at 4.2V.  If you're getting a reading of anything else after a cell of that type comes off the charger, there's something wrong, probably the charger. 

The terminal charging voltage for a 3.7V Li-Ion has to be exact, 4.2 Volts plus or minus 30mV.  The charger controllers I use are never more than 10mV off.

The LiFePO4 Li-Ions are 3.2 Volts nominal and come off the charger at 3.6V.  If you have one of these types of cells, the only good place for it is the trash bin.

If you don't already have one, invest in a good DMM (digital multi-meter).  Cheap ones can go screwy or they can be way off right out of the box.  For someone planning to do anything with electronics, a good DMM with high accuracy and quality is #1 on the equipment list.

http://www.youtube.com/watch?v=A6mKd5_-abk

http://www.youtube.com/watch?v=n3WGaiYF2sk

http://www.youtube.com/watch?v=3-_dUB8vy8U
« Last Edit: July 30, 2012, 02:29:45 AM by CraigHB »

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #22 on: July 30, 2012, 05:17:49 AM »
That makes sense then - I've got a couple of the LiFePo4's and they came with the same charger so I guess it's the charger at fault!
I'll get a new one made up from the spares I've got lying around - won't be too hard and as they're protected batts I shouldn't need to do too much with them unless I want to build a current sensor in but I don't think I need it off the bat as some of the spare charger's  I've got have a bi-colour LED showing charge status anyway so can just butcher one of those and put it into an enclosure.

Had a load more stuff come from TI this morning too - damn their SMD current sensor's are small!!

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #23 on: July 31, 2012, 01:29:17 PM »
Well the voltage display arrived and it might just work being the size it is - win!


Online Breaktru

  • Administrator
  • PV Master
  • *****
  • Joined: Nov 2008
  • Location: NY
  • Posts: 3344
  • Karma: +792/-4
  • Gender: Male
  • PLEASE participate in this forum
Re: Beginnings of another MCU mod - but using PWM
« Reply #24 on: July 31, 2012, 03:21:59 PM »
nice and slim  :yes"

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #25 on: July 31, 2012, 03:31:41 PM »
It'll actually fit inside the tube dead central and the display then will be just the right distance from the outer edge where the aperture will be cut out.

Looks pretty good too in blue even though it's the brightest thing in the room when it's on :)

Offline banshee

  • Full Member
  • ***
  • Joined: Jan 2012
  • Posts: 25
  • Karma: +8/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #26 on: July 31, 2012, 03:38:30 PM »
That's a nice looking small meter. I see 3-wires. I assume it needs it's own power source?

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #27 on: July 31, 2012, 03:57:14 PM »
Yep, positive feed 4.5-17v then a feed for the meter input.

Should work ok as it's got a nice low drain on it of around 5ma :)

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #28 on: August 10, 2012, 05:18:55 PM »
So after much messing around and killing drill bits I'm just going to use the cigar tube as a basic VV mod - possibly with the PTR08100W and a trimmer.  It's just too damn hard to work with and it's also rather cramped in there for trying to fit everything in :(

I'm still going to do the MCU mod though once I get hold of the right MOSFETs I can use and a decent display to go with it (why can't you find watch style displays anyway these days????).  I'm on the look out for something like a 1" tube which gives me enough room to fit everything in including the buttons, MCU board and have enough room for a display too.

I've been mulling over my MCU options too as using the PWM and needing to monitor and adjust the voltage out based on battery drain means I have to use a PIC with a built in ADC which limits things slightly on the form factor front.
I'm looking at using a PIC16F876A which is a 28 pin DIP configuration as I have those readily available from previous projects.
But I've also noticed some rather handy looking boards with built in regulators on eBay (http://tinyurl.com/cfrr3mv), so I might end up using a smaller set up but that's yet to be decided as I'm keeping my options open on that depending on whether the display ends up driven by the PIC directly or not.

After much thinking and thinking again, my ideal set up would be using a boost board from a single battery to ramp up to 6v.  Then use that 6v driven though the MOSFET to fire the atty.  But again then we come up against the old favourite of space as I don't want a box mod, but something similar in size to a Lavatube or Provari.  I suppose using something like the PTN04050C I could try and squeeze it all in place using an 8 pin PIC to generate the PWM and not worry about the ADC side of things.

See, I'm getting lost in my own thoughts and can't make my mind up where to take it :D

I suppose the first question would be.... Does the output drop as the battery voltage drops on the PTN04050C or does it remain stable until cut off?  I could use an on-chip comparator to shut everything down on low battery voltage so that shouldn't cause too much of an issue all being well.

Online DRA

  • Full Member
  • ***
  • Joined: Mar 2010
  • Posts: 36
  • Karma: +8/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #29 on: August 10, 2012, 06:28:03 PM »
Have you seen Raidy's Cigar tube mod?

http://goo.gl/Dcx8s
« Last Edit: August 10, 2012, 06:31:24 PM by DRA »

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #30 on: August 10, 2012, 06:32:52 PM »
Yeah it was that I saw that originally made the decision for me to buy one to give it a try.

Sadly though I just don't have the metalwork tools to work it properly.  If I had my own machine shop so I could easily cut and drill 1mm thick stainless I'd get it done on the spot lol

Might try a copper pipe for ease of working though and increase the internal diameter from 18mm to 22mm/24mm to help with finding space.  Also means I can use the nice carbon fibre weave fabric I've got to wrap it in to make it look extra sexy :D

Online Breaktru

  • Administrator
  • PV Master
  • *****
  • Joined: Nov 2008
  • Location: NY
  • Posts: 3344
  • Karma: +792/-4
  • Gender: Male
  • PLEASE participate in this forum
Re: Beginnings of another MCU mod - but using PWM
« Reply #31 on: August 10, 2012, 06:35:58 PM »
How about in leather: Cigar Tube

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #32 on: August 10, 2012, 06:40:20 PM »
Well in my box of bits I've got leather, carbon fibre weave vinyl, actual carbon fibre, carbon kevlar, alcantara and general leatherette bits - can you tell I used to trim Miata's for a living?? lol

Just spotted a possible useful MOSFET too - http://tinyurl.com/br5kvlm
Hopefully it should hit the switching levels without generating too much heat... hopefully!

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #33 on: August 10, 2012, 06:42:02 PM »
Also found this display which should fit nicely into a tube mod - http://tinyurl.com/c3ovesp

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #34 on: August 10, 2012, 09:24:07 PM »
Looks like a good one.  The reason you don't see a lot of really small displays is they're usually custom made for products with orders in the thousands.  For example, I could go to Newhaven Display and have them make me an LCD any size I want with any character set I want, but I would have to order 1000 of them.  Only recently have I seen really small ones available off-the-shelf in small quantities, which is good for us.

As far as architecture, you're not going to want to involve PWM externally with a DC-DC converter.  It's no help.  Any DC-DC coverter already comprises a PWM controller.  It would be like running two regulators in series, there's just no sense in it.

If you're thinking in terms of bulding your own PWM controller for a DC-DC converter using an MCU, it's not going to be practical.  The switching frequencies required are too high for the PWM module most MCU's provide.  Then there's the coding which would be be quite a challenge to tune since LC circuits are naturally unstable.  That's why a controller chip is normally used in the first place.  As far as converters go, you'll want to use either a module or build one yourself utilizing a PWM controller chip designed for that purpose.

A boost converter is your only option when limited to a single cell.  PWM is limited to battery voltage which is too low.  When considering a device that utilizes series cells, you have the option.  You'll want to use a either a buck converter or a PWM regulator.  The PWM regulator has some big advantages, but since output is pulsed rather than DC, it can make things a bit convoluted.  However, a PWM regulator is considerably more efficient and has a much lower part count.

With a DC-DC converter, output voltage is not dependant on input voltage.  In other words, even with a low battery, output voltage will be maintained.  There are some caveats with that.  For a boost converter, low input voltage can cause input current demand to exceed the limit for the converter or battery.  In that case, output voltage will fall off.  For a buck converter, if output voltage demand exceeds that of the battery plus droput then output voltage will fall off.  A properly designed system accounts for all conditions and maintains output voltage througout the normal input voltage operating range.

Another consideration is that buck can only reduce voltage and boost can only increase voltage.  Most production VV mods utilize a buck-boost converter to provide a range of voltages above and below the voltage of a single cell.


« Last Edit: August 10, 2012, 10:04:20 PM by CraigHB »

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #35 on: August 10, 2012, 10:00:28 PM »
I was thinking of using the 7 segment meter style but if I'm trying to shrink the whole footprint down it's kinda counter productive due to the amount of signal pins I'd have to use to drive it.
Using an 8x2 lcd should mean I can use a simple pic with 8 pins for the main control and still have enough room to squeeze an lcd driver in too and pass info via a single data line.
Tomorrows task though will be trying to get a lead on some tube that's about an inch which should give me enough room to fit it all in with room to mount everything neatly.
And I might take the angle grinder to this cigar tube to open up the window for this existing voltmeter I've got.  Might try and build a quick mod out of it just for fun too :)

Just read through all 35 pages of Alan's pwm thread on ECF - interesting conclusions there and makes me want to get this sorted even sooner lol

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: PICVari MCU with PWM - WORKING!!
« Reply #36 on: August 11, 2012, 10:58:37 AM »
Well after lifting one of the nice n-channel MOSFETs from the old motherboard I had lying around and popped some tails on it I managed to get a fully working VV breadboard set up today!

Had a small issue at first where it wasn't reading the battery voltage, but it turns out my breadboard has seen many better days and the divider hadn't quite seated right in its hole.  Once that was sorted and the frequency adjusted it's running like a champ!

Next step I suppose is sort out a display of some sort as this volt meter I've got doesn't do rms so you only see a nice battery voltage jumping about a bit and I really want to show the battery voltage and the output simulated voltage which would be a real pain to sort only having a 5v reference and going up to 6v on the VV.

Plenty to think about anyway but for now we're cooking on gas :)

Edit:  Now working with timers in place to cut the atty trigger at 12 seconds and does a forced sleep after 5 seconds of inactivity which is only woken up by the main trigger.  Also does a forced sleep if the battery voltage drops too low.
Still need to work out the cold shutdown, but that's a minor issue considering how well this bloody thing vapes!!!
« Last Edit: August 11, 2012, 06:06:09 PM by sterling101 »

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #37 on: August 12, 2012, 07:12:33 PM »
Ok, for those who might want to see how it all connects up here's a couple of images.

The Schematic has the LCD module on it just so I could work out all the connecting links etc and the PCB has the actual copper traces and also the silkscreen on but that won't go onto the finished board, it's just to help me out when I'm putting it together.
The yellow lines between pads are wire links so I can keep things single sided as I've not actually etched a PCB for something like 18 years - too damn easy outsourcing stuff when you've got the cash, which sadly I no longer have lol

So, if anyone can read all the mess that is the PCB, shout if you see any glaringly bad errors cropping up :D

Edit: Just found one and corrected so I'll set the challenge again - can you see anything wrong with the PCB layout?
« Last Edit: August 12, 2012, 07:31:15 PM by sterling101 »

Online Breaktru

  • Administrator
  • PV Master
  • *****
  • Joined: Nov 2008
  • Location: NY
  • Posts: 3344
  • Karma: +792/-4
  • Gender: Male
  • PLEASE participate in this forum
Re: Beginnings of another MCU mod - but using PWM
« Reply #38 on: August 12, 2012, 07:57:19 PM »
Nice going.. Not knowing much about the PIC and checking the correctness of schematic to PCB, I would like to make only one comment:
Do you think maybe it would be wise to increase the weight of the trace lines for the atty to mosfet to battery do to heavier current? What weight did you use because it looks the same weight as the signal trace lines.
Been there, I have once blown a trace line and fixed it with a jumper wire.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #39 on: August 12, 2012, 08:00:25 PM »
Good thinking Dave - I'm using the same weight for all traces so boosting those up will probably be a very good idea if I can fit it all in :)

Online Breaktru

  • Administrator
  • PV Master
  • *****
  • Joined: Nov 2008
  • Location: NY
  • Posts: 3344
  • Karma: +792/-4
  • Gender: Male
  • PLEASE participate in this forum
Re: Beginnings of another MCU mod - but using PWM
« Reply #40 on: August 12, 2012, 08:04:22 PM »
Good thinking Dave - I'm using the same weight for all traces so boosting those up will probably be a very good idea if I can fit it all in :)

If widening the trace lines are not possible do to space, perhaps you can parallel some wire over the the trace lines and tact them to the components.

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #41 on: August 12, 2012, 08:10:20 PM »
Managed to shuffle the trace a little by the ICSP header so should now be better.  Just loses visibility on a trace under a wire link line but I know it's there so not a problem.

Online Breaktru

  • Administrator
  • PV Master
  • *****
  • Joined: Nov 2008
  • Location: NY
  • Posts: 3344
  • Karma: +792/-4
  • Gender: Male
  • PLEASE participate in this forum
Re: Beginnings of another MCU mod - but using PWM
« Reply #42 on: August 12, 2012, 08:45:44 PM »
Managed to shuffle the trace a little by the ICSP header so should now be better.  Just loses visibility on a trace under a wire link line but I know it's there so not a problem.

Good fix.
Just as a heads up, I have the trace size current relation here: http://breaktru.com/smf/index.php/topic,543.msg3462.html#msg3462

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #43 on: August 12, 2012, 08:49:52 PM »
Great info there!

Looks like a wire link of suitably heavy wire may be in order as using a 6A trip PTC I'd need a 3.5mm trace - about 10% of the board width lol

Offline timesarerough

  • PV Master
  • *******
  • Joined: Apr 2011
  • Username: Virus
  • Posts: 394
  • Karma: +338/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #44 on: August 13, 2012, 12:40:27 AM »
If widening the trace lines are not possible do to space, perhaps you can parallel some wire over the the trace lines and tact them to the components.

This is probably a really dumb question considering that I have VERY little knowledge....but, why not just do a double sided board with a paralleled secondary trace on the reverse side?

Offline CraigHB

  • PV Master
  • *******
  • Joined: Nov 2011
  • Location: Reno, Nevada
  • Posts: 2023
  • Karma: +246/-1
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #45 on: August 13, 2012, 01:20:00 AM »
Not a dumb suggestion at all.  I use a 4 layer board and use wide traces in all 4 layers to carry current to and from the atomizer.

Using the trace width calculator, you can find the heating and the resistance of whatever trace widths you choose.  I can tell you already, they are not nearly wide enough.  You may have to increase the size of your board or use a multi-layer board with traces on both sides.  A 3.5mm width would probably be about the minimum you want for currents up to 5A.  If the traces are a problem, use wires instead.  A 24 AWG copper wire is equal to a 6mm trace width using standard 1 oz copper.

Typically, you want to avoid angles other than 45 and 90 degrees when laying out traces.  You don't *have* to do that, but it's considered proper design etiquette.

Avoid right angles and pockets with traces.  You want to round them with a short 45 degree span.  The reason has to do with the manufacturing process.  Sharp angles and pockets can cause the etchant to over-shoot the corner.  Some board houses will do it automatically as required for the etching process, but that's not guaranteed.

1.5mA is high for a pull-down circuit.  I'd use at 10k pull downs at the minimum.

You can use pull-downs on your tactiles like that and software debounce them if you really want to, but I normally hardware debounce my tactiles with pull-ups (switch on the low side).  Hardware debouncing is better since it also affords some ESD protection.

Dedicate your ICSP clock and data connections.  You'll have trouble if you try to share them.  You have the spare pins for it.  You can run 10k pull-downs on clock and data if you like so they are not floating inputs.  You can also set them as outputs in code if you want to float them.  It will not affect programming.

The LCD and the voltage divider for the ADC are drawing power full time.  If you don't plan to use a master switch to shut the device off when you're not using it, you can use small signal MOSFETs controlled by the MCU to switch them off and on as required.  There's probably no point in putting the MCU to sleep if the hardware still consumes a good amount of power.

There sould be .1uF decoupling capacitors (nothing special, just an MLCC type) as close as possible to the power and ground pins for the LCD and for all VDD-VSS pairs on the MCU.  Some of the PICs have AVDD and AVSS pins as well.  Those should be connected to power and ground unconditionally and also decoupled.

If you are going to submit your board for fabrication, it will be a two layer board by default.  Use a ground plane on the bottom layer.  In other words, a copper fill connected to ground should cover the whole bottom layer.   Ground planes greatly reduce electrical noise which can cause spurious resets or failures in code execution for the MCU.  Run as few traces as possible in the ground plane.  You want to make it as contiguous as you can to optimize its effectiveness.


« Last Edit: August 13, 2012, 02:42:01 AM by CraigHB »

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #46 on: August 13, 2012, 05:02:32 AM »
Cheers for the input Craig - really appreciate it - got to keep reading it now so it all goes in :)

Might go double sided but as this is a play thing really I'm doing it in house as the missus would most likely kill me if I spent the money required to get it made up externally, I'm getting ready for some silent running over the component costs :D
I've just got to get some etching crystals and I've got the rest here to make it up (laser printer, copper cad board etc).  If I do go double sided the wire links will disappear anyway in favour of some through hole links.

Resistor values are something I was going to question anyway - I just popped in a default resistor from the list which just happened to be 3K3 but I've got 10K's in the basket ready for when I place the order.

Was thinking about the LCD and voltage divider last night and came to the same conclusion.  I'm going to have a look at whether there's enough current in this MCU to drive it directly as the LCD I've chosen is incredibly light on power requirements.  Then again it's about half inch by three quarters and I can't tell yet if it has a backlight as the data sheet's a little generic it seems.
The MCU is a fairly new one and has only been released about two months but it has some great internal clock speeds from it's own oscillator and good I/O too while keeping the pin count right down.  That was my main reason for choosing it - multiple A/D channels and lots of CCP modules that can be re-mapped around the chip at will.


Also reading on the current draw I think the battery in and atty out are going to need to be fairly beefy connectors, or just go for through hole wiring which given the tight space may be the best option.

I've upped the board width to 24mm as I now know it won't fit at all into the cigar tube without being far too long or far too fiddly for my dodgy hands lol - am looking at another nice tube here that has an ID of 25mm.  Switches and LCD will sit on a second board that will sit on top of this main one (or below, depending on which way around you're looking at it) I've just got to get this one right and then I can look at that board then.

Have got a few more changes to make then will post a pic up of the current stage - hopefully it'll be getting nearer...

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #47 on: August 13, 2012, 11:08:46 AM »
OK, here's the latest PCB layout.  Have increased dimensions to 24mm x 67mm and increased the trace size for the atty and also shortened the runs quite a lot.
The green traces are wire links - large green=high load wire.  Hopefully with the addition of two transistors, one for the voltage divider and one for the earth for the LCD it should mean I can control the external drains fairly well by switching them on and off as necessary.

Will upload the schematic once I've finished messing with it as I seem to have cocked up and got my pins back to front on a few things - guess that's what happens on 2 hours sleep....
« Last Edit: August 13, 2012, 12:06:27 PM by sterling101 »

Offline sterling101

  • Super Member
  • *****
  • Joined: Jul 2012
  • Location: UK
  • Posts: 180
  • Karma: +16/-0
  • Gender: Male
Re: Beginnings of another MCU mod - but using PWM
« Reply #48 on: August 13, 2012, 03:30:54 PM »
Well here's the new schematic - hopefully it all matches up ok to the PCB.

Forgot to mention I've put a 6 way jumper header in place for the ICSP control so you have the jumpers on pins 1-2 and 5-6 to program and 2-3 and 4-5 for normal operations.  Saves trying to re-arrange the tracks even more and should work fine as it won't be often it'll need to be re-programmed :)

The new wider traces are 3.81mm or 0.150" so should be good for 6A all being well.  Just wondered if anyone else is using PTC fuses and if so what values you've gone for?  I'm looking at using a Multicomp MC36202 which is a 3A hold 6A trip (Info here - http://tinyurl.com/cyo3rt9) which I think should be ok but I'm open to suggestions of better ones if you know of any!

Edit: Forgot to attach the file!
« Last Edit: August 13, 2012, 04:17:45 PM by sterling101 »

Online Breaktru

  • Administrator
  • PV Master
  • *****
  • Joined: Nov 2008
  • Location: NY
  • Posts: 3344
  • Karma: +792/-4
  • Gender: Male
  • PLEASE participate in this forum
Re: Beginnings of another MCU mod - but using PWM
« Reply #49 on: August 13, 2012, 04:12:03 PM »
I use this PTC: http://goo.gl/KeVPw Your 3a / 6a looks fine to me. My PTC has less internal resistance and use two in parallel for even less resistance. Also mine is a lot smaller.
Once you have your mod hard wired, expect to tweak the code a bit. At least that is what I have experienced.
« Last Edit: August 13, 2012, 04:15:08 PM by Breaktru Admin »

Breaktru Forum  |  eCigarette Forum  |  Modding  |  Topic: Beginnings of another MCU mod - but using PWM
 

gfxgfx
gfx gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!