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

📄 bldc_ti.c

📁 直流无刷电机控制程序
💻 C
字号:
/* ==============================================================================
System Name:  BLDC3_2

File Name:	BLDC_TI.C

Description:  Peripheral independent object for the implementation of
           current controller for a three phase brushless DC Motor.	

Originator:		Digital control systems Group - Texas Instruments

Target dependency:	x240/1/2/3/07
To Select the target device see target.h file.

=====================================================================================
 History:
-------------------------------------------------------------------------------------
 9-15-2000	Release	Rev 1.0
=================================================================================  */

/*------------------------------------------------------------------------------
 Include header file which defines BLDC Object. This header file has all the
 data necessary for one instance of a BLDC_TI algorithm.
------------------------------------------------------------------------------*/
#include <bldc_ti.h>

/*-------------------------------------------------------------------------------
    Get buildlevel information.
---------------------------------------------------------------------------------*/
#include <build.h>


/*------------------------------------------------------------------------------
 Notes: 1.  Attributes are conveniently changed here, but this does
            consume cycles twice,
            (a) in the 'C' boot-up, and then
            (b) in the execution of this code. Setting up the needed
                constants the declaration of  PID2 pid2   = PID2_VALUES,
                rather than the defaults is clearly more effecient.
                This method is more intended for runtime changes.
        2.  There is also a code-size associated with these changes.
-----------------------------------------------------------------------------*/

#if (BUILDLEVEL==LEVEL1)
void BLDC_TI_Init(BLDC_TI_handle v)
{
     v->cmtn_period_setpt=0x0500;
         
     v->rmp2.out = ALIGN_DUTY;
     v->rmp2.dly = 0x0050;
     v->rmp2.max = 0x7ff0;
     v->rmp2.min = 0x000f;

     v->rmp3.desired = v->cmtn_period_target;//开环启动的终止速度
     v->rmp3.dly = v->ramp_delay;//启动时加速步距 RMP3CNTL启动时用到的模块
     v->rmp3.out = v->cmtn_period_setpt;//加速的时间 是输出
     v->rmp3.min = 0x0050;

     v->cmtn.nw_dynThold = 0x000f;
     v->cmtn.cdnw_delta = 0x0002;
     v->cmtn.noise_windowMax =
     v->cmtn.nw_dynThold - v->cmtn.cdnw_delta;

     v->pid2.max_reg2 = 0x7000;    /* Q15                           */
     v->pid2.min_reg2 = 0x0000;    /* Q15                           */
     v->pid2.k0_reg2  = 0x0080;    /* Q9                            */
     v->pid2.k1_reg2  = 0x0140;    /* Q13                           */
     v->pid2.kc_reg2  = 0x0506;    /* Q13                           */
}  /* End : BLDC_TI_Init() */
#endif  /* (BUILDLEVEL==LEVEL1) */

#if (BUILDLEVEL==LEVEL2)
void BLDC_TI_Init(BLDC_TI_handle v)
{
     v->rmp2.out = ALIGN_DUTY;
     v->rmp2.dly = 0x0050;
     v->rmp2.max = 0x7ff0;
     v->rmp2.min = 0x000f;

     v->rmp3.desired = v->cmtn_period_target;
     v->rmp3.dly = v->ramp_delay;
     v->rmp3.out = v->cmtn_period_setpt;
     v->rmp3.min = 0x0050;

     v->cmtn.nw_dynThold = 0x000f;
     v->cmtn.cdnw_delta = 0x0002;
     v->cmtn.noise_windowMax =
                v->cmtn.nw_dynThold - v->cmtn.cdnw_delta;

     v->pid2.max_reg2 = 0x7000;    /* Q15                           */
     v->pid2.min_reg2 = 0x0000;    /* Q15                           */
     v->pid2.k0_reg2  = 0x0080;    /* Q9                            */
     v->pid2.k1_reg2  = 0x0140;    /* Q13                           */
     v->pid2.kc_reg2  = 0x0506;    /* Q13                           */
}  /* End : BLDC_TI_Init() */
#endif  /* (BUILDLEVEL==LEVEL2) */

#if (BUILDLEVEL==LEVEL3)
void BLDC_TI_Init(BLDC_TI_handle v)
{
     v->rmp2.out = ALIGN_DUTY;
     v->rmp2.dly = 0x0050;
     v->rmp2.max = 0x7ff0;
     v->rmp2.min = 0x000f;

     v->rmp3.desired = v->cmtn_period_target;
     v->rmp3.dly = v->ramp_delay;
     v->rmp3.out = v->cmtn_period_setpt;
     v->rmp3.min = 0x0050;

     v->cmtn.nw_dynThold = 0x000f;
     v->cmtn.cdnw_delta = 0x0002;
     v->cmtn.noise_windowMax =
                v->cmtn.nw_dynThold - v->cmtn.cdnw_delta;

     v->pid2.max_reg2 = 0x7000;    /* Q15                           */
     v->pid2.min_reg2 = 0x0000;    /* Q15                           */
     v->pid2.k0_reg2  = 0x0080;    /* Q9                            */
     v->pid2.k1_reg2  = 0x0140;    /* Q13                           */
     v->pid2.kc_reg2  = 0x0506;    /* Q13                           */
}  /* End : BLDC_TI_Init() */
#endif  /* (BUILDLEVEL==LEVEL3) */


#if (BUILDLEVEL==LEVEL4)
void BLDC_TI_Init(BLDC_TI_handle v)
{
    
    v->cmtn.nw_dynThold = 0x000f;
    v->cmtn.cdnw_delta = 0x0002;
    v->cmtn.noise_windowMax =
    v->cmtn.nw_dynThold - v->cmtn.cdnw_delta;

     v->rmp2.out = ALIGN_DUTY;
     v->rmp2.dly = 0x0050;
     v->rmp2.max = 0x7ff0;
     v->rmp2.min = 0x000f;

     v->rmp3.desired = v->cmtn_period_target;
     v->rmp3.dly = v->ramp_delay;
     v->rmp3.out = v->cmtn_period_setpt;
     v->rmp3.min = 0x0050;

     v->cmtn.nw_dynThold = 0x000f;
     v->cmtn.cdnw_delta = 0x0002;
     v->cmtn.noise_windowMax =
     v->cmtn.nw_dynThold - v->cmtn.cdnw_delta;

     v->pid2.max_reg2 = 0x7000;    /* Q15                           */
     v->pid2.min_reg2 = 0x0000;    /* Q15                           */
     v->pid2.k0_reg2  = 0x0080;    /* Q9                            */
     v->pid2.k1_reg2  = 0x0140;    /* Q13                           */
     v->pid2.kc_reg2  = 0x0506;    /* Q13                           */
}  /* End : BLDC_TI_Init() */
#endif  /* (BUILDLEVEL==LEVEL4) */

#if (BUILDLEVEL==LEVEL5)
void BLDC_TI_Init(BLDC_TI_handle v)
{
     v->rmp2.out = ALIGN_DUTY;
     v->rmp2.dly = 0x0050;
     v->rmp2.max = 0x7ff0;
     v->rmp2.min = 0x000f;

     v->rmp3.desired = v->cmtn_period_target;
     v->rmp3.dly = v->ramp_delay;
     v->rmp3.out = v->cmtn_period_setpt;
     v->rmp3.min = 0x0050;

     v->cmtn.nw_dynThold = 0x000f;
     v->cmtn.cdnw_delta = 0x0002;
     v->cmtn.noise_windowMax =
                v->cmtn.nw_dynThold - v->cmtn.cdnw_delta;

     v->pid2.max_reg2 = 0x7000;    /* Q15                           */
     v->pid2.min_reg2 = 0x0000;    /* Q15                           */
     v->pid2.k0_reg2  = 0x0080;    /* Q9                            */
     v->pid2.k1_reg2  = 0x0140;    /* Q13                           */
     v->pid2.kc_reg2  = 0x0506;    /* Q13                           */
}  /* End : BLDC_TI_Init() */
#endif  /* (BUILDLEVEL==LEVEL5) */


#if (BUILDLEVEL==LEVEL1)
void BLDC_TI_Run(BLDC_TI_handle v)
{
/*-----------------------------------------------------------------------------
    Open loop commutation control
-----------------------------------------------------------------------------*/
           (*v->rmp3.calc)(&v->rmp3);
           v->cmtn_period_setpt = v->rmp3.out;

           v->impl.period = v->rmp3.out;
           (*v->impl.calc)(&v->impl);

           v->mod6.trig_in = v->impl.out;
           (*v->mod6.calc)(&v->mod6);

           v->cmtn.ptr_ct = v->mod6.cntr;      /* Input to COMMUTATION_TRIGGER */
} /* BLDC_TI_Run() */
#endif /* (BUILDLEVEL==LEVEL1) */


#if (BUILDLEVEL==LEVEL2)
void BLDC_TI_Run(BLDC_TI_handle v)
{
          (*v->cmtn.calc)(&v->cmtn);

          (*v->rmp3.calc)(&v->rmp3);
          v->cmtn_period_setpt = v->rmp3.out;

          v->impl.period = v->rmp3.out;
          (*v->impl.calc)(&v->impl);

          v->mod6.trig_in = v->impl.out;
          (*v->mod6.calc)(&v->mod6);

          v->cmtn.ptr_ct = v->mod6.cntr;    /* Input to COMMUTATION_TRIGGER */
} /* BLDC_TI_Run() */
#endif /* (BUILDLEVEL==LEVEL2) */

#if (BUILDLEVEL==LEVEL3)
void BLDC_TI_Run(BLDC_TI_handle v)
{
          (*v->cmtn.calc)(&v->cmtn);

          (*v->rmp3.calc)(&v->rmp3);
          v->cmtn_period_setpt = v->rmp3.out;

          v->impl.period = v->rmp3.out;
          (*v->impl.calc)(&v->impl);

          v->mod6.trig_in = v->impl.out;
          (*v->mod6.calc)(&v->mod6);

          v->cmtn.ptr_ct = v->mod6.cntr;    /* Input to COMMUTATION_TRIGGER */
} /* BLDC_TI_Run() */
#endif /* (BUILDLEVEL==LEVEL3) */

#if (BUILDLEVEL==LEVEL4)
void BLDC_TI_Run(BLDC_TI_handle v)
{
        (*v->cmtn.calc)(&v->cmtn);

        if(FALSE == v->sp_up_done_flg){

            (*v->rmp3.calc)(&v->rmp3);
            v->sp_up_done_flg = v->rmp3.done_flg;
            v->cmtn_period_setpt = v->rmp3.out;
            v->impl.period  = v->rmp3.out;
            (*v->impl.calc)(&v->impl);

            v->mod6.trig_in = v->impl.out;
        }/*if(FALSE == v->sp_up_done_flg)*/
        else
            v->mod6.trig_in = v->cmtn.trig; /* Closed Loop */

       (*v->mod6.calc)(&v->mod6);  /* Open Loop   */

       v->cmtn.ptr_ct = v->mod6.cntr;    /* Input to COMMUTATION_TRIGGER */
/*--------------------------------------------------------------------------
Implements ramp control of D_func during open current loop control
---------------------------------------------------------------------------*/
        v->rmp2.desired = v->D_func_desired;
       (*v->rmp2.calc)(&v->rmp2);

} /* BLDC_TI_Run() */
#endif /* (BUILDLEVEL==LEVEL4) */


#if (BUILDLEVEL==LEVEL5)
void BLDC_TI_Run(BLDC_TI_handle v)
{
   (*v->cmtn.calc)(&v->cmtn);

   if(FALSE == v->sp_up_done_flg) {
        (*v->rmp3.calc)(&v->rmp3);
        v->sp_up_done_flg  = v->rmp3.done_flg;
        v->cmtn_period_setpt = v->rmp3.out;

        v->impl.period = v->rmp3.out;//脉冲周期信号
        (*v->impl.calc)(&v->impl);

        v->mod6.trig_in = v->impl.out;
   } /*if(FALSE == v->sp_up_done_flg)*/

   else
       v->mod6.trig_in = v->cmtn.trig; /* Closed Loop */

   (*v->mod6.calc)(&v->mod6); /* Open Loop */

   v->cmtn.ptr_ct = v->mod6.cntr;    /* Input to COMMUTATION_TRIGGER */

   v->pid2.ref_reg2 = v->current_set;
   (*v->pid2.calc)(&v->pid2);                                             /*
---------------------------------------------------------------------------
   Uses PID result when the flag is set, i.e., I_loop_flg=1
   Implements ramp control of D_func during open current loop
   control, i.e., I_loop_flg=0
---------------------------------------------------------------------------*/
   if(FALSE == v->I_loop_flg){
        v->rmp2.desired = v->D_func_desired;
        (*v->rmp2.calc)(&v->rmp2);
   } /*if(FALSE == v->I_loop_flg) */
} /* BLDC_TI_Run() */
#endif /* (BUILDLEVEL==LEVEL5) */

⌨️ 快捷键说明

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