Project

General

Profile

Files » fnct.c

Frédéric Blanc, 2016-01-29 09:58

 
/**
* @brief fonction DCDC
* @date 17/10/2011
* @author F.BLANC LAAS-CNRS
*
*/
#include <utility.h>
#include "asynctmr.h"
#include "var.h"
/**
* @brief Set_panel_control
* @return 0
* @date 10/12/2010
*
*/
int Set_panel_control(void)
{
int ctrlarray;
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_FREQ,consigne[0].freq/1000); //en kHz
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGPHAS,consigne[0].phase);
init_phase();
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_INTER,consigne[0].interleaving);

SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vin_START,consigne[0].Vin_START);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vin_STOP,consigne[0].Vin_STOP);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vin_STEP,consigne[0].Vin_STEP);

SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_START,consigne[0].Vout_START);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STOP,consigne[0].Vout_STOP);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STEP,consigne[0].Vout_STEP);

SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_START,consigne[0].Pout_START);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STOP,consigne[0].Pout_STOP);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STEP,consigne[0].Pout_STEP);

SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_delays,consigne[0].delays);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Delay_Cal,consigne[0].Delay_Cal);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_KP,consigne[0].Kp);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_KI,consigne[0].Ki);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_ACC,consigne[0].accuracy);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_VMAX,consigne[0].Vout_MAX);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_IMAX,consigne[0].Iin_MAX);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_PWMMAX,consigne[0].pwm_MAX);
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_NB_CYCLE,consigne[0].nb_cycle);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_V3,Ctrl.m_V3);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_V4,Ctrl.m_V4);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_I3,Ctrl.m_I3);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_I4,Ctrl.m_I4);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_P3,Ctrl.m_P3);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_P4,Ctrl.m_P4);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGMODE,Ctrl.Iout);
switch (Ctrl.Iout)
if(Ctrl.Iout==MODE_IOUT)
{
case MODE_IOUT:
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_START,ATTR_LABEL_TEXT, "Iout Start (A)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STOP,ATTR_LABEL_TEXT, "Iout Stop (A)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STEP,ATTR_LABEL_TEXT, "Iout Step (A)");
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_SET_Pout,ATTR_LABEL_TEXT, "SetIout (A)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_START,ATTR_LABEL_TEXT, "Vout Start (V)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STOP,ATTR_LABEL_TEXT, "Vout Stop (V)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STEP,ATTR_LABEL_TEXT, "Vout Step (V)");
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_SET_Vout,ATTR_LABEL_TEXT, "SetVout (V)");
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_KPID);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 0);
init_phase();
save_LOG("Control ouput Iout");
break;
case MODE_POUT:
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_START,ATTR_LABEL_TEXT, "Pout Start (W)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STOP,ATTR_LABEL_TEXT, "Pout Stop (W)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STEP,ATTR_LABEL_TEXT, "Pout Step (W)");
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_SET_Pout,ATTR_LABEL_TEXT, "SetPout (W)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_START,ATTR_LABEL_TEXT, "Vout Start (V)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STOP,ATTR_LABEL_TEXT, "Vout Stop (V)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STEP,ATTR_LABEL_TEXT, "Vout Step (V)");
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_SET_Vout,ATTR_LABEL_TEXT, "SetVout (V)");
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_KPID);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 0);
init_phase();
save_LOG("Control ouput Pout");
break;
case MODE_PWM:
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_START,ATTR_LABEL_TEXT, "Iout Start (A)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STOP,ATTR_LABEL_TEXT, "Iout Stop (A)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STEP,ATTR_LABEL_TEXT, "Iout Step (A)");
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_SET_Pout,ATTR_LABEL_TEXT, "SetIout (A)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_START,ATTR_LABEL_TEXT, "PWM Start (%)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STOP,ATTR_LABEL_TEXT, "PWM Stop (%)");
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STEP,ATTR_LABEL_TEXT, "PWM Step (%)");
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_SET_Vout,ATTR_LABEL_TEXT, "SetPWM (%)");
init_phase();
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_KPID);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 1);
save_LOG("Control ouput PWM");
break;
}
return 0;
}

/**
* @brief Get_panel_control
* @return 0
* @date 10/12/2010
*
*/
int Get_panel_control(void)
{
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_FREQ,&consigne[0].freq); //en kHz
consigne[0].freq*= 1000;
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGPHAS,&consigne[0].phase);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_INTER,&consigne[0].interleaving);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vin_START,&consigne[0].Vin_START);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vin_STOP,&consigne[0].Vin_STOP);
if(consigne[0].Vin_START==consigne[0].Vin_STOP)
{
consigne[0].Vin_STEP=0;
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vin_STEP,consigne[0].Vin_STEP);
}else
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vin_STEP,&consigne[0].Vin_STEP);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_START,&consigne[0].Vout_START);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STOP,&consigne[0].Vout_STOP);
if(consigne[0].Vout_START==consigne[0].Vout_STOP)
{
consigne[0].Vout_STEP=0;
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STEP,consigne[0].Vout_STEP);
}else
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Vout_STEP,&consigne[0].Vout_STEP);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_START,&consigne[0].Pout_START);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STOP,&consigne[0].Pout_STOP);
if(consigne[0].Pout_START==consigne[0].Pout_STOP)
{
consigne[0].Pout_STEP=0;
SetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STEP,consigne[0].Pout_STEP);
}else
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Pout_STEP,&consigne[0].Pout_STEP);

GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_delays,&consigne[0].delays);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_Delay_Cal,&consigne[0].Delay_Cal);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_KP,&consigne[0].Kp);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_KI,&consigne[0].Ki);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_ACC,&consigne[0].accuracy);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_VMAX,&consigne[0].Vout_MAX);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_IMAX,&consigne[0].Iin_MAX);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_PWMMAX,&consigne[0].pwm_MAX);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_NB_CYCLE,&consigne[0].nb_cycle);
//GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_CAL_AUTO,&measure[0].CalIin_Auto);
measure[0].CalVin_Auto=0;
measure[0].CalVout_Auto=0;
measure[0].CalIin_Auto=1;
measure[0].CalIout_Auto=1;
return 0;
}

/**
* @brief Set_panel_measure_time
* @return 0
* @date 10/12/2010
*
*/
int Set_panel_measure_time_total(void)
{
char buffer[1024];
struct tm *time_total;
double a,b,c;
a= ((consigne[0].Vin_STOP - consigne[0].Vin_START)/consigne[0].Vin_STEP)+1;
b= ((consigne[0].Pout_STOP - consigne[0].Pout_START)/consigne[0].Pout_STEP)+1;
c= ((consigne[0].Vout_STOP - consigne[0].Vout_START)/consigne[0].Vout_STEP)+1;
Ctrl.time_total=a * b *c *consigne[0].delays * 1.1;
time_total = gmtime(&Ctrl.time_total);
strftime (buffer,80,"%j:%H:%M:%S\0",time_total);
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_TXT_TIME,buffer);

return 0;
}

/**
* @brief Set_panel_measure_time
* @return 0
* @date 10/12/2010
*
*/
int Set_panel_measure_time_remaining(void)
{
char buffer[1024];
struct tm *time_remaining;
time_remaining = gmtime ( &Ctrl.time_remaining);
strftime (buffer,80,"%j:%H:%M:%S\0",time_remaining);
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_TXT_TIME_3,buffer);
return 0;
}

/**
* @brief Set_panel_measure_time
* @return 0
* @date 10/12/2010
*
*/
int Set_panel_measure_time_elapsed (void)
{
char buffer[1024];
struct tm *time_elapsed ;
time_elapsed = gmtime ( &Ctrl.time_elapsed );
strftime (buffer,80,"%j:%H:%M:%S\0",time_elapsed );
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_TXT_TIME_2,buffer);

return 0;
}


/**
* @brief fnct_stop
* @return 0
* @date 10/12/2010
*
*/
int fnct_stop (void)
{
int ctrlarray;
cmd_power(0,0,0);
cmd_AFG_out(INST_AFG,1,0);
cmd_AFG_out(INST_AFG,2,0);
cmd_AFG_out(INST_AFG_2,1,0);
cmd_AFG_out(INST_AFG_2,2,0);
cmd_load(0,0,0);
SetAsyncTimerAttribute (Ctrl.timer_id,ASYNC_ATTR_ENABLED,0 );//desactivation timer
if(Ctrl.verbose)
{
save_LOG("CVI_TIMER OFF");
}
save_LOG("STOP");
if(file_LOG_mesure!=NULL)
{
fclose(file_LOG_mesure);
file_LOG_mesure =NULL;
}
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_START,ATTR_DIMMED, 0);
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_CONTROL);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 0);
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_MEASURE].panel, CTRL_MEASURE);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 1);
return 0;
}
/**
* @brief fnct_start
* @return 0
* @date 10/12/2010
*
*/
int fnct_start (void)
{
int ctrlarray;
int test;
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_START,ATTR_DIMMED, 1);
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_CONTROL);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 1);
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_MEASURE].panel, CTRL_MEASURE);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 0);
save_dir_init();
Ctrl.time_remaining=Ctrl.time_total;
Ctrl.time_elapsed=0;
Ctrl.stop=0;
save_LOG("START");
DeleteGraphPlot (T_panel[PANEL_GRAPH].panel,P_GRAPH2D_GRAPH,-1 , VAL_IMMEDIATE_DRAW);
DisplayPanel (T_panel[PANEL_GRAPH].panel);
//init_PM_CAL();
init_PM_measure();
GetAsyncTimerAttribute(Ctrl.timer_id,ASYNC_ATTR_ENABLED,&test );
SetAsyncTimerAttribute (Ctrl.timer_id,ASYNC_ATTR_ENABLED,1 );//activation timer
if(Ctrl.verbose)
{
if(test==0)
{
save_LOG("CVI_TIMER ON");
}else
save_LOG("CVI_TIMER FAIL");
}
fnct_measure ();
fnct_stop();
return 0;
}

/**
* @brief fnct_measure
* @return 0
* @date 30/11/2012
*
*/
int fnct_measure_PM (void)
{
char message [1024];
read_PM_YOKOGAWA(&measure[0].Vout,&measure[0].Iin,&measure[0].Pin,
&measure[0].Vin,&measure[0].Iout,&measure[0].Pout,&measure[0].V3,&measure[0].V4,&measure[0].I3,&measure[0].I4,&measure[0].P3,&measure[0].P4);
read_Cal_PM_YOKOGAWA(&measure[0].CalVin,&measure[0].CalIin,
&measure[0].CalVout,&measure[0].CalIout);
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCin_V,measure[0].Vin);
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCin_I,measure[0].Iin);
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCin_P,measure[0].Pin);
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_V,measure[0].Vout);
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_I,measure[0].Iout);
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_P,measure[0].Pout);
if(Ctrl.m_V3)
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_V3,measure[0].V3);
if(Ctrl.m_V4)
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_V4,measure[0].V4);
if(Ctrl.m_I3)
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_I3,measure[0].I3);
if(Ctrl.m_I4)
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_I4,measure[0].I4);
if(Ctrl.m_P3)
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_P3,measure[0].P3);
if(Ctrl.m_P4)
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_P4,measure[0].P4);
measure[0].n= measure[0].Pout/measure[0].Pin*100;
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_n_DCDC,measure[0].n);
if(measure[0].Iin>= consigne[0].Iin_MAX)
{
Ctrl.stop=1;
sprintf (message," ERROR Iin(%2.2f)>=%2.2f",measure[0].Iin,consigne[0].Iin_MAX);
save_LOG(message);
}
if(measure[0].Vout>= consigne[0].Vout_MAX)
{
Ctrl.stop=1;
sprintf (message," ERROR Vout(%2.2f)>=%2.2f",measure[0].Vout,consigne[0].Vout_MAX);
save_LOG(message);
}
return 0;
}
/**
* @brief fnct_measure
* @return 0
* @date 23/09/2013
*
*/
int fnct_measure (void)
{
double pout,vin;
int i;
int color=0;
int test_Vout=0;
int test_Vin=0;
int test_Pout=0;
int cycle;
pf_mesure=NULL;
for(cycle=0;cycle<consigne[0].nb_cycle;cycle++)
{
consigne[0].Vout=consigne[0].Vout_START;
do //Vout ou PWM
{
ProcessSystemEvents ();
if(Ctrl.stop==1)
return 1;
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_SET_Vout,consigne[0].Vout);
//cmd_PM_CAL_V(2,consigne[0].Vout);
vin=consigne[0].Vin_START;
//
do //Vin
{
ProcessSystemEvents ();
if(Ctrl.stop==1)
return 1;
consigne[0].Vin=vin;
//cmd_PM_CAL_V(1,consigne[0].Vin);
save_mesure_init (cycle);
if(Ctrl.Iout==MODE_PWM)
consigne[0].pwm=consigne[0].Vout;
else
consigne[0].pwm=MIN_PWM;
consigne[0].sigma_error=0;
pout=consigne[0].Pout_START;
//
do //Pout -> Iout si Ctrl.Iout=0
{
ProcessSystemEvents ();
if(Ctrl.stop==1)
return 1;
if(Ctrl.Iout==MODE_IOUT)
cmd_load(consigne[0].Vout_MAX,pout,1);
if(Ctrl.Iout==MODE_POUT)
cmd_load(consigne[0].Vout_MAX,pout/consigne[0].Vout,1);
if(Ctrl.Iout==MODE_PWM)
cmd_load(consigne[0].Vout_MAX,pout,1);
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_SET_Pout,pout);
Delay(0.5);
cmd_power(vin,consigne[0].Iin_MAX,1);
Delay( consigne[0].Delay_Cal);
if(Ctrl.pid==1)
{
if(fnct_PID()<0)
{
Ctrl.stop=1;
return -1;
}
}
else
{
Delay(consigne[0].delays);
fnct_measure_PM();
}
save_mesure ();
fnct_plot(color);
pout+=consigne[0].Pout_STEP;
if(consigne[0].Pout_STEP>0)
test_Pout=(pout<=consigne[0].Pout_STOP);
if(consigne[0].Pout_STEP<0)
test_Pout=(pout>=consigne[0].Pout_STOP);
if(consigne[0].Pout_STEP==0)
test_Pout=0;
}while(test_Pout);
//
color=++color%15;
vin+=consigne[0].Vin_STEP;
if(consigne[0].Vin_STEP>0)
test_Vin=(vin<=consigne[0].Vin_STOP);
if(consigne[0].Vin_STEP<0)
test_Vin=(vin>=consigne[0].Vin_STOP);
if(consigne[0].Vin_STEP==0)
test_Vin=0;
if(pf_mesure!=NULL)
{
fclose(pf_mesure);
pf_mesure=NULL;
}
}while(test_Vin);
//
consigne[0].Vout+=consigne[0].Vout_STEP;
if(consigne[0].Vout_STEP>0)
test_Vout=(consigne[0].Vout<=consigne[0].Vout_STOP);
if(consigne[0].Vout_STEP<0)
test_Vout=(consigne[0].Vout>=consigne[0].Vout_STOP);
if(consigne[0].Vout_STEP==0)
test_Vout=0;
}while(test_Vout);
}
return 0;
}

/**
* @brief fnct_PID
* @return 0
* @date 10/12/2010
*
*/
int fnct_PID (void)
{
double volt;
double error;
double proportional;
double inetgral;
int eventPanel,eventCtrl;
int ctrlarray;
char message_LOG[1024];
time_t temps;
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_MEASURE].panel, CTRL_PID);
cmd_AFG_pwm(INST_AFG,1,consigne[0].pwm);

cmd_AFG_out(INST_AFG,1,Ctrl.phase1);
cmd_AFG_out(INST_AFG,2,Ctrl.phase2);
cmd_AFG_out(INST_AFG_2,1,Ctrl.phase3);
cmd_AFG_out(INST_AFG_2,2,Ctrl.phase4);
cmd_AFG_trig(INST_AFG);
temps=Ctrl.time_elapsed;
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 1);
//PID
if((Ctrl.Iout==MODE_IOUT) || (Ctrl.Iout==MODE_POUT))
do{
ProcessSystemEvents ();
if(Ctrl.stop==1)
return 1;
read_PM_volt(&volt);
error=consigne[0].Vout-volt;
proportional=consigne[0].Kp*error;
consigne[0].sigma_error+=error;
if(consigne[0].sigma_error<0) //intergrateur negatif
consigne[0].sigma_error=0;
inetgral=consigne[0].Ki*consigne[0].sigma_error;
consigne[0].pwm= proportional+ inetgral;
if(consigne[0].pwm>consigne[0].pwm_MAX)
{
sprintf (message_LOG," ERROR PWM(%2.2f)>%2.2f",consigne[0].pwm,consigne[0].pwm_MAX);
save_LOG(message_LOG);
sprintf (message_LOG," and Vout(%2.2fV)>VoutSet(%2.2fV)",volt,consigne[0].Vout);
save_LOG(message_LOG);
return -2;
}
if(consigne[0].pwm<MIN_PWM)
{
sprintf (message_LOG," ERROR PWM(%2.2f)<%2.2f",consigne[0].pwm,MIN_PWM);
save_LOG(message_LOG);
consigne[0].pwm=MIN_PWM;
}
cmd_AFG_pwm_ALL(consigne[0].pwm);
} while(consigne[0].accuracy <=fabs((consigne[0].Vout-volt)/consigne[0].Vout*100) );
else
cmd_AFG_pwm_ALL(consigne[0].pwm);
//DELAYS
do{
ProcessSystemEvents ();
if(Ctrl.stop==1)
return 1;
}while(consigne[0].delays>(Ctrl.time_elapsed-temps));
fnct_measure_PM();
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 0);
return 0;
}

/**
* @brief fnct_plot
* @return 0
* @date 10/12/2010
*
*/
int fnct_plot (int color)
{
int plotColors[15] = {VAL_BLACK,VAL_RED,VAL_GREEN,VAL_BLUE,VAL_CYAN,
VAL_MAGENTA,VAL_YELLOW,VAL_DK_RED, VAL_DK_BLUE, VAL_DK_GREEN,
VAL_DK_CYAN, VAL_DK_MAGENTA, VAL_DK_YELLOW,VAL_GRAY};
PlotPoint (T_panel[PANEL_GRAPH].panel,P_GRAPH2D_GRAPH,measure[0].Pin,measure[0].n,VAL_SMALL_SOLID_SQUARE,plotColors[color]);
return 0;
}
/**
* @brief fnct_plot
* @return 0
* @date 10/12/2010
*
*/
int fnct_cal_err(void)
{
measure[0].ErrVin=(0.05*measure[0].Vin)/100+(0.05*measure[0].CalVin)/100;
measure[0].ErrVout=(0.05*measure[0].Vout)/100+(0.05*measure[0].CalVout)/100;

measure[0].ErrIin=(0.05*measure[0].Iin)/100+(0.05*measure[0].CalIin)/100;
measure[0].ErrIout=(0.05*measure[0].Iout)/100+(0.05*measure[0].CalIout)/100;

measure[0].ErrPin=(0.05*measure[0].Pin)/100+(0.1*measure[0].CalVin*measure[0].CalIin)/100;
measure[0].ErrPout=(0.05*measure[0].Pout)/100+(0.1*measure[0].CalVout*measure[0].CalIout)/100;

measure[0].Errnmoins=(measure[0].Pout-measure[0].ErrPout)/(measure[0].Pin+measure[0].ErrPin)*100;
measure[0].Errnplus=(measure[0].Pout+measure[0].ErrPout)/(measure[0].Pin-measure[0].ErrPin)*100;
return 0;
}

/**
* @brief fnct_attente
* @param [in] temps en seconde
* @param [in] message
* @return 0
* @date 24/10/2012
*
*/
int fnct_attente (int i,char* message)
{
char message2[15];
SetCtrlVal (T_panel[PANEL_INFO].panel,P_INFO_TEXTMSG,message);
sprintf(message2,".");
DisplayPanel (T_panel[PANEL_INFO].panel);
while(i!=0)
{
strcat (message2,".");
SetCtrlVal (T_panel[PANEL_INFO].panel,P_INFO_TEXTMSG_2,message2);
Delay(1);
--i;
}
HidePanel(T_panel[PANEL_INFO].panel);
return 0;
}
(12-12/25)