⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acmotor.c

📁 该程序是ST7MC驱动三洋压缩机(交流)
💻 C
字号:
/**************** (c) 2004  STMicroelectronics ********************************
     
PROJECT  : 3-phase AC induction motor drive Software Library
COMPILER : COSMIC / METROWERKS

MODULE  :  acmotor.c
VERSION :  1.0.0

CREATION DATE : April 2004

AUTHOR :	V. Onde / Microcontroller Division Applications
			Consumer & Micro Group

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

DESCRIPTION :   3-phase AC motor control routines, include Start/Stop 
					management and PI regulation
              
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

MODIFICATIONS :

*******************************************************************************
 THE SOFTWARE INCLUDED IN THIS FILE IS FOR GUIDANCE ONLY. ST MICROELECTRONICS
 SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES
 WITH RESPECT TO ANY CLAIMS ARISING FROM USE OF THIS SOFTWARE.
******************************************************************************/

#include "lib.h"		/*General purpose typedefs and macros */
#include "mtc.h"		/*Public motor control peripheral function prototypes*/
#include "ACMparam.h"	/*AC Motor Control parameters */
#include "acmotor.h"	/*Public AC motor control function prototypes */
#include "pwmart.h"		/*Public general purpose Timebase function prototypes*/

#ifdef PI_PARAM_TUNING
	u8	Kp, Ki;
#else
	static u8	Kp, Ki;
#endif

static s32 VoltageIntegralTerm;                      
static s8 Error_slip;
static s32	DeltaVoltage_slip;
static s16	Voltage_slip;
static s32	DeltaVoltage_slip_s32;
static s32	Voltage_slip_s32;         
static BOOL MinPiOut;
static BOOL MaxPiOut;


#define	VOLT_INIT	((u8)0)		/* Voltage initialisation at MCU start-up */
#define	FREQ_INIT	((u16)50)	/* Freq initialisation at MCU start-up */

#define SLEW_LIMIT	((u8)20)	/* Voltage and frequency increment/decrement 
								rate in ms */

/*-----------------------------------------------------------------------------
ROUTINE Name : ACM_Init

Description: This function performs the initialisation of ACM module.
             Conditions for proper initialisation of ACM module:
             _ MTC functions called in below described order,
             _ Init Sinewave generation with Voltage = 0 to be sure that duty 
               cycle on each phase is 50% when starting.
-----------------------------------------------------------------------------*/
void ACM_Init(void)
{

	MTC_InitPeripheral();			// Initialize peripheral for three phase PWM generation
	MTC_InitSineGen();				// Configure SW variables for sinewave generation

   MTC_Set_ClockWise_Direction();

	ART_SetSpeedRegPeriod(SAMPLING_TIME);
	
}


/*-----------------------------------------------------------------------------
ROUTINE Name : ACM_VoltageMaxAllowed

Description: This function limits the voltage on motor stator according to
             setpoints given in ACMParam.h. It performs a linear interpolation.
             No error codes are returned if StatorFrequency is outside the 
             frequency domain given in MTCParam.h [VF_LOWFREQ_LIMIT/VF_HIGHFREQ_LIMIT].
Duration:
Important caution: when modifying setpoints, user must keep in mind that
            VF_COEFF, VF_OFFSET and local variable Buffer are declared as u16.
            They must therefore be declared as u32 there is chance for overflow to occur.
-----------------------------------------------------------------------------*/
u8 ACM_VoltageMaxAllowed(u16 StatorFrequency)
{
         u8  VoltageMax;

  if ( StatorFrequency <= VF_LOWFREQ_LIMIT )
  {
       VoltageMax = V_MIN;

  } else if ( StatorFrequency >= VF_HIGHFREQ_LIMIT )
         {
              VoltageMax = V_MAX;

         } else {
                       u16 Buffer;
                   Buffer = (u16)(StatorFrequency * VF_COEFF) - VF_OFFSET;
                   VoltageMax = (u8)(V_MIN + (u8)((u16)Buffer / (u16)256));
            /* 256 factor is included in VF COEFF and VF_OFFSET calculations */
                        /* Aim is to keep calculation accuracy */
                }

  return ( VoltageMax );
}


/*-----------------------------------------------------------------------------
ROUTINE Name : ACM_InitSoftStart

Description: This function initializes the soft start procedure: it forces 
				the voltage to be null, enable the PMW outputs and set-up the 
				timebases required to smoothly increase voltage and have a start-up
				time out.
-----------------------------------------------------------------------------*/
void ACM_InitSoftStart(u16 StatorFreq)
{
		u8 VoltageMax = ACM_VoltageMaxAllowed( StatorFreq );
		u16 TimeUnit;


	MTC_InitTachoMeasure( );
	MTC_UpdateSine(0, StatorFreq);
	MTC_EnableMCOutputs();			// PWM is present on MCO outputs

	TimeUnit = START_TIMEOUT / VoltageMax;
	if ( TimeUnit == 0 )
	{
		TimeUnit = 1;   /* Avoid applying full voltage directly */
	}
	ART_Set_TimeInMs(TimeUnit);		// Set soft start slope
		
	ART_SetSequenceDuration(START_TIMEOUT + EXTRA_TIMEOUT);

}


/*-----------------------------------------------------------------------------
ROUTINE Name : ACM_SoftStart

Description: This function provides a soft start which limits the inrush current 
				in the motor. It also monitors the speed feedback to stop 
				the voltage increase when a given minimum rotor speed is reached.
				The function ramps up the stator voltage linearly while the stator 
				frequency remains constant. The ramp ends when one of the following 
				conditions occurs:
				

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -