📄 pi.c
字号:
/*
* Project: 3-PHASE AC DRIVE
*
* Microcontroller: Motorola MC68HC908MR24
*
* Module: PI.C
* Revision/Date: 2.0 / February 2000
* Description: This module is responsible for calculation of control
* algorithm of the drive. It is called by MAIN.C s/w
* timer and uses subroutines in the file RAMP.C.
*
* Compiler: Hiware08 - COSMIC Software Inc.
*
* Author: Radim VISINKA
* Company: MOTOROLA SPS
* Motorola Czech Systems Laboratories
* Roznov pod Radhostem, Czech Republic
*
* ===================================================================
*
* Copyright (c): MOTOROLA Inc.,1998, All rights reserved.
*
* ====================================================================
* THIS SOFTWARE IS PROVIDED BY MOTOROLA RSAL "AS IS" AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA RSAL OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
/* DEFINITION_START */
#include <mr24io.h>
#include "CONST.H" /* file contains global constants
and definitions */
/* Include Header Files */
/* Assembler Subroutine Definitions */
/* Constant Definitions */
/* Global Variables (External) - 8 bit */
extern unsigned char Mcs_status; /* Status register of MCS */
extern unsigned char Fault_flags; /* 8 bit fault flag register */
extern unsigned char Dcb_voltage; /* AD value of DC Bus voltage */
extern unsigned char Speed_control; /* Control register for OPEN/CLOSED loop */
/* Global Variables (External) - 16 bit */
extern signed int V_command; /* command speed */
extern signed int V_com_actual; /* actual ramp speed */
extern signed int V_out; /* output frequency */
extern unsigned int Tacho_pulses; /* pulses captured between 2 IC events*/
/* Local Variables - 8 bit */
signed char E_n_8;
/* Local Variables - 16 bit */
signed int In_1 = 0; /* integrational part of the PI */
signed int In_2; /* previous In_1 */
signed int E_n; /* control error */
signed int Temp_variable;
unsigned int V_actual_abs; /* ABS of V com_actual */
unsigned int V_tacho = 0; /* actual tacho speed in 8.8 */
signed int V_pi; /* output of PI controller */
/* External Subroutines */
extern void accel_ramp (void);
extern void vhz_ramp (void);
/* DEFINITION_END */
void pi (void)
{
/* IF disable state, leave the routine */
if (Mcs_status & MCS_STAND_BY)
{
In_1 = 0;
V_pi = 0;
V_com_actual = 0;
}
else /* IF enable state, performe the calculations */
{
/* Overvoltage Protection During Deceleration */
if ((~(Mcs_status)) & MCS_ACCEL) /* if deceleration in process */
{
if (Dcb_voltage > DEC_HIGH_DCB_V)
{
Fault_flags |= OV_DEC_FLAG;
}
else /* DCB voltage < high limit */
{
if (Fault_flags & OV_DEC_FLAG) /* if overvoltage in process */
{
if (Dcb_voltage < DEC_LOW_DCB_V) /* DCB voltage < low limit */
{
Fault_flags &= (~(OV_DEC_FLAG));
accel_ramp (); /* Acceleration Ramp Calculation */
}
}
else /* no overvoltge occured */
{
accel_ramp (); /* Acceleration Ramp Calculation */
}
}
}
else
{
accel_ramp (); /* Acceleration Ramp Calculation */
}
/* Tacho speed calculation -> V_tacho in 8.8 format */
V_actual_abs = abs(V_com_actual);
/* in low speed tacho output is unprecise */
if (V_actual_abs < 0x0200) /* if v_actual < 5Hz */
{
if (Mcs_status & MCS_ACCEL) /* if acceleration in process */
{
V_tacho = (V_actual_abs>>1); /* V_tacho = ABS(V_actual) / 2 */
}
else /* if deceleration in process */
{
V_tacho = (V_actual_abs<<1); /* V_tacho = ABS(V_actual) * 2 */
}
}
else /* in higher speeds the tacho is OK */
{
V_tacho = ((F_TIMERA_2 / (Tacho_pulses>>1))<<6);
}
/* P I C O N T R O L L E R C A L C U L A T I O N */
E_n = V_actual_abs - V_tacho; /* Speed Error E_n */
E_n_8 = E_n>>8;
/* Calculate Integrational part of PI controller */
In_2 = In_1;
Temp_variable = (I_CONST * E_n_8);
/* Limitation of Integrator */
if ((Temp_variable > 0) && ((0x7f00 - In_1) < Temp_variable))
{
In_1 = 0x7f00;
}
else
{
if ((Temp_variable < 0) && (abs(Temp_variable) > In_1))
{
In_1 = 0;
}
else
{
In_1 = In_1 + Temp_variable;
if (In_1 > IN_1_LIMIT)
{
In_1 = IN_1_LIMIT;
}
}
}
/* Calculate Proportional part of the PI controller
andcreate PI Controller output */
Temp_variable = (P_CONST * E_n_8);
/* PWM output limitation */
if ((Temp_variable > 0) && ((0x7f00 - Temp_variable) < In_1))
{
V_pi = 0x7f00;
In_1 = In_2;
}
else
{
if ((Temp_variable < 0) && (abs(Temp_variable) > In_1))
{
V_pi = 0;
In_1 = 0;
}
else
{
V_pi = In_1 + Temp_variable;
}
}
/* Slip Limitation */
/* if ((abs(V_pi - V_tacho)) > MAX_SLIP)
{
if (V_pi > V_tacho)
{
V_pi = V_tacho + MAX_SLIP;
}
else
{
V_pi = V_tacho - MAX_SLIP;
}
}
*/
/* Calculate new stator frequency - forw. or rew. */
if ((V_pi < 0x0100) || (abs(V_com_actual) < 0x0100))
{
V_pi = 0;
}
else
{
if (V_com_actual < 0) /* if rewerse, negate the PI output */
{
V_pi = (-V_pi);
}
}
V_out = V_pi; /* output frequency */
/* OPEN/CLOSED LOOP OPTION */
if (Speed_control & OPEN_LOOP)
{
V_out = V_com_actual; /* Output frequency = actual command frequency */
}
/* Call subroutine ** vhz_ramp ** to calculate the voltage amplitude
according to V/Hz characteristic of the motor */
vhz_ramp();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -