mc_control.c File Reference

#include "config.h"
#include "mc_control.h"
#include "mc_drv.h"
#include "mc_interface.h"

Include dependency graph for mc_control.c:

Go to the source code of this file.

Functions

U8 mc_control_current (U8 cur_cmd)
 use to control current , current regulation loop need parameter : Kp_cur, Ki_cur ,Kd_cur and K_cur_scal in config_motor.h need to call in Te ms
U8 mc_control_speed (U8 speed_cmd)
 use to control speed , speed regulation loop need parameter : Kp_speed, Ki_speed ,Kd_speed and K_speed_scal in config_motor.h need to call in Te ms
U8 mc_get_Duty_Cycle ()
 set type of regulation
void mc_regulation_loop ()
 launch speed control or no regulation
void mc_set_Current_Loop ()
 set type of regulation
void mc_set_Open_Loop ()
 set type of regulation
void mc_set_Speed_Loop ()
 set type of regulation

Variables

S16 cur_der = 0
S16 cur_derivative = 0
S16 cur_error = 0
 Error calculation.
S16 cur_integ = 0
S16 cur_integral = 0
S16 cur_proportional = 0
U8 duty_cycle = 0
 Parameter to set PWM Duty Cycle after regulation calculation.
S16 last_cur_error = 0
 Variable for the last error.
S16 last_speed_error = 0
 Variable for the last error.
U8 regulation_type = OPEN_LOOP
 Define the type of regulation (OPEN_LOOP or CLOSE_LOOP).
S16 speed_der = 0
S16 speed_derivative = 0
S16 speed_error = 0
 Error calculation.
S16 speed_integ = 0
S16 speed_integral = 0
S16 speed_proportional = 0


Function Documentation

U8 mc_control_current ( U8  cur_cmd  ) 

use to control current , current regulation loop need parameter : Kp_cur, Ki_cur ,Kd_cur and K_cur_scal in config_motor.h need to call in Te ms

Returns:
value of current, duty cycle on 8 bits

Definition at line 104 of file mc_control.c.

References cur_error, cur_integ, cur_integral, cur_proportional, K_cur_scal, Ki_cur, Kp_cur, and mci_get_measured_current().

Referenced by mc_regulation_loop().

00105 {
00106   U8 Duty = 0;
00107   S32 increment = 0;
00108 
00109   // Error calculation
00110   cur_error = cur_cmd - (mci_get_measured_current());// value -255 <=> 255
00111 
00112   // proportional term calculation
00113   cur_proportional = Kp_cur*cur_error;
00114 
00115   // integral term calculation
00116   cur_integral = cur_integral + cur_error;
00117 
00118   if(cur_integral >  255) cur_integral =  255;
00119   if(cur_integral < -255) cur_integral = -255;
00120 
00121   cur_integ = Ki_cur*cur_integral;
00122 
00123   // derivative term calculation
00124   /*cur_derivative = cur_error - last_cur_error;
00125 
00126   if(cur_derivative >  255) cur_derivative =  255;
00127   if(cur_derivative < -255) cur_derivative = -255;
00128 
00129   cur_der = Kd_cur*cur_derivative;
00130 
00131   last_cur_error = cur_error;*/
00132 
00133   // Duty Cycle calculation
00134   increment = cur_proportional + cur_integ;
00135   //increment += cur_der;
00136   increment = increment >> K_cur_scal;
00137 
00138   // Variable saturation
00139   if(increment >= (S16)(255)) Duty = 255;
00140   else
00141   {
00142     if(increment <= (S16)(0)) Duty =   0;
00143     else Duty = (U8)(increment);
00144   }
00145 
00146   // return Duty Cycle
00147   return Duty;
00148 }

Here is the call graph for this function:

U8 mc_control_speed ( U8  speed_cmd  ) 

use to control speed , speed regulation loop need parameter : Kp_speed, Ki_speed ,Kd_speed and K_speed_scal in config_motor.h need to call in Te ms

Returns:
value of speed, duty cycle on 8 bits

Definition at line 49 of file mc_control.c.

References K_speed_scal, Ki_speed, Kp_speed, mci_get_measured_speed(), speed_error, speed_integ, speed_integral, and speed_proportional.

Referenced by mc_regulation_loop().

00050 {
00051   U8 Duty = 0;
00052   S32 increment = 0;
00053 
00054   // Error calculation
00055   speed_error = speed_cmd - mci_get_measured_speed();// value -255 <=> 255
00056 
00057   // proportional term calculation
00058   speed_proportional = Kp_speed*speed_error;
00059 
00060   // integral term calculation
00061   speed_integral = speed_integral + speed_error;
00062 
00063   if(speed_integral >  255) speed_integral =  255;
00064   if(speed_integral < -255) speed_integral = -255;
00065 
00066   speed_integ = Ki_speed*speed_integral;
00067 
00068   // derivative term calculation
00069   /*speed_derivative = speed_error - last_speed_error;
00070 
00071   if(speed_derivative >  255) speed_derivative =  255;
00072   if(speed_derivative < -255) speed_derivative = -255;
00073 
00074   speed_der = Kd_speed*speed_derivative;
00075 
00076   last_speed_error = speed_error;*/
00077 
00078   // Duty Cycle calculation
00079   increment = speed_proportional + speed_integ;
00080   //increment += speed_der;
00081   increment = increment >> K_speed_scal;
00082 
00083   // Variable saturation
00084   if(increment >= (S16)(255)) Duty = 255;
00085   else
00086   {
00087     if(increment <= (S16)(0)) Duty =   0;
00088     else Duty = (U8)(increment);
00089   }
00090 
00091   // return Duty Cycle
00092   return Duty;
00093 }

Here is the call graph for this function:

U8 mc_get_Duty_Cycle (  ) 

set type of regulation

Precondition:
none
Postcondition:
Close loop regulation Set

Definition at line 204 of file mc_control.c.

References duty_cycle.

Referenced by mci_retry_run(), and mci_run().

00205 {
00206   return duty_cycle;
00207 }

void mc_regulation_loop (  ) 

launch speed control or no regulation

Precondition:
none
Postcondition:
new duty cycle on PWM

Definition at line 160 of file mc_control.c.

References Clear_EXT3, CURRENT_LOOP, duty_cycle, mc_control_current(), mc_control_speed(), mc_get_motor_speed(), mc_get_potentiometer_value(), OPEN_LOOP, regulation_type, Set_EXT3, and SPEED_LOOP.

Referenced by mci_retry_run(), and mci_run().

00161 {
00162   // measure
00163   Set_EXT3();
00164 
00165   switch(regulation_type)
00166   {
00167     case OPEN_LOOP     : duty_cycle = mc_get_motor_speed();break;
00168     case SPEED_LOOP    : duty_cycle = mc_control_speed(mc_get_motor_speed());break;
00169     case CURRENT_LOOP  : duty_cycle = mc_control_current(mc_get_potentiometer_value());break;
00170     default : break;
00171   }
00172 
00173   // measure
00174   Clear_EXT3();
00175 }

Here is the call graph for this function:

void mc_set_Current_Loop (  ) 

set type of regulation

Precondition:
none
Postcondition:
Position loop regulation Set

Definition at line 196 of file mc_control.c.

References CURRENT_LOOP, and regulation_type.

void mc_set_Open_Loop (  ) 

set type of regulation

Precondition:
none
Postcondition:
Open loop regulation Set

Definition at line 182 of file mc_control.c.

References OPEN_LOOP, and regulation_type.

void mc_set_Speed_Loop (  ) 

set type of regulation

Precondition:
none
Postcondition:
Speed loop regulation Set

Definition at line 189 of file mc_control.c.

References regulation_type, and SPEED_LOOP.


Variable Documentation

S16 cur_der = 0

Definition at line 37 of file mc_control.c.

Definition at line 36 of file mc_control.c.

Error calculation.

Definition at line 31 of file mc_control.c.

Referenced by mc_control_current().

Definition at line 34 of file mc_control.c.

Referenced by mc_control_current().

Definition at line 33 of file mc_control.c.

Referenced by mc_control_current().

Definition at line 35 of file mc_control.c.

Referenced by mc_control_current().

Parameter to set PWM Duty Cycle after regulation calculation.

Definition at line 18 of file mc_control.c.

Referenced by mc_get_Duty_Cycle(), and mc_regulation_loop().

Variable for the last error.

Definition at line 32 of file mc_control.c.

Variable for the last error.

Definition at line 23 of file mc_control.c.

U8 regulation_type = OPEN_LOOP

Define the type of regulation (OPEN_LOOP or CLOSE_LOOP).

Definition at line 19 of file mc_control.c.

Referenced by mc_regulation_loop(), mc_set_Current_Loop(), mc_set_Open_Loop(), and mc_set_Speed_Loop().

Definition at line 28 of file mc_control.c.

Definition at line 27 of file mc_control.c.

Error calculation.

Definition at line 22 of file mc_control.c.

Referenced by mc_control_speed().

Definition at line 25 of file mc_control.c.

Referenced by mc_control_speed().

Definition at line 24 of file mc_control.c.

Referenced by mc_control_speed().

Definition at line 26 of file mc_control.c.

Referenced by mc_control_speed().


Generated on Wed Oct 22 16:03:25 2008 for AVR496 : Atmel BLDC control on ATAVRMC301 with ATtiny861 by  doxygen 1.5.7.1