📄 isrs.c
字号:
// Calculate decel rate based on minimum period and the user parameter
// which determines time period over which ramp down will occur
windmilling_decel_rate=(BRAKING_PR2_LIMIT-new_PR2)/user_parameters[42];
// Invert direction in which energisation will occur
control_flags.DIR=FORWARDS;
// Force a Timer 2 interrupt event to start commutation
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
// Set current demand to the windmilling_demand which is derived from
// the user parameters for demand and scaling
current_demand=windmilling_demand;
ENABLE_FIRING;
return;
}
// To reach this section of code motor not windmilling and have detected a
// second valid rising edge and so ought to be able to launch sensorless.
// However, if going too fast, sensorless will get immediately lost due
// to enevitable error in threshold detection and because there may
// not be time for sufficient samples of VPH to catch the zero crossing
if (period_measurement > REACQUIRE_THRESHOLD) // If OK to run sensorless
{
// To ensure sensorless can pick straight up need to
// extrapolate backwards in time and set up previous timestamps
previous_timestamps[0]=new_edge_time - one_twenty_deg - thirty_deg;
previous_timestamps[1]=new_edge_time - thirty_deg;
previous_timestamps[2]=new_edge_time - one_twenty_deg + thirty_deg;
previous_delta=one_twenty_deg/2;
control_flags.ACQUIRE2=FALSE;
// Setting the SWAP flag triggers the transition to sensorless
control_flags.SWAP=TRUE;
// Set run state to RUNNING in case this was a flying start
run_state=RUNNING;
// Force a Timer 2 interrupt event to start commutation
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
ENABLE_FIRING;
}
else // Going too fast to re-acquire
{
// Force re-start of acqusition
control_flags.ADCCONFIG=TRUE;
// Also set ROTATION_CHECK flag
// so that rotation timer can't timeout before
// speed has fallen below where can re-acquire
control_flags2.ROTATION_CHECK=TRUE;
}
return;
}
if (control_flags.ACQUIRE2_YELLOW==TRUE)
{
sector=2;
OVDCON=SECTOR2_OVERRIDE;
one_twenty_deg=new_edge_time-previous_edge_time;
thirty_deg=one_twenty_deg/4;
period_measurement=one_twenty_deg+(one_twenty_deg/2);
stall_counter=0;
if (control_flags.DIR==FORWARDS) // If windmilling
{
sector=5;
OVDCON=SECTOR5_OVERRIDE;
control_flags2.WINDMILLING=TRUE;
control_flags2.ROTATION_CHECK=FALSE;
control_flags.ACQUIRE2=FALSE;
new_PR2=one_twenty_deg/2;
windmilling_decel_rate=(BRAKING_PR2_LIMIT-new_PR2)/user_parameters[42];
control_flags.DIR=BACKWARDS;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
current_demand=windmilling_demand;
ENABLE_FIRING;
return;
}
if (period_measurement > REACQUIRE_THRESHOLD) // If OK to run sensorless
{
previous_timestamps[0]=new_edge_time - one_twenty_deg - thirty_deg;
previous_timestamps[1]=new_edge_time - one_twenty_deg + thirty_deg;
previous_timestamps[2]=new_edge_time - thirty_deg;
previous_delta=one_twenty_deg/2;
control_flags.ACQUIRE2=FALSE;
control_flags.SWAP=TRUE;
run_state=RUNNING;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
ENABLE_FIRING;
}
else
{
control_flags.ADCCONFIG=TRUE;
control_flags2.ROTATION_CHECK=TRUE;
}
return;
}
// Save timestamp just taken as it will be required when second rising
// edge is detected to work out period etc.
previous_edge_time=new_edge_time;
// Set flag to indicate a valid rising edge has been detected on this phase
control_flags.ACQUIRE2_RED=TRUE;
}
}
/********************* END OF RED PHASE CODE *****************************************/
/********************START OF YELLOW PHASE CODE **************************************/
if ((vph_yellow < vph_yellow_threshold) \
&& (level_count_yellow < (unsigned char)user_parameters[35]))
{
level_count_yellow++;
}
if (level_count_yellow == (unsigned char)user_parameters[35])
{
if ((previous_vph_yellow >= vph_yellow_threshold) \
&& (vph_yellow >= vph_yellow_threshold))
{
new_edge_time=POSCNT;
if (control_flags.ACQUIRE2_YELLOW)
{
control_flags2.RETRY_FLAG=TRUE;
if (retry_counter)
retry_counter--;
control_flags.ADCCONFIG=TRUE;
return;
}
level_count_yellow=0;
if (control_flags.ACQUIRE2_RED==TRUE)
{
sector=1;
OVDCON=SECTOR1_OVERRIDE;
one_twenty_deg=new_edge_time-previous_edge_time;
thirty_deg=one_twenty_deg/4;
period_measurement=one_twenty_deg+(one_twenty_deg/2);
stall_counter=0;
if (control_flags.DIR==BACKWARDS)
{
sector=4;
OVDCON=SECTOR4_OVERRIDE;
control_flags2.WINDMILLING=TRUE;
control_flags2.ROTATION_CHECK=FALSE;
control_flags.ACQUIRE2=FALSE;
new_PR2=one_twenty_deg/2;
windmilling_decel_rate=(BRAKING_PR2_LIMIT-new_PR2)/user_parameters[42];
control_flags.DIR=FORWARDS;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
current_demand=windmilling_demand;
ENABLE_FIRING;
return;
}
if (period_measurement > REACQUIRE_THRESHOLD)
{
previous_timestamps[0]=new_edge_time - one_twenty_deg + thirty_deg;
previous_timestamps[1]=new_edge_time - one_twenty_deg - thirty_deg;
previous_timestamps[2]=new_edge_time - thirty_deg;
previous_delta=one_twenty_deg/2;
control_flags.ACQUIRE2=FALSE;
control_flags.SWAP=TRUE;
run_state=RUNNING;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
ENABLE_FIRING;
}
else
{
control_flags.ADCCONFIG=TRUE;
control_flags2.ROTATION_CHECK=TRUE;
}
return;
}
if (control_flags.ACQUIRE2_BLUE==TRUE)
{
sector=4;
OVDCON=SECTOR4_OVERRIDE;
one_twenty_deg=new_edge_time-previous_edge_time;
thirty_deg=one_twenty_deg/4;
period_measurement=one_twenty_deg+(one_twenty_deg/2);
stall_counter=0;
if (control_flags.DIR==FORWARDS)
{
sector=1;
OVDCON=SECTOR1_OVERRIDE;
control_flags2.WINDMILLING=TRUE;
control_flags2.ROTATION_CHECK=FALSE;
control_flags.ACQUIRE2=FALSE;
new_PR2=one_twenty_deg/2;
windmilling_decel_rate=(BRAKING_PR2_LIMIT-new_PR2)/user_parameters[42];
control_flags.DIR=BACKWARDS;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
current_demand=windmilling_demand;
ENABLE_FIRING;
return;
}
if (period_measurement > REACQUIRE_THRESHOLD)
{
previous_timestamps[0]=new_edge_time - thirty_deg;
previous_timestamps[1]=new_edge_time - one_twenty_deg - thirty_deg;
previous_timestamps[2]=new_edge_time - one_twenty_deg + thirty_deg;
previous_delta=one_twenty_deg/2;
control_flags.ACQUIRE2=FALSE;
control_flags.SWAP=TRUE;
run_state=RUNNING;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
ENABLE_FIRING;
}
else
{
control_flags.ADCCONFIG=TRUE;
control_flags2.ROTATION_CHECK=TRUE;
}
return;
}
previous_edge_time=new_edge_time;
control_flags.ACQUIRE2_YELLOW=TRUE;
}
}
/********************* END OF YELLOW PHASE CODE **********************************/
/**********************START OF BLUE PHASE CODE **********************************/
if ((vph_blue < vph_blue_threshold) \
&& (level_count_blue < (unsigned char)user_parameters[35]))
{
level_count_blue++;
}
if (level_count_blue == (unsigned char)user_parameters[35])
{
if ((previous_vph_blue >= vph_blue_threshold) \
&& (vph_blue >= vph_blue_threshold))
{
new_edge_time=POSCNT;
if (control_flags.ACQUIRE2_BLUE)
{
control_flags2.RETRY_FLAG=TRUE;
if (retry_counter)
retry_counter--;
control_flags.ADCCONFIG=TRUE;
return;
}
level_count_blue=0;
if (control_flags.ACQUIRE2_YELLOW==TRUE)
{
sector=3;
OVDCON=SECTOR3_OVERRIDE;
one_twenty_deg=new_edge_time-previous_edge_time;
thirty_deg=one_twenty_deg/4;
period_measurement=one_twenty_deg+(one_twenty_deg/2);
stall_counter=0;
if (control_flags.DIR==BACKWARDS)
{
sector=0;
OVDCON=SECTOR0_OVERRIDE;
control_flags2.WINDMILLING=TRUE;
control_flags2.ROTATION_CHECK=FALSE;
control_flags.ACQUIRE2=FALSE;
new_PR2=one_twenty_deg/2;
windmilling_decel_rate=(BRAKING_PR2_LIMIT-new_PR2)/user_parameters[42];
control_flags.DIR=FORWARDS;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
current_demand=windmilling_demand;
ENABLE_FIRING;
return;
}
if (period_measurement > REACQUIRE_THRESHOLD)
{
previous_timestamps[0]=new_edge_time - thirty_deg;
previous_timestamps[1]=new_edge_time - one_twenty_deg + thirty_deg;
previous_timestamps[2]=new_edge_time - one_twenty_deg - thirty_deg;
previous_delta=one_twenty_deg/2;
control_flags.ACQUIRE2=FALSE;
control_flags.SWAP=TRUE;
run_state=RUNNING;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
ENABLE_FIRING;
}
else
{
control_flags.ADCCONFIG=TRUE;
control_flags2.ROTATION_CHECK=TRUE;
}
return;
}
if (control_flags.ACQUIRE2_RED==TRUE)
{
sector=0;
OVDCON=SECTOR0_OVERRIDE;
one_twenty_deg=new_edge_time-previous_edge_time;
thirty_deg=one_twenty_deg/4;
period_measurement=one_twenty_deg+(one_twenty_deg/2);
stall_counter=0;
if (control_flags.DIR==FORWARDS)
{
sector=3;
OVDCON=SECTOR3_OVERRIDE;
control_flags2.WINDMILLING=TRUE;
control_flags2.ROTATION_CHECK=FALSE;
control_flags.ACQUIRE2=FALSE;
new_PR2=one_twenty_deg/2;
windmilling_decel_rate=(BRAKING_PR2_LIMIT-new_PR2)/user_parameters[42];
control_flags.DIR=BACKWARDS;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
current_demand=windmilling_demand;
ENABLE_FIRING;
return;
}
if (period_measurement > REACQUIRE_THRESHOLD)
{
previous_timestamps[0]=new_edge_time - one_twenty_deg + thirty_deg;
previous_timestamps[1]=new_edge_time - thirty_deg;
previous_timestamps[2]=new_edge_time - one_twenty_deg - thirty_deg;
previous_delta=one_twenty_deg/2;
control_flags.ACQUIRE2=FALSE;
control_flags.SWAP=TRUE;
run_state=RUNNING;
IFS0bits.T2IF=TRUE;
IEC0bits.T2IE=TRUE;
ENABLE_FIRING;
}
else
{
control_flags.ADCCONFIG=TRUE;
control_flags2.ROTATION_CHECK=TRUE;
}
return;
}
previous_edge_time=new_edge_time;
control_flags.ACQUIRE2_BLUE=TRUE;
}
}
/********************** END OF BLUE PHASE CODE *********************************/
// Save current VPH samples for use next call of routine
// Note that code above only returns before this point if an action is being taken
// on a rising edge detect.
previous_vph_red=vph_red;
previous_vph_yellow=vph_yellow;
previous_vph_blue=vph_blue;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -