Universal PIC switchmode status report

Universal PIC switchmode status report

I wrote a large part of the software, much could be just cut and paste from other projects, like swr_pic:

formatting link

This adds the following functionality to the 'universal PIC PWM controller'. LCD display with:

1) input voltage 2) output voltage setpoint 3) output voltage 4) output current setpoint 5) output current 6) real time clock

The clock can be used in software to make for example a battery charger timer, etc.

3 free pins for for example: menu select, up, down. That is enough to do most things.

RS232 interface, typing 's' shows all parameters. setpoints can be set via RS232 Setpoints are automatically saved to EEPROM when changed. Manual setting of PWM possible (overrides anything, be careful, just for testing perhaps).

So, that is the software side, the PIC is a 16F690. The software will be published on my site when usable, still have to do the feedback and current limit. The LCD is not needed, just RS232 will do, you can either comment out the 'define USE_LCD' in the asm, or connect a pin to ground to simulate 'LCD ready' Or you can program it one time with the required values for output voltage and current limit, and use the PIC stand alone.

So, now the hardware.

Joerg was so kind to publish a SEPIC design here yesterday, and after looking at that, I thought: 'Why not make this universal PIC controller a SEPIC, as then I can make any voltage (well almost) from any input voltage.' Already started thinking about a new name for the project, like SE-PIC, or SEPIC_PIC or PIC-SEPIC, or even SEE_PIC :-) But I already made directories and files with 'power_pic', so the source is called pwr.asm. _But_ that SEPIC design has *2* inductors. I looked and thought: 'Why not use a transformer, 1:1', (and actually the SEPIC design solves the problem of switching in the negative too, as the ground is simply ground, good for in the car), somebody must have thought of that too', so I typed 'SEPIC 'transformer' in google, and it turned up some nice links, and THIS one really set me going:

formatting link

Now there is one remark this person makes:

One simplification is to use a 1:1 transformer, such as a low-cost, commodity, common-mode power-line input-filter choke, < end quote>

So, yesterday I had this old PC supply, that I use for scrap parts, and noticed that transformer / choke. I thought 'shall I take it out?', but I cannot do anything with it, reluctantly put it back carefully. SO, after reading that remark, went back, soldered it out, put the PIC in the programmer, it already has the RS232 interface, programmed it, 100% OK first time, tried to set the PWM, worked first time, got the scope, looked at the pulses, OK first time.

Wired up that little mains filter as transformer, connected a fast schottky rectifier, the MOSFET, a filter cap, and the SEPIC coupling cap, and a 4W 12 V lightbulb, and 12V DC for test. Worked first time ! ftp://panteltje.com/pub/power_pic/pwr_pic_pwm_20_img_0876.jpg

More images at: ftp://panteltje.com/pub/power_pic/ The toroids at the top are the ones I did not need for this :-) And the board on the left is the 'noppp' (modifed) PIC programmer, the PIC does not leave the programmer until the project is complete, grnd, PWM, and other control signals simply soldered on the PIC.

This is a fun project. Where are you now, dedicated expensive chip manufacturers, do you have a LCD driver, do you have RS232? Do you have EEPROM?

I love it when a plan works (stolen from the A team). Ich liebe es wen ein Plan funktioniert!

Reply to
Jan Panteltje
Loading thread data ...

Universal PIC switchmode status report

Went gradually up in power, using a car headlight (55W) as load: ftp://panteltje.com/pub/power_pic/about_25_watt_img_0881.jpg The caps got hot, so used bigger ones.

Tried to go higher, but a little wire unsoldered itself from the transformer, triggering a huge current, and many of the wires melted (fuse is 30A): ftp://panteltje.com/pub/power_pic/when_things_go_wrong_img_0885.jpg

Replaced the wires, and it works again.

25W seems to be the limit for that mains filter used as transformer, else it gets too hot, makes sense if you think it is wound with rather thin wire too.

Bigger mains filter, or may be wind a toroid after all? The MOSFET did not even get very warm...

So, always use flatcable, auto-fuse mode :-)

Reply to
Jan Panteltje

Universal PIC switchmode status report

Today added the cycle by cycle current limit, it is working here, to limit the current to a low value. cycle_by_cycle_current_limit_current_transformer_img_0891.jpg Note the small ringcore current transformer in the picture. The little trimpot was for test, it is not connected.

This works as follows:

The wire from the source of the power MOSFET forms one turn through small ringcore, the ringcore has 40 turns, so 4 A in the one turn (to make the math simple) results in 100 mA in those 40 turns. A 10 Ohm resistor is the load on the 4O turns, so generates 1 V peak at 4A peak. This voltage is fed to the PIC analog comparator 1 input via a 6k8 resistor, so in case bad things happens, and the output is more then 5V from the current transformer, the current into the PIC via the internal diodes is limited by the 6k8 resistor.

The current transformer also allows one to nicely scope the current, nice linear ramp!

Now, for those who did say that a PIC cannot be fast enough, well it can! The reason is that the PIC designers already though about all this, the analog comparators (yes PIC has 2) have a direct way to stop the PWM output pulse in hardware, and the PWM generator has an auto-restart mode too, so that if the current is low again, the next PWM pulse is generated on time. Datasheet PC16F690 page 143, enhanced PWM auto shutdown mode.

On the other side of the comparator is an on chip reference voltage generator, with 31 settings. See datasheet page 107 voltage reference selection.

So now I can set 31 levels for the current limit via RS232. The picture above has one of the lowest '5', selected, so the light bulb is dimmed, while the cycle by cycle current protection is active.

The current limit already saved a lightbulb, there was '50' programmed as default into the PWM. That was cut and paste code from the time I used the PWM to drive a LCD backlight.. Nice.

Reply to
Jan Panteltje

That's a pretty neat trick. As far as I can tell the regular Atmel AVRs can't do this... anyone know of other PWM peripherals in contemporary microcontrollers that can?

Reply to
Joel Koltner

You should check the electrical specs on that pin. I remember when the PIC 18F series came out the input impedance on the ADC pins went wayy down. And I seem to remember that the old, higher value was 2.5k. The new one was low enough that you couldn't set Aref with a reasonable divider. I don't know if this applies to the comparator, though.

comparators

and the PWM generator has

Interesting, I didn't know that one.

Ironically my best electronic hack of the last 2 days was to *remove* PWM from a lamp which buzzed at any setting. It's so strange to flip a switch and have silent light that I have to remind myself that it's NORMAL for a lamp to be silent...

--
Ben Jackson AD7GD

http://www.ben.com/
Reply to
Ben Jackson

On a sunny day (Thu, 05 Feb 2009 19:09:54 GMT) it happened Ben Jackson wrote in :

Strange, on the 16F690 I did feed the input via a 100k trim pot, that is the one in the picture that is disconnected. Input impedance must be very much higher then that, as it tracked nicely midrange. Microchips does recommend somewhere to use < 10k IIRC.

You did not happen to have a weak pullup active? is that even possible when using analog in? I have all pullups disabled I think.

analog comparators

and the PWM generator has

I drive the LEDs with PWM, they are silent. That reminds me, my RGB LED strips have not arrived yet, must email them.

Reply to
Jan Panteltje

You're going to need more of a path than that.

Reply to
JeffM

ftp://panteltje.com/pub/power_pic/cycle_by_cycle_current_limit_current_transformer_img_0891.jpg

better?

Reply to
Anthony Fremont

On a sunny day (Thu, 5 Feb 2009 14:34:49 -0800 (PST)) it happened JeffM wrote in :

? What do you mean by path?

Read my original postings for the steps planned.

Anyways, from here, there are 3 ways forward, with some sub solutions.

To add voltage feedback, the simplest way is to add a zener from output to this same comparator I think, it will then limit the PWM as the output voltage reaches the zener voltage.

How to add the PID part .. some RC perhaps, how stable that will be, etc, no idea, will have to try.

The second way, is to use the second comparator for output voltage compare to the programmable internal reference, and end up with 31 programmable output voltages, the same PID problems apply.

The third way is to run the AD conversion in the main loop for Iout and Uout, do the PID in software, and have it control the PWM register.

This is accurate, but slower (but not really that slow, as main is idle it can run at max speed doing ADC and math).

The fourth way, and this is a little trick I thought of, is to make a software PWM, and filter that to a precise DC (so DAC), and use that as external reference for comparator 2, compare it to Vout. The disadvantage is that interrupts cause then fluctuations in the soft PWM. This can perhaps be solved by doing that PWM DAC in the clock interrupt. That would make changing output voltages a bit slower, but give you max accuracy.

Of course soft start (the current limit starts at zero and the timer tick slowly increases it to the requested value), is also needed, already wrote most of that. pwr.asm is now 3341 lines long, and there is still plenty of of free space in the chip.

The only really difficult factor in this, is the jingling with IO pins, if I want to keep the LCD interface. But, I still have 4 free pins now :-)

For me, it looks like I will not need a dedicated switcher IC, as the 16F690 is in the drawer. I have used 3 of these now if different projects, and zero problems,

The features of this chip, like 4 PWM outputs, 3 timers, 2 analog comparators, EEPROM, UART, SCC, brownout timer, watchdog, 4kB code space, 12 ADC channels, and much more, make it a very nice thing to work with.

Microchip did a great job with this 16F690, my hat of to them :-)

Reply to
Jan Panteltje

Yes nice. I never seen that one before lots of features and under two bucks. I've been using the 16f28 It might be time to have a closer look at the two and see which has the most features.

Nice snapshots:)

Reply to
Hammy

are,

PWM

s can't

Yep, the PSoC

/Klaus

Reply to
Klaus Kragelund

Universal PIC switchmode status report

Today added a simple zener to comparator 1, for a fixed output voltage, on top of the current sense, to create a hysteretic controller.

There was a slight overshoot on power on, I do not like overshoots in power supplies, so went back to finish the soft-start routines. So, with the soft-start, there is no overshoot, not even without a load.

Some applications may want the soft start as feature, so I made the softstart-speed programmable via RS232, and saved in EEPROM. It can be set from a few milliseconds to 20 seconds now! Added the new feature to the RS232 menu.

Did short circuit tests, did you know those cheap Chinese multimeters have a high internal resistance at the 10 A range? anyways, short circuit test is OK. Also the regulation is OK, I had to add a RC filter before the zener diode as the thin wires I am using cause large drops (cause spikes), this thing will work much better once mounted on a PCB with short tracks, already it can deliver a punch, good connections will up the power even more. I moved the current transformer from the MOSFET source to the drain, as the little extra inductance it then adds in that circuit contributes to the extra needed as described here:

formatting link

That is it for today, next I will have to sort out some pin changes to accommodate using comparator 2 for variable voltage control, and perhaps try the PWM DAC trick I described in a previous post.

Hammy, hysteretic is indeed cool, no other stabilisation RC networks needed. I looked up the NCP40363 too, and the MC34063A.pdf, the soft start I have now, makes the PIC solution a bit better I think, the MCP3063 has a slight overshoot at startup, see page 7 of the datasheet.

The question remains, how will FLASH and EEPROM stay error free over time? One can make a checksum, and test against that at power up, or if the memory is big enough keep 2 copies of the code and compare at startup. You know how they dig up dinosaurs and old pots and pans and stuff, maybe thousands of years from now, when they dig up stuff from our civilisation, they will not be able to even try any of the zillion gadgets, as all FLASH will be dead :-)

Reply to
Jan Panteltje

I usually do a CRC of the flash on startup. The process is a little cumbersome (hex -> binary, pad the binary to the designated CRC location with "blank" 0xFF bytes, calculate the CRC and stick it onto the end of the binary, convert it all back binary -> hex for the burner) but it's part of the Makefile so the cumbersome-ness is transparent.

