Closed loop speed controller


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default A couple of questions...

    Thanks for the fast reply Darrel!

    1. The PID code is for a servo right? I see that it has direction control and I'm guessing when the setpoint and the ADC value match, it's going to stop the motor and fight to keep it in that position?

    2. what do I change in the code to make this thing run as a speed control?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    That's what the example does, but the PID routine itself can be used for MANY different things.

    In Henrik's example, it's controlling "Position". But if the numbers presented to the PID are representative of the Speed, then it will adjust the output until the Speed is matched.

    It doesn't really matter what it is, temperature, humidity, speed, acceleration ...

    If you can read it, then you can make a "Setpoint" within that range.
    The PID loop adjusts the output until the "Reading" and the "Setpoint" are the same.

    It does it in a way that is as fast as possible while minimizing overshoot and rejecting spurious influences as much as it can.

    All you need to do, is find a way to read the speed of the motor, and a way to control the speed of the motor, which I think you already have.
    <br>
    DT

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Just as Darrel says it can be used to control "anything". Basicly you feed it the Error and it returns the amount of Drive it thinks is neccesary to reduce the Error to zero based on the P- I- & D-gains and a couple of other paramters. It doesn't know, or care, if it's position, speed or whatever.

    Code:
    pidError = Setpoint - CurrentSpeed	'Calculate error
    Gosub PID				'Call PID. Result returned in pid_Out
    There are a couple of things you need to concider. Since you're driving the motor in one quadrant only. There may be occations when the output of the PID routine is "negative" ie. it want's to actually reverse the motor. Obviously you can't do that with only one transistor so you need to clamp the output from the PID routine to positive drive only, perhaps something like this:
    Code:
    pid_Error = Setpoint - CurrentSpeed   	'Calculate error
    Gosub PID                           	'Result returned in pid_Out                           
     If pid_out.15 then                 	'If "negative drive" is called for...
       pid_out = 0                       	'..set output to 0...
       pid_Ei = 0                        	'And keep the I-term from accumulating..
      
     Else                               	'and if positve drive is called for....
    
       pid_Out = ABS pid_Out             	'...set it to absoulte value of pid_Out
     Endif
    Since you want to controll the speed from zero all the way up I think you should concider more than a single a pulse per rev. Otherwise it can get really hard to get good control in the lower speedrange.

    Another thing that is important in digital PID control is constant sampling rate. Ideally you set up a timer interrupt to run at whatever rate you need. What rate to run at depends on the timeconstant of the load and you may need to experiment with a bit but for a basic motorcontrol I'd say somewhere between 100-1000Hz.

    /Henrik Olsson.
    Last edited by HenrikOlsson; - 26th January 2008 at 07:59.

  4. #4
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Thanks

    yeah, that was one thing i was worried about, when my speed goes below the clamp setting.. and it doesnt have to go to complete zero, I can handle that in other ways. my final output shaft is 173RPM, I might add more magnets to the main motor shaft, before the gear reduction just to be safe, i'll have to see what i can get away with. I'm not quite sure i know what your saying about sampling rate? I was going to use timer1 as a counter to get the tach of the motor, which people typically want as RPMs for a display and would count for a second, but are you saying i should count for less then a second? or as much as possible? and also, im sure the number i get for the speed isnt going to be 1:1 with my ADC (the speed setpoint), should i be adjusting something to scale those, or? I don't have everything on hand i need at the moment for a bench test and experiment, I'll have to order a few more things (fets, a rectifier and cap for the motor). i'd like to have a handle on code things before hand tho! thanks again.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default

    Hi,
    About the sampling rate. The motor and whatever is attached to it has a certain mechanical time constant. If you apply a voltage to it it it takes a certain amount of time for it to "respond". If you sample a lot slower than this time constant you won't be able to get good control.

    I'll take a shot at an example:
    If we are controlling the temperature in our swimming pool (which probably have a very large time constant) perhaps we should read the actual temperature and calculate a new "drive-value" for the heater once every hour or even slower than that. But if we're controlling the position of the mirror in a laser-scanner we may need to read the actual position and calculate a new "drive-value" tens of thousands of times per second.

    Whatever the rate is (once a day or once every uS) it needs to be constant because the final output is based on the error itself (P) the magnitude and amount of time the error has been present (I) and the rate of change of the error (D).

    It all depends on how "stiff" you want the control-loop to be. You may get away with a sampling rate of 1s if you can live with very a slow response. If you need to "instantly" respond to the change in load you need to sample much much faster than that.

    There was a really good article available on the web called PID without a PhD explaining this a lot better than I can but I can't seem to find it. If you look around a bit you may be able to find it.

    EDIT: Here it is.

    HTH
    /Henrik Olsson
    Last edited by HenrikOlsson; - 26th January 2008 at 10:24. Reason: Found the article.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink the octogonal wheel ???

    Hi, Enrik

    You should browse the Parallax site : in their applications ... there's all your link shows ... but for PICs AND PbP ( or compatible) written.

    http://www.parallax.com/Portals/0/Do...eb-PC-v1.0.pdf

    see also here : http://www.emesystems.com/BS2math5.htm#Smoothing

    " Hope it can help " ... as we use to say !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 17:48
  2. Serin to Serin2 ??
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 04:56
  3. Replies: 14
    Last Post: - 26th September 2007, 06:41
  4. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 18:42
  5. calculating speed of a loop
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th June 2005, 21:34

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts