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

📄 com_sub.c

📁 实现120无传感器变频输出
💻 C
字号:
/****************************************************************************/
/*                                                                          */
/*      common functions                                                    */
/*                                                                          */
/****************************************************************************/
/****************************************************************************/
/*                                                                          */
/*      include files                                                       */
/*                                                                          */
/****************************************************************************/
#include    "typedefine.h"                        /* type define file */
#include    "sfr26a.h"                           /* sfr define file */

#define MAIN (1)
#include    "com_ram.h"                         /* ram define file */
#include    "com_def.h"                         /* control define file */
#include    "com_sub.h"                         /* common subroutine */


#include "uart.h"
/****************************************************************************/
/*                                                                          */
/*      subroutine definition                                               */
/*                                                                          */
/****************************************************************************/
/****************************************************************************/
/*                                                                          */
/*      ram define                                                          */
/*                                                                          */
/****************************************************************************/
/****************************************************************************/
/*                                                                          */
/*      speed command calculation                                           */
/*                                                                          */
/****************************************************************************/



/*SINT_16    cal_wr_ref(UINT_16 ad)
{
    static  SINT_16    wr = (KIDO_Hz + 1);
    static  SINT_16    i = 0;
    static  SINT_32    wr_add;
    SINT_16    in;

    in = ((SINT_16)(ad - 512) * (SINT_32)K_WR_AD_REF) >> Sft_WR_AD_REF;   // change a-d input - speed command 
    wr_add += in;
    i ++;
 
    if(i >= 16)                                                     // speed command the average of 16 times 
    {
        wr = wr_add >> 4;
        wr_add = 0;
        i = 0;
    }
    return  wr;
}*/

SINT_16    cal_wr_ref(UINT_16 rpm)
{
    //SINT_16    wr;
    
    //wr = ((SINT_32) rpm * POLESNUM *RPMTORADFAC)>>15; // speed command  * 2
        
    return  ((SINT_16)(((SINT_32) rpm * POLESNUM *RPMTORADFAC)>>15));
}

UINT_16    cal_wract_ref(SINT_16 act_wr)
{    
    return ((UINT_16)(((UINT_32)act_wr << 15)/(RPMTORADFAC * POLESNUM ))); ;  
}

/****************************************************************************/
/*                                                                          */
/*      vdc calculation                                                     */
/*                                                                          */
/****************************************************************************/
void    cal_vdc_ref(UINT_16 ad)
{
    SINT_32    in;                                                             /* 041029 */
    static  SINT_16    i = 0;
    static  SINT_32    vdc_add = 0;

    in = ((SINT_32)K_VDC_AD_V * (SINT_16)ad) >> Sft_VDC_AD_V; /* change a-d input - vdc */

    vdc_add += in;
    i++;
    if(i >= 64)                                         /* vdc the average of 64 times */
    {
        i = 0;
        in = vdc_add >> 6;
        if(in >= VDC_MAX)   in = VDC_MAX;               /* vdc limit */
        if(in <= VDC_MIN)   in = VDC_MIN;
        vdc = (SINT_16)in;                                                     /* 041029 */
        vdc_inv = K_VDC_INV / vdc;                      /* 1/(vdc/2) calculation */
        vdc_add = 0;
    }
}

/****************************************************************************/
/*                                                                          */
/*      motor stop judgment                                                 */
/*                                                                          */
/****************************************************************************/
SINT_16    stop_chk(void)
{
    if(wr_ref == 0)             
    {
    	return  1;                      /* stop command */
    }
    if((invc0 & 0x08) == 0)     
    {
    	invc0 &= 0xf7;
    	g_TxdDat[3] = M_ErrFoIPM; 	/* IPM Fo error*/
    	return  1;                      /* overcurrent error */
    }
    return  0;
}

/****************************************************************************/
/*                                                                          */
/*      interrupt vector setting function                                   */
/*                                                                          */
/****************************************************************************/
void    set_int_vec(UINT_8 i, UINT_32 fp)
{
    //tbl_int_vec[i] = fp;
}



/****************************************************************************/
/*                                                                          */
/*  function : motor lock detection                                         */
/*  argument : none                                                         */
/*  return value : none                                                     */
/*  constant : motor lock detection time                                    */
/*                                                                          */
/****************************************************************************/
void    motor_lock_chk(void)
{
    SINT_16    lock_act;
   /* if(lock_tim == 0)
    {
        lock_tim = CNT_WR_ACT_4K;

        if((int2ic & 0x08) == 0)
        {
            if(lock_cnt < 0x7fff)   lock_cnt ++;
        }
        else
        {
            int2ic = 0x00;
            lock_cnt = 0;
        }
        if((lock_cnt >= E_MOT_LOCK_TIME) && (out_mode == TUJO_MODE))
        {
            prcr  = 0x02;
	        invc0 &= ~0x08;                      /* output disable */
        //    prcr  = 0x00;
       // }
    //}
}

⌨️ 快捷键说明

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