DC MOTOR CONTROL WITH PC

N

Thread Starter

nikos nannos

I've developed an ISA card with INTEL 8255 chip and A/D & D/A converters. In order to control the DC motor I use Visual Basic but I've a problem in how to write the code of the PID controller. Can anyone help me by sending me some simple code that have been tested? (I use IN and OUT commands to send and receive from the motor)
THANKS.
 
> I've developed an ISA card with INTEL 8255 chip and A/D & D/A converters. In order to control the DC motor I use Visual Basic but I've a problem in how to write the code of the PID controller. Can anyone help me by sending me some simple code that have been tested? (I use IN and OUT commands to send and receive from the motor)
> THANKS.


As you've probably found by now, PID can get complicated quickly. You will probably find that the loop update time gets longer than the motor response time. That will make the motor seem out of control. You can try the following:

Proportional: Read the motor speed and compare it to the setpoint. Generate the sign of the needed correction as well. Multiply by the gain ( if used ). Store in a register. Send out the new motor speed command. Loop around and repeat.

If the motor is responding well to sudden load swings, you can add an Integral component by looking at the difference between the actual speed and the setpoint after 3 or 4 update cycles of the proportional number. Use this difference to add or subtract from the register in the proportional loop.

By the same token, use the difference between actual and setpoint speeds in successive update cycles to further modify the register contents when a sudden change is noted.
 
J

Johan Bengtsson P&L Automatik AB

Add some time measuring, the loop time if you run
in a windows environment and do not explicitly control it could vary quite much. The simplest way to make some kind of repeatable loop time is to attach it to a timer (If I remember it correctly there is quite easy support for that in VB)

PI code would be something like this in it's simplest form:

Pout=(SP-PV)*Kc
if Pout>0 and output<1 then Iout=Iout+Pout*Dt/Ti
if Pout<0 and output>0 then Iout=Iout+Pout*Dt/Ti
output=Pout+Iout

Kc is the proportional gain
Ti is the integration time
Dt is the timestep (time since last update)
SP is the setpoint (ie the wanted speed)
PV is the process value (ie the actual speed)
Pout is the output of the proportional part of the controller
Iout is the output of the integrating part of the controller
output is the output from the controller

All variables are supposed to be floating point and vary between 0 and 1, if you want something else you have to adjust accordingly. Times are to be measured in the same unit whatever you want that to be.

The value of Iout and output have to be stored between updates.

I am not entirely sure the syntax is correct for VB (it was some time ago) but I am sure you can fix that yourself the if statement are not the most efficient way to code that part but they show the prociple. They are necesary for not
making the integrating part go away when the setpoint can not be reached for long periods, this is called antiwindup.
The idea is that if the output is at one of its limits the I part should never try to go in that direction any further.

Please note: output will go slighly outside the range 0 to 1, that might have to be considered.

D is somewhat more complicated but you will probably not need that anyway....


/Johan Bengtsson

----------------------------------------
P&L, the Academy of Automation
Box 252, S-281 23 H{ssleholm SWEDEN
Tel: +46 451 49 460, Fax: +46 451 89 833
E-mail: [email protected]
Internet: http://www.pol.se/
----------------------------------------
 
As you've probably found by now, PID can get complicated quickly. You will probably find that the loop update time gets longer than the motor response time. That will make the motor seem out of control. You can try the following:

Proportional: Read the motor speed and compare it to the setpoint. Generate the sign of the needed correction as well. Multiply by the gain ( if used ). Store in a register. Send out the new motor speed command. Loop around and repeat.

If the motor is responding well to sudden load swings, you can add an Integral component by looking at the difference between the actual speed and the setpoint after 3 or 4 update cycles of the proportional number. Use this difference to add or subtract from the register in the proportional loop.

By the same token, use the difference between actual and setpoint speeds in successive update cycles to further modify the register contents when a sudden change is noted.
 
Top