PIC16f1782 based Switching PSU - Page 1
Forum section: electronics / projects

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 15, 2015, 05:47:07 pm
content: Decided it was time to have a look at some of the newer 8bit offerings from Microchip, been using 16F628 16F684 etc for a long time, but the new generation does look quite interesting, lots of features and very cheap.So I thought it would be interesting to try do something with the PSMC (programmable switchmode) based on my previous experiments using a dsPIC33/pic24h (https://www.eevblog.com/forum/projects/multiphase-buck-converter-controlled-by-uc-with-cv-and-cc/msg342537/#msg342537)Would be interesting to do something similar with this little 8 bit.Feature wise, it's got 12 bit ADCs (single ended/differential), Fast comparators, Rail-to-rail opamps, programmable reference, 8 bit DAC, UART, I2C, EEPROM, CCP, PSMC (64MHz resolution), loads of timers and interrupts, but only 2 kB of flash and 256 bytes RAM.Full details:http://ww1.microchip.com/downloads/en/DeviceDoc/40001579E.pdfAnyway, first step, being able to plug it into a breadboard:Experience tells me that a bread board features test, before making a PCB, is well worth the time, otherwise too many assumptions easily turn out not to be true.

author: Paul Price
author_rank: Super Contributor
timestamp: February 15, 2015, 06:01:12 pm
content: PIC16F1788 has 16K flash and 2048 data RAM and it is not much more expensive, not to mention there are 8 k and 4k flash types in between.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 15, 2015, 06:08:10 pm
content: Quote from: Paul Price on February 15, 2015, 06:01:12 pmThanks, yeah, it's nice they do have offerings with the same feature set and different amounts of FLASH and RAM, I am hoping I can squeeze what I need into the 2kB, should be sufficient, but if things get out of hand, it's always nice to be able to just upgrade to the next available instead of having to go into some time consuming hand optimized assembly rewrite.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 15, 2015, 06:15:05 pm
content: Feature testing, no issues so far:I want to have 2 phases offset by 180 degrees, it does not support that directly, but with a bit of workaround it does it just fine. The PSMC modules do have quite a lot of modes and features, everything from single PWM to 3 phase motor control pwn, push-pull with or without complementary outputs etc.I'll try with 250kHz, giving 8 bit resolution.

author: Paul Price
author_rank: Super Contributor
timestamp: February 15, 2015, 06:24:12 pm
content: Your attempt to cut cost with a 2K flash doesn't make sense. The 16K flash part is only 1.25 more expensive, but trying to optimize your code to fit into 2k would be 1000.25% more expensive in programming total time spent and the perhaps the ultimate result of all this extra effort would likely compromise functionality and ease of use, etc..you gain little, but perhaps loose time, performance and overall quality of the finished product..that is unless you are seeking to make something so simple it might not be nice to work with.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 15, 2015, 06:25:25 pm
content: My only issue is a fluffy fat cat that likes to sleep on my table as soon as I go make a cup of coffee

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 15, 2015, 06:29:14 pm
content: Quote from: Paul Price on February 15, 2015, 06:24:12 pmI think you misunderstood me, I don't expect to have any issues with the 2kB Flash limit (I might get wiser) but generally with 8 bits, I never use floats and do calculations in integers shifting left and right for precision etc.If I get into trouble, I'll surely update before considering serious optimizations.

author: SeanB
author_rank: Super Contributor
timestamp: February 15, 2015, 06:30:22 pm
content: Pay more attention to the cat, or place a hot resistor in the middle of the table.

author: Paul Price
author_rank: Super Contributor
timestamp: February 15, 2015, 06:42:34 pm
content: Perhaps the cat has realized that the 16K part is readily available in a 28-pin skinny-dip, so no breakout adapter card is necessary at all.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 15, 2015, 06:47:47 pm
content: Quote from: SeanB on February 15, 2015, 06:30:22 pm... I'm sure something hot would do it, but not only warm, that just attracts cats.But on a serious note, I do need to be careful when working with higher voltages. I don't think my better part would be proud of me if I electrocute any of the cats

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 15, 2015, 06:50:56 pm
content: Quote from: Paul Price on February 15, 2015, 06:42:34 pmPossible, but she seems more interested in tuna... puny human technology only invokes limited interest unless it's warm and worth sleeping on.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 15, 2015, 07:01:23 pm
content: Anyway, pinout for the pinout puzzle game. It does have quite a few remappable features, which is very nice when trying to use a lot of the included features.

author: dannyf
author_rank: Super Contributor
timestamp: February 15, 2015, 07:13:55 pm
content: Nice work. Looking forward to seeing what will come out of this.

author: dannyf
author_rank: Super Contributor
timestamp: February 15, 2015, 07:15:39 pm
content: QuoteRemappable pins are coming to the lower range mcus. Still, the 24F parts excel in that.Why did you decide to start this instead of finishing the 24F project?

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 01:14:38 pm
content: Time to build a prototype on PCB. Made a little board that hopefully will work as intended.Made it double sided to get better ground.Front:back:Came out OK, but it was a pain as I broke a bit half way though.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 01:23:48 pm
content: Quote from: dannyf on February 15, 2015, 07:15:39 pmYeah, I love the remappable features in pic24, makes it so much easier to do layouts and sometimes saves your ass when you make mistakesThe initial project was really just playing around to see how well it would work, but something useful could be made out of it, the performance was pretty good. I used the pic24H part in that project (identical to dspic33).

author: Pjotr
author_rank: Frequent Contributor
timestamp: February 19, 2015, 01:25:25 pm
content: Quote from: AcHmed99 on February 15, 2015, 07:38:46 pmI wonder. We have had finally lengthy discussions about those bugs some years ago with engineers of Microchip. They were well aware of the bugs, but nothing of it in the data sheet errata about it. Also they didn't plan to to fix them. Made the Pics unusable for the converter then (a phase shifted H-bridge).

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 01:34:12 pm
content: Quote from: AcHmed99 on February 15, 2015, 07:38:46 pmI don't expect to need more than 1k. Feature wise, I'll be using 4xADC, 1xReference, 2xComparator, 2xOpAmp, Timer(s) and ADC interrupts, plus various IO pins for display, LED etc.I did check the errata, appears they got most of the bugs fixed, errata only goes to revision 4, but according to my pickit the ones I got are revision 6, so I don't expect any surprises. (well I guess it wouldn't be a surprise if you expected it)Edit: And of course the PSMC module, I use the push-pull mode (without complementary) to get 2 phases, and to get more than 50% duty cycle, I just invert the outputs.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 02:20:49 pm
content: Started populating the board, just the basics to get it up and running, power, MCU, display and ICSP.All good so far, but then again, it's not really doing much yet

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 03:56:02 pm
content: More progress, getting close to functional:

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 04:14:35 pm
content: While the top side is kept nice old school looking (aesthetic design decision), the bottom is somewhat more interesting:

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 04:21:45 pm
content: Feature wise, the goals are:Input: 10-28VOutput: 0-20V, 0 - 4A (buck only, so max Vout = Vin - a few 100mV)CV/CC capable, 2 phase design for minimal ripple.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 05:02:34 pm
content: A couple of quick ripple measurements (20MHz limited, using ground spring, between out+ and out-)12V in 5V out, 1A load:12V in 5V out 2A load:Looks almost too good to be true.

author: Howardlong
author_rank: Super Contributor
timestamp: February 19, 2015, 05:35:54 pm
content: Very nice!I spent some time with an MCP19111 over a year ago, in an attempt to make a synchronous buck SMPS whose switching frequency could be controlled with the intention of using it to do a 2S Li-Ion charger from 12 to 14V. The possibility of using such a device seemed most enticing.In the end it was all too hard, the device would not work without external current sensing devices if trying to use on 8.4V, which negated its benefits of reducing BOM line items. The datasheet says it could be done with a simple potential divider to get the voltage levels back to the device's range, but that's just not gonna work when you look a bit further into it!Before that I spent a short amount of time on their dsPIC33s on an SMPS design, but turns out there's zero point using them on a low power device: the high resolution PWMs required in the PID loop dissipate way too much power, more than the CPU core in fact.Maybe I should take another look at this as a solution.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 06:05:48 pm
content: Quote from: Howardlong on February 19, 2015, 05:35:54 pmThanksI think this little 16F178x is close to perfectly configured for a Li-ion charger, you get 2x switch mode module, fast comparators for improved voltage and current control (pulse skipping etc), opamps for amplifying current shunt, internal reference for accuracy, fairly high res ADCs (12 bit/100ksps) for monitoring. built in DAC. and a lot cheaper than a dspic33So far I've been impressed by this little 8 bit.The switch mode module is quite flexible:

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 19, 2015, 06:29:50 pm
content: Quote from: Howardlong on February 19, 2015, 05:35:54 pmSome hints in this presentation:http://eshare.stust.edu.tw/EshareFile/2012_12/2012_12_31d01d74.pdfbut it would be nice if Microchip would put together a complete appnote for common applications like a charger circuit.

author: Howardlong
author_rank: Super Contributor
timestamp: February 19, 2015, 07:06:52 pm
content: Quote from: jaxbird on February 19, 2015, 06:29:50 pmAgreed. As I remember it (and I could well be misremembering!), on the MCP19111, it has a high side current sense, but for 2S that would take the acceptable current sense voltage outside the device's operating range. The datasheet mentions using potential dividers... well, you could do, but you'll need to have _very_ accurate and thermally stable, or at least matched, resistors to make that work. As I said, all too hard!But I am super impressed with the regulation of your solution.

author: retemitlum
author_rank: Newbie
timestamp: February 19, 2015, 10:08:12 pm
content: Check the ground connection for the decoupling capacitor on pin 20.To me it seems that there is several centimeters, from the ground of the capacitor to the ground of the PIC.I would suggest that you flip the capacitor, so it is connected directly between pin 19 and 20.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 20, 2015, 11:53:11 am
content: Quote from: retemitlum on February 19, 2015, 10:08:12 pmGood catchyeah, I better flip that capacitor around to the other side.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 22, 2015, 05:45:33 pm
content: Fully assembled and fully functional, still needs a bit of fine tuning here and there, but meets the goals I set for the project.Now I just need to measure the performance and fine tune it.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 22, 2015, 06:02:21 pm
content: Quote from: Howardlong on February 19, 2015, 07:06:52 pmYeah, ideally you'd want to use some external high side current sense chip with this pic16. In this project I'm using low side sensing, but one down side to this, is that I need to use an external opamp for differential output voltage sense.Regulation is quite good for a switchmode, but I am using a few tricks that waste some power and lower efficiency but improve regulation, like, I try not to skip pulses as it gives a cleaner output with continuous PWM, but it does burn some extra power driving the gates, and I load the output with a constant current (~50mA) plus I can adjust this load up to ~250mA in 7 steps (3 bits) to minimize overshoot when external load is small.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 22, 2015, 06:05:32 pm
content: Not sure how I feel about the compiler calling my code degenerateSure I know what it's telling me, but really.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 22, 2015, 06:17:50 pm
content: Since I have a lot of unused flash and ram left with all the core functionality implemented. (not directed at any anyone in particular)I think I'll add some elaborate multi point calibration procedure with interpolation for both voltage and current and store it in eeprom.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 22, 2015, 08:42:24 pm
content: Few measurements, first the outputs when device is powered on (seems a lot of PSUs get this wrong):Power On:(Not even a tiny peak in there, all good)Switch On 5V into no load:(some tiny overshoot with no load, can probably improve that)And switch Off no load:(Really just discharging the smallish output capacitors)

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 22, 2015, 09:06:11 pm
content: Resistor test load:Switch on into this load 5V and ~1A:

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 22, 2015, 09:18:26 pm
content: Switch on into resistor load but with current limit set to 500mA:No overshoot, but oscillation in CC mode, need to have a look at that.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 22, 2015, 09:42:53 pm
content: Brewed some coffee, and the cat is back again

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 22, 2015, 10:50:59 pm
content: Dynamic testing, @5V, switching between 500mA and 1500mA Load:From 500mA to 1500mA:And 1500mA to 500mA:Not the fastest recovery in the world, but most important, there is not much overshoot.

author: dannyf
author_rank: Super Contributor
timestamp: February 22, 2015, 11:07:46 pm
content: Nice work.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 23, 2015, 12:06:21 am
content: Quote from: dannyf on February 22, 2015, 11:07:46 pmThanks, yeah, I think not bad for less than ~$15 in parts.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 23, 2015, 12:09:26 am
content: Quote from: jaxbird on February 22, 2015, 09:18:26 pmHad a look at this oscillation, the "gain" in the cc feedback loop was too high, minor code change and it's much improved:Same test switch on into 500mA CC limited:

author: dannyf
author_rank: Super Contributor
timestamp: February 23, 2015, 12:30:51 am
content: QuoteYeah. The important thing is in the doing - something about the journey,

author: void_error
author_rank: Frequent Contributor
timestamp: February 23, 2015, 01:26:26 am
content: Quote from: jaxbird on February 22, 2015, 09:42:53 pmYou need another workbench. Cat can't be on both at the same time.Nice project btw, I'll have a go at a PIC with PSMC when the need for something like this arises, or probably just for fun.

author: bbjk7
author_rank: Contributor
timestamp: February 23, 2015, 05:29:45 am
content: Quote from: jaxbird on February 22, 2015, 09:06:11 pmIs that the bottom of a UNI-T 61E I spy? HEATHEN!! Dave would be very displeased...Kidding ofcourse, it's the best multimeter I currently ownNice work.. wanted to do something similar myself, just lacking time, motivation and expertise...

author: Richard Head
author_rank: Frequent Contributor
timestamp: February 23, 2015, 05:41:50 am
content: The lovely fluffy cat looks like a serious static generator.

author: Kalvin
author_rank: Super Contributor
timestamp: February 23, 2015, 06:48:36 am
content: Quote from: void_error on February 23, 2015, 01:26:26 amWrong assumption. It is a cat, so it can be at two different positions at the same time (seehttp://en.wikipedia.org/wiki/Schr%C3%B6dinger%27s_cat). He needs three workbenches to be sure.Thought about this a bit more. N benches doesn't solve the problem. I would state this more generally: No matter how many workbenches one may have, the person's current position will predict in 97.3% probability what is the cat's next position.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 24, 2015, 12:13:40 pm
content: Quote from: dannyf on February 23, 2015, 12:30:51 amAbsolutely .. this project was most about getting familiar with the new generation of PIC16 and having a go at using the PSMC feature, but also fun to design a small PSU, not so much because I desperately need more power supplies, but hey, can't have too many power supplies

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 24, 2015, 12:31:14 pm
content: Quote from: bbjk7 on February 23, 2015, 05:29:45 amSure is, a decent little meter. I don't think Dave would approve of any of my equipmentBut as they say, it's not about how you are equipped, but what you can do with what you got

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 24, 2015, 12:49:26 pm
content: Had a look in my box of power bricks, got a few of these, I believe they came from some LCD monitors, should be a good match for this project:

author: albert22
author_rank: Regular Contributor
timestamp: February 24, 2015, 07:45:35 pm
content: Nice work !Could you please give us a brief description on how the control loop works?Thanks

author: jlmoon
author_rank: Unknown
timestamp: February 24, 2015, 07:52:52 pm
content: Quote from: jaxbird on February 15, 2015, 06:25:25 pmOh look... a mobile ESD generator!

author: senso
author_rank: Frequent Contributor
timestamp: February 24, 2015, 08:24:30 pm
content: Nice work.Its just a matter of giving the cat an anti-static collar and a long cable.My cats also love to sleep in my laptop..

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 25, 2015, 05:02:26 pm
content: Quote from: Kalvin on February 23, 2015, 06:48:36 amIt is well known that cats have developed technology allowing spontaneous short distance teleportation when they are not being observed:? - Stalking Cat -

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 25, 2015, 05:12:16 pm
content: Anyway, since this little PSU works quite well, I think it deserves a proper box.Bottom part:

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 25, 2015, 05:32:34 pm
content: Was about to start the old 3D printer when I wanted to move some cables around, I noticed the power connector seemed stuck, well, actually it's meltedA bit strange, as it is 10A rated, and I know the printer only requires close to 10A while warming up both the extruder and print surface at the same time, that should only be about 5-10% of the time, rest of the time the current is below 3A. And I don't believe the plug/socket is some cheap copy.Anyway, it's probably done close to 1000 hours of printing, so I'll just replace the plug, clean the socket and check on it once in a while.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 25, 2015, 06:00:31 pm
content: Quote from: Richard Head on February 23, 2015, 05:41:50 amYeah, long haired cats do tend to generate static, but it's really not much of an issue, got pretty high humidity. And I do assembly in another room where no cats are allowed. This is more my test and programming bench.Datasheets seem to lack specs using the feline body model

author: SeanB
author_rank: Super Contributor
timestamp: February 25, 2015, 06:25:42 pm
content: The 10A rating for the plug and socket is there with a caveat. The allowed insert remove cycles for that to be valid is 5, after that the contacts inside are likely to be too loose, giving the cooked socket you have. If the socket has had a few dozen cycles it is no longer going to do 10A reliably. Ideally you only want it to be used one time from new, but they give 5 cycles typically because some will be taken up in testing.Vibration also reduces the contact tension. That is why the circular military connectors cost the price they do, as they are designed and built to still pass the rated current reliably after 500 insert remove cycles, and are all tested to exceed that at a minimum. After around 5000 cycles you might see an increase in resistance.

author: Christopher
author_rank: Frequent Contributor
timestamp: February 25, 2015, 06:28:22 pm
content: Very nice project so far. I'm keeping watch. What's the final end project? Looks like a bench PSU to me.Would be interesting to see schematics of your buck regulator part and the design choices you have made

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 26, 2015, 01:15:41 am
content: Small box complete, cute little power supply:It will deliver up to 80W, still need to do some thermal measurements, things do start to heat up at 4A, nothing alarming though.Should probably have used some 10 turn pots, it can be a bit hard to set exact voltage and current.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 26, 2015, 06:16:53 pm
content: Quote from: SeanB on February 25, 2015, 06:25:42 pmGood info thanksIt's not a connector I usually plug in and out a lot, probably been years since last time. But that said, I most likely did plug it in and out a lot back when I built the printer.And all the vibrations probably helped age it as you mentioned. I think I'll solder in some screw terminals instead whenever convenient.

author: jaxbird
author_rank: Frequent Contributor
timestamp: February 26, 2015, 06:44:30 pm
content: Quote from: albert22 on February 24, 2015, 07:45:35 pmI use both hardware control (comparators) and software control. After some experiments I found that I can get a cleaner output via pure software control, but it's nice to have the hardware control as a safety. So what I do is regulating the output in software slightly below the comparator threshold.Of course it is a bit tricky to get a well performing/fast software control loop with both ADC sampling and regulating duty cycle. No floating points, and no division or even multiplication, just shifting, adding and subtracting.It is basically an integrating controller with conditions.I have experimented with PID control as well, but a simple PID algorithm with fixed tuning does not work well, as conditions change when e.g. load changes, so while it can perform even better it gets a bit complex.

author: albert22
author_rank: Regular Contributor
timestamp: March 01, 2015, 06:45:48 pm
content: Thanks a lot

author: jaxbird
author_rank: Frequent Contributor
timestamp: March 13, 2015, 02:55:33 pm
content: Quote from: Christopher on February 25, 2015, 06:28:22 pmYeah I guess I didn't really clearly specify my project specs. Actually my primary goal was low noise and minimum output ripple, hence the two phases and close attention to controlling the switching.Schematic wise it's really very simple, just 2 synchronous buck converters 180 degrees out of phase to minimize the ripple.I am using pretty shitty general purpose capacitors ($0.1 each) to prove a point. but a well designed LC filter is very effective even with shitty components.