Simple SMPS using 8 pin PIC microcontroller. - Page 3 - diyAudio
Go Back   Home > Forums > Amplifiers > Power Supplies

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
Reply
 
Thread Tools Search this Thread
Old 15th November 2010, 01:19 AM   #21
diyAudio Member
 
nigelwright7557's Avatar
 
Join Date: Apr 2008
Location: Carlisle, England
Quote:
Originally Posted by Sch3mat1c View Post
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.
  Reply With Quote
Old 15th November 2010, 01:36 AM   #22
tomchr is offline tomchr  United States
diyAudio Member
 
tomchr's Avatar
 
Join Date: Feb 2009
Location: Greater Seattle Area
Quote:
Originally Posted by nigelwright7557 View Post
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 View Post
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
  Reply With Quote
Old 15th November 2010, 01:46 AM   #23
diyAudio Member
 
nigelwright7557's Avatar
 
Join Date: Apr 2008
Location: Carlisle, England
Quote:
Originally Posted by tomchr View Post
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.
  Reply With Quote
Old 15th November 2010, 05:37 AM   #24
luka is offline luka  Slovenia
diyAudio Member
 
luka's Avatar
 
Join Date: Sep 2005
Location: in Slovenia :)
Send a message via Skype™ to luka
Quote:
Originally Posted by nigelwright7557 View Post
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
__________________
home page @ http://www.classdaudio.tk/ @ 24/7 all year long
I FEEL SLOVENIA
  Reply With Quote
Old 15th November 2010, 09:28 PM   #25
diyAudio Member
 
nigelwright7557's Avatar
 
Join Date: Apr 2008
Location: Carlisle, England
A picture.
Click the image to open in full size.
  Reply With Quote
Old 15th November 2010, 09:55 PM   #26
tomchr is offline tomchr  United States
diyAudio Member
 
tomchr's Avatar
 
Join Date: Feb 2009
Location: Greater Seattle Area
Quote:
Originally Posted by nigelwright7557 View Post
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
  Reply With Quote
Old 15th November 2010, 11:07 PM   #27
diyAudio Member
 
Sch3mat1c's Avatar
 
Join Date: Jan 2003
Location: Milwaukee, WI
Send a message via ICQ to Sch3mat1c Send a message via AIM to Sch3mat1c
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
Projects and Resources
  Reply With Quote
Old 17th November 2010, 01:08 AM   #28
diyAudio Member
 
nigelwright7557's Avatar
 
Join Date: Apr 2008
Location: Carlisle, England
Quote:
Originally Posted by tomchr View Post
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.
Altering the load made no difference to the voltage tracking.
  Reply With Quote
Old 17th November 2010, 04:58 AM   #29
luka is offline luka  Slovenia
diyAudio Member
 
luka's Avatar
 
Join Date: Sep 2005
Location: in Slovenia :)
Send a message via Skype™ to luka
cool!
__________________
home page @ http://www.classdaudio.tk/ @ 24/7 all year long
I FEEL SLOVENIA
  Reply With Quote
Old 17th November 2010, 11:25 AM   #30
Banned
 
Join Date: Jan 2008
Blog Entries: 2
Post the modified code please.

w
  Reply With Quote

Reply


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling a relay with a PIC microcontroller rtarbell Parts 9 12th October 2006 10:29 PM
PIC Microcontroller starter kit?? Zero Cool Everything Else 15 25th July 2006 02:24 PM
wiring config..of 4 pin multi (pic) jonz Everything Else 0 1st October 2004 11:55 PM


New To Site? Need Help?

All times are GMT. The time now is 02:07 PM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio

Content Relevant URLs by vBSEO 3.3.2