# 开环磁链的理解

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)
}



03-29 5471

05-15 33

03-19 1066

03-27 325

10-09 1万+

02-01 446

02-14 738

04-25 3421

02-18 209

12-18 59

03-09 2159

11-08 6554

03-18 869

02-25 1034

03-05 369

04-19 33

04-25 926

03-15 94

09-25 5056

04-14 59万+

03-13 15万+

02-19 18万+

03-04 14万+

03-06 2286

03-08 2万+

04-25 7万+

03-10 13万+

03-10 18万+

03-12 11万+

03-13 11万+

03-16 1873

03-18 1万+

03-19 8万+

03-19 3万+

03-20 9698

03-22 4725

03-23 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-27 5万+

03-29 22万+

03-29 10万+

03-30 16万+

06-01 6835

04-02 6294

04-02 4万+

06-01 342

04-06 1万+

04-06 7万+

04-06 3559

04-09 8万+

04-09 3万+

05-17 9199

04-11 4万+

04-15 6万+

04-18 4万+

04-20 4万+

04-24 3万+

05-03 1万+

05-16 5万+

05-06 1万+

05-06 2316

05-07 4058

05-08 4万+

05-10 3657

05-11 2647

05-14 6986

05-14 1255

05-16 3915

05-16 1万+

05-17 5394

05-30 1399

05-18 2540

05-18 8873

05-18 3962

05-19 1万+

05-21 8660

05-21 8772

#### 老码农吐血建议：2020年，低于1w的程序员要注意了...

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试