Closed loop speed controller


Results 1 to 9 of 9

Threaded View

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


    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 06:59.

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 16:48
  2. Serin to Serin2 ??
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 03:56
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  5. calculating speed of a loop
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th June 2005, 20: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