Exemplo n.º 1
0
void  DTC_SVM(void)
{

static bool shutdown=true;
static bool increase_flux  = false;

if (center_aligned_state==FIRST_HALF)
{

  i_sD     = direct_stator_current_i_sD     (i_sA);
  i_sQ     = quadrature_stator_current_i_sQ (i_sA,i_sB);

  static float psi_sD_i_neglected=0.0f;
  static float psi_sQ_i_neglected=0.0f;

  flux_linkage_estimator(2.0f*TICK_PERIOD,V_sD,V_sQ,i_sD,i_sQ,R_s,CUR_FREQ,&psi_sD,&psi_sQ,&psi_s,&psi_s_alpha_SVM);
  flux_linkage_estimator_neglected_currents (2.0f*TICK_PERIOD,V_sD,V_sQ,&psi_sD_i_neglected,&psi_sQ_i_neglected);
                                                  
  //actual value
  //it has to be multiplied by two in order because the switching frequency
  //is half the pwm frequency due to the two-cycle center-aligned signal
  //w_r = 0.15915494309189533576f*rotor_speed_w_r (psi_sD,psi_sQ,TICK_PERIOD*2.0f); 
  
  //using neglected-currents flux-linkage estimator
  w_r = 0.15915494309189533576f*rotor_speed_w_r (psi_sD_i_neglected,psi_sQ_i_neglected,TICK_PERIOD*2.0f);  
  w_r = wr_moving_average_filter(w_r); 
  hall_freq=frequency_direction_two_hall_sensors_AB(CUR_FREQ);
  if (w_r!=w_r) w_r=0.0f;

  //t_e       = electromagnetic_torque_estimation_t_e   (psi_sD,i_sQ,psi_sQ,i_sD,pole_pairs);
  t_e       = electromagnetic_torque_estimation_t_e   (psi_sD_i_neglected,i_sQ,psi_sQ_i_neglected,i_sD,pole_pairs);
  //t_e =  te_moving_average_filter(t_e);

  psi_s_ref=psi_F;
  
  //--------------------------------SVM algorithm--------------------------------------------//


} 


else
{

/*
  ref_freq_SVM = admittance_controller    (
                                            stiffness,
                                            damping,
                                            reference_electric_angle,
                                            electric_angle,
                                            strain_gauge
                                            );
*/
  
  /**************************************************************/
  /*********Admitance Controller*********************************/
  /**************************************************************/
  /*ref_freq_SVM = admittance_controller    (
                                            stiffness,
                                            damping,
                                            reference_electric_angle,
                                            electric_angle,
                                            strain_gauge
                                            );
  */


  electric_angle= electric_angle+
                            /*DTC-SVM PID controller*/                            

                            /*SVM with PID controller on the frequency calculated with the hall sensor*/
                            //SVM_speed_close_loop_of_voltage_frequency(ref_freq_SVM,hall_freq,true,&V_sD,&V_sQ,U_d,shutdown); 
  
                            /*SVM with lineal increase of electric frequency [based on frecuency calculated with the flux-linkage estimator]*/ 
                            SVM_speed_close_loop_of_voltage_frequency_old(ref_freq_SVM,w_r      ,true,&V_sD,&V_sQ,U_d,shutdown);

#define MAX_GEAR_CYCLES 100.0f

  if (reference_electric_angle>=360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES)
    reference_electric_angle=reference_electric_angle-360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES;
  if (electric_angle<-  360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES)
    reference_electric_angle=reference_electric_angle+360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES;              

  if (electric_angle>=360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES)
    electric_angle=electric_angle-360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES;
  if (electric_angle<-360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES)
    electric_angle=electric_angle+360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES;



  fast_vector_angle_and_magnitude(V_sQ,V_sD,&V_s,&cita_V_s);

  required_V_sD     =   V_sD;
  required_V_sQ     =   V_sQ;
  required_V_s      =   V_s;
  required_cita_V_s =   cita_V_s;


  SVM_Maximum_allowed_V_s_ref (&V_sD,&V_sQ,&V_s,U_d*UD_PERCENTAGE,&increase_flux);//0.70f);
  V_s_ref_relative_angle = SVM_V_s_relative_angle      (cita_V_s);


  float V_s_duty_cycle=0.0f;
  float U_max=0.0f;
  V_s_duty_cycle=V_s/(0.66666666666666666666f*U_d); //V_s_duty_cycle=V_s/( (2.0f/3.0f) *U_d);
  U_max=U_d*0.66666666666666666666f;

  T1       = SVM_T1       (V_s_duty_cycle,V_s,U_max, V_s_ref_relative_angle);
  T2       = SVM_T2       (V_s_duty_cycle,V_s,U_max, V_s_ref_relative_angle);
  

  T_min_on =SVM_T_min_on (1.0f, T1, T2); //T_min_on = SVM_T_min_on (1.0f, T1, T2);
  T_med_on =SVM_T_med_on (T_min_on, T1,T2,cita_V_s);
  T_max_on =SVM_T_max_on (T_med_on,T1,T2,cita_V_s);

  SVM_phase_duty_cycles           (&duty_a, &duty_b, &duty_c, cita_V_s,T_max_on,T_med_on,T_min_on);
  
  //duty_a=0.5f;
  //duty_b=0.0f;
  //duty_c=0.0f;

  

  shutdown_counter(ref_freq_SVM,&shutdown);
  SVM_voltage_switch_inverter_VSI ( duty_a,  duty_b,  duty_c,shutdown);
}


if (center_aligned_state==FIRST_HALF)
{
  center_aligned_state=SECOND_HALF;
}
else 
{
  center_aligned_state=FIRST_HALF;
}

}
Exemplo n.º 2
0
void  DTC_SVM(void)
{
static bool shutdown=true;
  static bool open_loop_SVM  = false;
  //static bool close_loop_SVM = false;
  static bool increase_flux  = false;

if (center_aligned_state==FIRST_HALF)
{


  
  i_sD     = direct_stator_current_i_sD     (i_sA);
  i_sQ     = quadrature_stator_current_i_sQ (i_sA,i_sB);
  //fast_vector_angle_and_magnitude(i_sQ,i_sD,&i_s,&cita_i_s);

 
/*
  //nan erradication
  if (psi_sD!=psi_sD) psi_sD=0.0f;
  if (psi_sQ!=psi_sQ) psi_sQ=0.0f;
  if (psi_s !=psi_s ) psi_s =0.0f;
  if (t_e!=t_e      ) t_e    =0.0f;
  if (psi_s_alpha_SVM!=psi_s_alpha_SVM) psi_s_alpha_SVM=0.0f;
*/

  static float psi_sD_i_neglected=0.0f;
  static float psi_sQ_i_neglected=0.0f;

  //flux_linkage_estimator(2.0f*TICK_PERIOD,V_sD,V_sQ,i_sD,i_sQ,R_s,CUR_FREQ,&psi_sD,&psi_sQ,&psi_s,&psi_s_alpha_SVM);
  //flux_linkage_estimator_neglected_currents (2.0f*TICK_PERIOD,V_sD,V_sQ,&psi_sD_i_neglected,&psi_sQ_i_neglected);

//psi_sD_i_neglected=direct_stator_flux_linkage_estimator_psi_sD     (2.0f*TICK_PERIOD,V_sD,i_sD,R_s,w_r);
//psi_sQ_i_neglected=quadrature_stator_flux_linkage_estimator_psi_sQ (2.0f*TICK_PERIOD,V_sQ,i_sQ,R_s,w_r);

//psi_sD_i_neglected=direct_stator_flux_linkage_estimator_psi_sD     (2.0f*TICK_PERIOD,V_sD,0.0f,R_s,w_r);
//psi_sQ_i_neglected=quadrature_stator_flux_linkage_estimator_psi_sQ (2.0f*TICK_PERIOD,V_sQ,0.0f,R_s,w_r);
  
/*
  //nan erradication
  if (psi_sD!=psi_sD) psi_sD=0.0f;
  if (psi_sQ!=psi_sQ) psi_sQ=0.0f;
  if (psi_s !=psi_s ) psi_s =0.0f;
  if (t_e!=t_e      ) t_e    =0.0f;
  if (psi_s_alpha_SVM!=psi_s_alpha_SVM) psi_s_alpha_SVM=0.0f;
*/


  //w_r             = (1.0f/(2.0f*PI))     *rotor_speed_w_r                                 (psi_sD,psi_sQ,TICK_PERIOD*2.0f);
  //w_r             = 0.15915494309189533576f*rotor_speed_w_r                                 (psi_sD,psi_sQ,TICK_PERIOD*2.0f);  
                                                           //it has to be multiplied by two in order because the switching frequency
                                                           //is half the pwm frequency due to the two-cycle center-aligned signal
  //actual value
 // w_r = 0.15915494309189533576f*rotor_speed_w_r (psi_sD,psi_sQ,TICK_PERIOD*2.0f); 
  
  //using neglected-currents flux-linkage estimator
  //w_r = 0.15915494309189533576f*rotor_speed_w_r (psi_sD_i_neglected,psi_sQ_i_neglected,TICK_PERIOD*2.0f);  
  //w_r = wr_moving_average_filter(w_r); 
  hall_freq=frequency_direction_two_hall_sensors_AB(CUR_FREQ);

  if (w_r!=w_r) w_r=0.0f;

  //t_e       = electromagnetic_torque_estimation_t_e   (psi_sD,i_sQ,psi_sQ,i_sD,pole_pairs);
  t_e       = electromagnetic_torque_estimation_t_e   (psi_sD_i_neglected,i_sQ,psi_sQ_i_neglected,i_sD,pole_pairs);
 

  //t_e =  te_moving_average_filter(t_e);


  //t_e_ref = DTC_torque_reference_PI                 (CUR_FREQ, ref_freq);
  //psi_s_ref = stator_flux_linkage_reference_psi_s_ref (psi_F,t_e_ref,L_sq,pole_pairs);

  if (user_input==true)
    psi_s_ref=psi_ref_user;
  else 
    psi_s_ref=psi_F;
  
  //--------------------------------SVM algorithm--------------------------------------------//

  //SVM_starting_open_loop(open_loop_SVM,&V_sD,&V_sQ,U_d,MAXIMUM_OPEN_LOOP_SPEED,CUR_FREQ,ref_freq_SVM);
  //SVM_starting_open_loop(open_loop_SVM,&V_sD,&V_sQ,U_d,ref_freq_SVM,CUR_FREQ,ref_freq_SVM);
  SVM_starting_open_loop(open_loop_SVM,&V_sD,&V_sQ,U_d,ref_freq_SVM,hall_freq,ref_freq_SVM);
} 


else
{
  //SVM_speed_close_loop(ref_freq_SVM,CUR_FREQ,close_loop_SVM,&V_sD,&V_sQ);
  //SVM_speed_close_loop(ref_freq_SVM,w_r,close_loop_SVM,&V_sD,&V_sQ);
  //SVM_speed_close_loop_of_voltage_frequency(ref_freq_SVM,CUR_FREQ,close_loop_SVM,&V_sD,&V_sQ,U_d,shutdown);   



/*
  ref_freq_SVM = admittance_controller    (
                                            stiffness,
                                            damping,
                                            reference_electric_angle,
                                            electric_angle,
                                            strain_gauge
                                            );
*/
  
  /**************************************************************/
  /*********Admitance Controller*********************************/
  /**************************************************************/
  /*ref_freq_SVM = admittance_controller    (
                                            stiffness,
                                            damping,
                                            reference_electric_angle,
                                            electric_angle,
                                            strain_gauge
                                            );
  */
   //float intermidiate_value;
   //intermidiate_value = wr_moving_average_filter(CUR_FREQ); 
  electric_angle= electric_angle+
                            //SVM_speed_close_loop_of_voltage_frequency(ref_freq_SVM,CUR_FREQ,true,&V_sD,&V_sQ,U_d,shutdown); 
                            //SVM_speed_close_loop_of_voltage_frequency(ref_freq_SVM,hall_freq,true,&V_sD,&V_sQ,U_d,shutdown); 
                            //hall_freq=CUR_FREQ;
							//for resistence test, use SVM_speed_close_loop_of_voltage_frequency function
                          SVM_speed_close_loop_of_voltage_frequency(ref_freq_SVM,w_r,true,&V_sD,&V_sQ,U_d,shutdown); 
                          //SVM_speed_close_loop_of_voltage_frequency(ref_freq_SVM,hall_freq,close_loop_SVM,&V_sD,&V_sQ,U_d,shutdown); 


#define MAX_GEAR_CYCLES 100.0f

  if (reference_electric_angle>=360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES)
    reference_electric_angle=reference_electric_angle-360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES;
  if (electric_angle<-  360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES)
    reference_electric_angle=reference_electric_angle+360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES;              

  if (electric_angle>=360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES)
    electric_angle=electric_angle-360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES;
  if (electric_angle<-360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES)
    electric_angle=electric_angle+360.0f*pole_pairs*gear_ratio*MAX_GEAR_CYCLES;



/*
  if (shutdown==true)
    electric_angle=0.0f;
*/
  //SVM_torque_close_loop(t_e_ref,t_e,close_loop_SVM,&V_sD,&V_sQ);
  //SVM_loop_control(hall_freq,MAXIMUM_OPEN_LOOP_SPEED,t_e_ref,ref_freq_SVM,&open_loop_SVM,&close_loop_SVM); 

  fast_vector_angle_and_magnitude(V_sQ,V_sD,&V_s,&cita_V_s);

  required_V_sD     =   V_sD;
  required_V_sQ     =   V_sQ;
  required_V_s      =   V_s;
  required_cita_V_s =   cita_V_s;

  SVM_Maximum_allowed_V_s_ref (&V_sD,&V_sQ,&V_s,U_d*UD_PERCENTAGE,&increase_flux);//0.70f);
  V_s_ref_relative_angle = SVM_V_s_relative_angle      (cita_V_s);


  //cheating
  //V_sD=required_V_sD;
  //V_sQ=required_V_sQ;

  float V_s_duty_cycle=0.0f;
  float U_max=0.0f;
  V_s_duty_cycle=V_s/(0.66666666666666666666f*U_d); //V_s_duty_cycle=V_s/( (2.0f/3.0f) *U_d);
  U_max=U_d*0.66666666666666666666f;

  T1       = SVM_T1       (V_s_duty_cycle,V_s,U_max, V_s_ref_relative_angle);
  T2       = SVM_T2       (V_s_duty_cycle,V_s,U_max, V_s_ref_relative_angle);
  

  T_min_on =SVM_T_min_on (1.0f, T1, T2); //T_min_on = SVM_T_min_on (1.0f, T1, T2);
  T_med_on =SVM_T_med_on (T_min_on, T1,T2,cita_V_s);
  T_max_on =SVM_T_max_on (T_med_on,T1,T2,cita_V_s);

  SVM_phase_duty_cycles           (&duty_a, &duty_b, &duty_c, cita_V_s,T_max_on,T_med_on,T_min_on);
  

  //shutdown_SVM_speed (ref_freq_SVM,w_r,&shutdown);
  /*shutdown_SVM_position (   ref_freq_SVM,
                            reference_change_electric_angle/(pole_pairs*gear_ratio) ,
                            reference_electric_angle/(pole_pairs*gear_ratio)        ,
                            electric_angle/(pole_pairs*gear_ratio),
                            &shutdown);*/
  //shutdown_admittance_speed (ref_freq_SVM,hall_freq,&shutdown);
  //simple_shutdown(reference_change_electric_angle/(pole_pairs*gear_ratio),&shutdown);
  shutdown_counter(ref_freq_SVM,&shutdown);
  SVM_voltage_switch_inverter_VSI ( duty_a,  duty_b,  duty_c,shutdown);
}


if (center_aligned_state==FIRST_HALF)
{
  center_aligned_state=SECOND_HALF;
}
else 
{
  center_aligned_state=FIRST_HALF;
}

}