开环磁链的理解

http://blog.sina.com.cn/s/blog_14c6479ae0102vk3s.html

1.rampgen.h
=================================================================================
File name:        RAMPGEN.H  (IQ version)                   
Description: 
This file contains type definitions, constants and initializers for
the ramp generation functions contained in RAMPGEN.C
=====================================================================================
#ifndef __RAMPGEN_H__
#define __RAMPGEN_H__

typedef struct 
{    _iq  Freq; // Input: Ramp frequency (pu)
     _iq  StepAngleMax;   // Parameter: Maximum step angle (pu)
     _iq  Angle; // Variable: Step angle (pu)  
     _iq  Gain;       // Input: Ramp gain (pu)
     _iq  Out;       // Output: Ramp signal (pu)
     _iq  Offset;    // Input: Ramp offset (pu)  
     void  (*calc)(); // Pointer to calculation function
 } RAMPGEN;            

typedef RAMPGEN *RAMPGEN_handle;  
------------------------------------------------------------------------------
      Object Initializers
------------------------------------------------------------------------------                    
#define RAMPGEN_DEFAULTS {0,0,0,_IQ(1),0,_IQ(1),
                         (void (*)(Uint32))rampgen_calc }
------------------------------------------------------------------------------
      Funtion prototypes
------------------------------------------------------------------------------                    
 void rampgen_calc(RAMPGEN_handle);
#endif // __RAMPGEN_H__

2.rampgen.c
=====================================================================================
 File name:        RAMPGEN.C  (IQ version)                  
 Description:  The Ramp Generation                   
=====================================================================================
#include "IQmathLib.h"         // Include header for IQmath library
// Don't forget to set a proper GLOBAL_Q in "IQmathLib.h" file
#include "dmctype.h"
#include "rampgen.h"

void rampgen_calc(RAMPGEN *v)
{

// Compute the angle rate
        v->Angle += _IQmpy(v->StepAngleMax,v->Freq);       

// Saturate the angle rate within (-1,1)        
        if (v->Angle>_IQ(1.0))
          v->Angle -= _IQ(1.0);
        else if (v->Angle<_IQ(-1.0))
          v->Angle += _IQ(1.0);

// Compute the ramp output
       v->Out = _IQmpy(v->Angle,v->Gain) + v->Offset;

// Saturate the ramp output within (-1,1)     
       if (v->Out>_IQ(1.0))
          v->Out -= _IQ(1.0);
        else if (v->Out<_IQ(-1.0))
          v->Out += _IQ(1.0);
}

3. pmsm.c
float32 T = 0.001/ISR_FREQUENCY;  // Samping period=0.001(ms)/20(kHz)=0.00005 (sec), see parameter.h
//Instance a ramp generator to simulate an Anglele
RAMPGEN rg1 = RAMPGEN_DEFAULTS;
// Initialize RAMPGEN module
rg1.StepAngleMax = _IQ(BASE_FREQ*T);   //BASE_FREQ=200Hz, StepAngleMax =200Hz * 0.00005s =0.01
void main(void)
{
}
 
4. interrupt void MainISR
interrupt void MainISR(void)
{
// Verifying the ISR
    IsrTicker++;
// ***************** LEVEL1 *****************
#if (BUILDLEVEL==LEVEL1)
// ------------------------------------------------------------------------------
//    Connect inputs of the RMP module and call the Ramp control
//    calculation function.
// ------------------------------------------------------------------------------
    rc1.TargetValue = _IQ(SpeedRef);
    rc1.calc(&rc1);
// ------------------------------------------------------------------------------
//    Connect inputs of the RAMP GEN module and call the Ramp generator
//    calculation function.
// ------------------------------------------------------------------------------
    rg1.Freq = rc1.SetpointValue;
    rg1.calc(&rg1);
// ------------------------------------------------------------------------------
//    Connect inputs of the INV_PARK module and call the inverse park transformation
//    calculation function.
// ------------------------------------------------------------------------------
    VdTesting = 0.0585+(fabs(rg1.Freq)-0.16)*0.305;
    VqTesting = VdTesting;
    ipark1.Ds = _IQ(VdTesting);
    ipark1.Qs = _IQ(VqTesting); 
    ipark1.Angle = rg1.Out;
    ipark1.calc(&ipark1);
// ------------------------------------------------------------------------------
//    Connect inputs of the SVGEN_DQ module and call the space-vector gen.
//    calculation function.
// ------------------------------------------------------------------------------
    svgen_dq1.Ualpha = ipark1.Alpha;
  svgen_dq1.Ubeta = ipark1.Beta;
   svgen_dq1.calc(&svgen_dq1); 
// ------------------------------------------------------------------------------
//    Connect inputs of the PWM_DRV module and call the PWM signal generation
//    update function.
// ------------------------------------------------------------------------------
    pwm1.MfuncC1 = (int16)_IQtoQ15(svgen_dq1.Ta); // MfuncC1 is in Q15
    pwm1.MfuncC2 = (int16)_IQtoQ15(svgen_dq1.Tb); // MfuncC2 is in Q15 
    pwm1.MfuncC3 = (int16)_IQtoQ15(svgen_dq1.Tc); // MfuncC3 is in Q15
 pwm1.update(&pwm1);
// ------------------------------------------------------------------------------
//    Connect inputs of the DATALOG module
// ------------------------------------------------------------------------------
    DlogCh1 = (int16)_IQtoQ15(rg1.Out);
    DlogCh2 = (int16)_IQtoQ15(svgen_dq1.Ta);
    DlogCh3 = (int16)_IQtoQ15(svgen_dq1.Tb);
    DlogCh4 = (int16)_IQtoQ15(svgen_dq1.Tc);
#endif // (BUILDLEVEL==LEVEL1)
}

在这里插入图片描述

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试
应支付0元
点击重新获取
扫码支付

支付成功即可阅读