A table-driven CRC inside the executable has been a good compromise between speed and space. It has caught errors a few times, mostly during development when the power supply knob got knocked down a notch and made the flash unhappy.

be dead :-)

Indeed!

--
Rich Webb     Norfolk, VA
Reply to
Rich Webb

My favorite 18 pinner is the 16F88.

Reply to
Anthony Fremont

Yes it is,you cant beat it for simplicity.The only downsides to it are the funky output ripple but AND8284-D shows how you can use feedfoward to reduce it.

formatting link

The other thing is the darlington output makes it somewhat slow compared to other controllers and higher quiescent current. But if they tweaked it to much they would have to jack the price up so for 50 cents it's definetly better then using a 7800 series.Particularily if you have a large input to output difference.

overshoot

Yes it doesnt have a soft start function.

be dead :-)

Reply to
Hammy

On a sunny day (Fri, 06 Feb 2009 18:40:08 -0500) it happened Hammy wrote in :

I just did read that, very interesting.. One thing I see in the PIC PWM, is that in case of hysteretic converters, and especially in cycle by cycle current limit, the resolution of the PWM generator is not actually limited by the 8 bits or 6 bits of the timer register reload, but is only limited by the hardware response speed in the PIC. So once can say the PWM resolution is infinite. This feature would then allow to select a much higher output frequency then one would expect. I mean instead of selecting a 8 bit PWM timer at 19 kHz, one can select a 6 bit PWM timer at 38 kHz. I tried the 6 bit PWM at 19 kHz, and as expected it has no negative influence, as the pulse is stopped in hardware when the setpoint is reached. So I will try 78 kHz, and see if it has any advantages with this transformer and MOSFET, at least it should create less ripple for the same values of the output Capacitor.

The inductance of those mains-filters units that I use as transformer is something like 300 uH per winding it seems, and they are cheap too, less then 5 Euro, and can handle a lot of watts.

Absolutely, at high currents 780X is a heater element :-)

Reply to
Jan Panteltje

Universal PIC switchmode status report

Today added comparator 2, it compares the output voltage to a 256 steps PWM DAC made on an other output pin, the setpoint. Of course you can hang that on the +5V too, as reference, or any other lower voltage ,and use 2 resistors to divide the output. But this allows very precise control via RS232. I need to improve that PWM DAC (it has a RC lowpass on its output) in software. Maybe put it in the timer 3 interrupt? Or in the clock tick. It is in main now, and sensitive to interrupts.

Added voltage measurement (for feedback via RS232, and LCD display).

Last night changed pin configuration completely, the LCD driver will have to be written, _all_ pins have changed, so I could do the above trick.

And finally, just upped the frequency from 19.6 kHz to 77.92 kHz. Not even the output voltage changed :-)

Will need to re-test everything with the higher frequency. So flexible it is!

And the rest.. is software... Switched of the soldering iron for now.

This thing is simple, it is cheap, and it rocks.

For now, if you want source, to experiment, ask me. When the soft is finished it will go on my site.

I will have to draw a new diagram.

Reply to
Jan Panteltje

Universal PIC switchmode status report

Today worked on the RS232 control of the output voltage.

The first test used PWM from an output pin, to drive a RC lowpass, to make the reference for comparator 2, the hysteretic output voltage comparator.

Doing a DAC this way in software (only one independent PWM hardware channel available, and that is in use to drive the power MOSFET) is sensitive to anything else happening on the system, like interrupts, or menu printing, that takes cycles away, and causes fluctuation in Vref generated that way. So, last night I tried thinking of a better solution. Fell asleep in the faith that so far I solved all other problems. And indeed, in deep meditation this morning, the answer was there: Use an output pin, tristate it when setpoint reached, and set it high when level too low, and set it low when level to high, and feed it into that same lowpass that now filters the PWM frequency. PIC allows you (via the TRIS registers) to on the fly configure a pin as input, so to a high impedance tri state...

Took me a while to get it working, but it works! No more instability when setting the voltage via RS232! In fact this method works much better, as it auto-servos the output to the requested voltage.

Think of it this way: Suppose you have a lab power supply. It is displaying 6 volt, but you want 10 volt. So what do you do? You grab that voltage control, and start turning it up, until you see 12 volt on the display. Now what if you get interrupted? Suppose somebody throws you a ball? Now *if you hold on* to that voltage control, and try to catch the ball with the other hand, you will likely cause some unwanted movement of that voltage control, possibly an overshoot that kills your object under test, and also may not be able to catch that ball, and lose something expensive when it hits elsewhere.

So the solution is: *Let go of the voltage control*. In electronics for this we have 'sample and hold', or a capacitor,. Put the output pin in tri-state, let a capacitor hold the voltage, and do something else for a while. Programmed that ways it works perfectly.

Setting the voltage via RS232 (and yes, you can see the voltage via RS232 too, but you could be at the other end of the world with a bad connection), now works just like turning that voltage control, the output moves slowly to the requested setpoint. And other advantage is the soft start, the output moves slowly to the requested voltage. This is not the same as the output control loop, this is just about setting it manually. The output voltage control is a hysteretic instantaneous control.

In routines that take a long time, I simply tri-state the output pin, and the reference voltage will not change.

Of course one needs the right value for R and C in the lowpas filter. Too small a R will create overshoot, and too big will make setting a voltage slow.

Some code example, RC low pass on output pin, C is reference voltage for hysteretic comparator, 'output_voltage_setpoint is the REQUESTED value via RS232, not the real setpoint.

; do the DAC thing banksel 0 ; read output voltage using ADC movlw OUTPUT_VOLTAGE movwf analog_select call_1 read_adc clrf PCLATH ; result in ad_h and ad_l, only use ad_l (255 steps is 25.5 V, the highest voltage we support here) banksel 0 ; if output voltage = output_voltage_setpoint, tristate DAC_BIT (hold cap) movfw output_voltage_setpoint subwf ad_l, w btfss STATUS, Z goto test_voltage_bigger ; equal banksel TRISA bsf DAC_TRIS, DAC_BIT ; tristate DAC_PIN goto dac_end test_voltage_bigger: ; if output_voltage > output_voltage_setpoint, reset DAC_BIT to zero (discharge cap) movfw output_voltage_setpoint subwf ad_l, w btfss STATUS, C goto voltage_smaller ; must be smaller ; bigger banksel TRISA bcf DAC_TRIS, DAC_BIT banksel 0 bcf DAC_PORT, DAC_BIT ; DAC_PIN to 0 goto dac_end ; must be smaller ; if output_voltage < output_voltage_setpoint, set DAC_BIT to one (charge cap) voltage_smaller: banksel TRISA bcf DAC_TRIS, DAC_BIT banksel 0 bsf DAC_PORT, DAC_BIT ; DAC_PIN to 1 dac_end: banksel 0

Copyright Jan Panteltje 2009-alway.

Environmental statement: No silicon creatures were killed or hurt in developing this design. One filament light bulb was flashed away as a tribute to outlawing Edison bulbs. end of environmental statement.

disclaimer: You are responsible yourself for having read this.

LOL

Reply to
Jan Panteltje

Universal PIC switchmode status report

Actually here is a picture of that soft / hardware new DAC working: ftp://panteltje.com/pub/power_pic/new_DAC_drive_interrupted_img_0900.jpg

It is measured at the output pin. The middle horizontal line is the value the output takes when the loop is in balance. You will see that when the software gets interrupted by other tasks, the area where there is no activity, the output remain at the set value. This is impossible with a normal software generated PWM, as that is always on or off when interrupted. Even when you were to tristate that, interrupting it it would confuse its timing, resulting in the output changing. The horizontal line is so clear at that output because when the pin is tristate the filter cap sets the voltage.

Reply to
Jan Panteltje

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.