Simple SMPS using 8 pin PIC microcontroller.
 User Name Stay logged in? Password
 Home Forums Rules Articles diyAudio Store Blogs Gallery Wiki Register Donations FAQ Calendar Search Today's Posts Mark Forums Read Search

 Please consider donating to help us continue to serve you. Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
nigelwright7557
diyAudio Member

Join Date: Apr 2008
Location: Carlisle, England
Quote:
 Originally Posted by Sch3mat1c What are you writing in, QBasic?! PID is the second simplest control method in all of digital design. Tim
Why PID when something simple will suffice.

I havent tried the A2D version yet.
If the A2D version doesnt work well then its PID or a class D type triangle wave and comparator technique.
__________________

tomchr
diyAudio Member

Join Date: Feb 2009
Location: Calgary
Quote:
 Originally Posted by nigelwright7557 The PIC only outputs a single pulse if the voltage is below 12 volts. This is a tiny amount of charge. The gain is very low but it still reacts very quickly to change. The pulses are very short, 50KHz.
It'll probably work alright at very low output currents. But once you have to replenish the charge drawn by the load on a more frequent basis, the output voltage will drop like a rock.

Quote:
 Originally Posted by nigelwright7557 I had considered a PID technique but this involves so many calculations the PIC would never keep up.
Some 12~13 years ago, I wrote a PID control routine for an 8051 uC. It took less than a screenful (25 lines) of assembly code to do it. You could probably do it in one line in C...

Recall that the derivative of the error signal, E, is merely E(n)-E(n-1), where n is the sample number. The integral, I, is I(n) = I(n-1)+E(n). You'll have to limit the integral value to something reasonable to prevent the register from rolling over.

I'm not suggesting that you implement the full PID control, though, that would probably result in a pretty well-performing system. All I'm saying is to use proportional control. I.e. PWM_value = ADC_value * P. That's one line of code... In assembly, it might be three instructions. Plus whatever is needed to set up the PWM and ADC. If you limit P to powers of two, you can use a shift instruction to perform the multiplication. Recall X*2^n = X << n.

~Tom

nigelwright7557
diyAudio Member

Join Date: Apr 2008
Location: Carlisle, England
Quote:
 Originally Posted by tomchr Some 12~13 years ago, I wrote a PID control routine for an 8051 uC. It took less than a screenful (25 lines) of assembly code to do it. You could probably do it in one line in C... ~Tom
I professionally wrote a PID program about 12 years ago.
It was for a big drill company.

It used 49*ERROR1-70*ERROR2+25*ERROR3 and scaled the result to get the right gain.
I did it in 16 bit arithmetic on a PIC.
It worked very well, the drill speed was rock steady.
It was just a matter of getting the gain right.

A colleague of mine got the formula from a PID seminar and it seemed to work with anything we threw at it with a little tweaking.

Just finished a discrete class d amplifier so into PWM at the moment.
__________________

luka
diyAudio Member

Join Date: Sep 2005
Location: in Slovenia :)
Quote:
 Originally Posted by nigelwright7557 I had considered a PID technique but this involves so many calculations the PIC would never keep up.
I don't know about that, I in my tests I had no problems, I even slowed it down
__________________
I FEEL SLOVENIA

 15th November 2010, 08:28 PM #25 nigelwright7557   diyAudio Member     Join Date: Apr 2008 Location: Carlisle, England A picture. __________________ PCBCAD51 pcb design software. http://www.murtonpikesystems.co.uk
tomchr
diyAudio Member

Join Date: Feb 2009
Location: Calgary
Quote:
 Originally Posted by nigelwright7557 I professionally wrote a PID program about 12 years ago. I did it in 16 bit arithmetic on a PIC. It worked very well, the drill speed was rock steady.
With 16-bit math it takes longer to compute. Mine was 8-bit math and it actually worked quite well for controlling a small plotter.

~Tom

 15th November 2010, 10:07 PM #27 Sch3mat1c   diyAudio Member     Join Date: Jan 2003 Location: Milwaukee, WI Still no big deal -- I don't recall which PICs have multipliers, but I think all AVR do. 8 bit hardware multiply makes even 16 bit multiplications speedy. When your loop bandwidth is a few kHz and the clock is over 1MHz, heck, you could still do it without hardware multiply. Needless to say, you'd be using the analog comparator (an external one if the internal isn't fast / accurate enough) for a current-mode boost / flyback converter, and wrapping the loop around that. Hmm, you need a DAC to do a proper current mode thing. At 1MHz clock, 1kHz bandwidth, you only get 10 bits PWM, and that's assuming a brick wall antialiasing filter. You only get ~7 bits for a factor of 10 frequency margin, and that's still a lot of ripple from a simple RC. Maybe sigma delta modulation would be better? Tim __________________ Seven Transistor Labs, LLC Projects and Resources / Electronic Design and Consultation
nigelwright7557
diyAudio Member

Join Date: Apr 2008
Location: Carlisle, England
Quote:
 Originally Posted by tomchr With 16-bit math it takes longer to compute. Mine was 8-bit math and it actually worked quite well for controlling a small plotter. ~Tom
The PIC seems to work ok with a simple pulse out to the SMPS if the voltage is too low.

However I decided to go the whole hog and do a PID version.
I just put in a read of the A2D to get an error number and put that into a PID I already had. It oscilated to start with because the gain was too high.
A slight reduction in gain saw a steady output voltage.
__________________

 17th November 2010, 03:58 AM #29 luka   diyAudio Member     Join Date: Sep 2005 Location: in Slovenia :) cool! __________________ home page @ http://www.classdaudio.tk/ @ 24/7 all year long I FEEL SLOVENIA
 17th November 2010, 10:25 AM #30 wakibaki   Banned   Join Date: Jan 2008 Post the modified code please. w

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Site     Site Announcements     Forum Problems Amplifiers     Solid State     Pass Labs     Tubes / Valves     Chip Amps     Class D     Power Supplies     Headphone Systems Source & Line     Analogue Source     Analog Line Level     Digital Source     Digital Line Level     PC Based Loudspeakers     Multi-Way     Full Range     Subwoofers     Planars & Exotics Live Sound     PA Systems     Instruments and Amps Design & Build     Parts     Equipment & Tools     Construction Tips     Software Tools General Interest     Car Audio     diyAudio.com Articles     Music     Everything Else Member Areas     Introductions     The Lounge     Clubs & Events     In Memoriam The Moving Image Commercial Sector     Swap Meet     Group Buys     The diyAudio Store     Vendor Forums         Vendor's Bazaar         Sonic Craft         Apex Jr         Audio Sector         Acoustic Fun         Chipamp         DIY HiFi Supply         Elekit         Elektor         Mains Cables R Us         Parts Connexion         Planet 10 hifi         Quanghao Audio Design         Siliconray Online Electronics Store         Tubelab     Manufacturers         AKSA         Audio Poutine         Musicaltech         Aussie Amplifiers         CSS         exaDevices         Feastrex         GedLee         Head 'n' HiFi - Walter         Heatsink USA         miniDSP         SITO Audio         Twin Audio         Twisted Pear         Wild Burro Audio

 Similar Threads Thread Thread Starter Forum Replies Last Post rtarbell Parts 9 12th October 2006 09:29 PM Zero Cool Everything Else 15 25th July 2006 01:24 PM jonz Everything Else 0 1st October 2004 10:55 PM

 New To Site? Need Help?

All times are GMT. The time now is 08:11 AM.