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

📄 pwm_120slc20.c

📁 实现120无传感器变频输出
💻 C
📖 第 1 页 / 共 4 页
字号:
#ifdef SMPL_20kHz
/****************************************************************************/
/*                                                                          */
/*      trapezoidl wave control without sensor (back EMF)                   */
/*               (carrier 4kHz)                                            */

/*	Up--p80		*/
/*	Un--p81		*/
/*	Vp--p72		*/
/*	Vn--p73		*/
/*	Wp--p74		*/
/*	Wn--p75		*/

/****************************************************************************/
/****************************************************************************/
/*                                                                          */
/*      include                                                             */
/*                                                                          */
/****************************************************************************/
#include    "typedefine.h"
#include    "sfr26a.h"
#include    "com_ram.h"
#include    "com_def.h"
#include    "com_sub.h"

#include "table.h"

//2005-8-3 22:24
#include "timer.h"

#include "simbemfinput.h"
//ENDOF 2005-8-3 22:24

#include "dltcnt_convtbl.h"

#include "uart.h"

#ifdef DEBUG
#include "systimer.h"
#endif

/****************************************************************************/
/*                                                                          */
/*      constant definition                                                 */
/*                                                                          */
/****************************************************************************/
/*#pragma INTERRUPT/B	extint3_int
#pragma INTERRUPT/B	extint4_int
#pragma INTERRUPT/B	extint5_int
#pragma INTERRUPT/B	ta0_int

void extint3_int(void);
void extint4_int(void);
void extint5_int(void);

void extintsvc (void);*/
/****************************************************************************/
/*                                                                          */
/*      function definition                                                 */
/*                                                                          */
/****************************************************************************/
void    PWM_initial(void);
void    main_pwm_120slc20(void);
void    motor_run(void);
void 	ActSpdCal(void);
#pragma	INTERRUPT	pwm_int
void    pwm_int(void);
static  void    pwm_stop(void);
static  void    pwm_kido(void);
static  void    pwm_tujo(void);
static  void    cal_sub_wr_duty(void);

//2005-8-3 22:03
void pwm_tujo_cal(void);
//end of 2005-8-3 22:03

//2005-8-17 9:58
static void pwm_start (void);
//end of 2005-8-17 9:58

//2005-10-20 10:30
static void pwm_bootstrap(void);
//end of 2005-10-20 10:30

/****************************************************************************/
/*                                                                          */
/*      RAM definition                                                      */
/*                                                                          */
/****************************************************************************/
static  SINT_16    stop_mode;
static  SINT_16    kido_cnt;
static  SINT_16    cnt_wr_act;
static  SINT_16    dlt_cnt;
static  SINT_16    reload_stg;
static  SINT_16    reload_cnt;
static  SINT_16    chk_on_cnt;


static UINT_16 ActSpdCnt = 0;
static const UINT_16 MaxActSpd = 1836; /*255*0.6*6*2*/


/***************************************
   for BEMF simulate
***************************************/
#define INIperiod 	(( K_WR_ACT_120SL/ KIDO_Hz )  >> 1)

static const UINT_8 BEMF_ini_level [6] = {0x3f,0x7f,0x5f,0xdf,0x9f,0xbf};

static const UINT_16 BEMF_ini_phase[6][3] = 
{ 	
	{INIperiod/6,                 INIperiod - INIperiod/6, INIperiod/2},
	{INIperiod/2,                 INIperiod/6,                  INIperiod - INIperiod/6},
	{INIperiod - INIperiod/6,INIperiod/2,                  INIperiod/6},
	{INIperiod/6,                 INIperiod - INIperiod/6, INIperiod/2},					
	{INIperiod/2,                 INIperiod/6,                  INIperiod - INIperiod/6},
	{INIperiod - INIperiod/6,INIperiod/2,                  INIperiod/6}
};


/****************************************************************************/
/*                                                                          */
/*      motor_run  subroutine                                                     */
/*                                                                          */
/****************************************************************************/

extern SINT_16    cal_wr_ref(UINT_16 rpm);

extern UINT_16    cal_wract_ref( SINT_16 act_wr);

void    motor_run(void)
{
	SINT_16    w_si16;
	if ( 0 == g_TxdDat[3]) /* Is there any error of machine?*/
	{
		rpm_cmd = (UINT_16)g_RxdDat[0] * 36;
		w_si16 = cal_wr_ref(rpm_cmd);
	
		if((w_si16 >= -KIDO_Hz) && (w_si16 <= KIDO_Hz))
		{
			wr_ref = 0;
		}
		else
		{
		        	wr_ref = w_si16;
		}
	}
	else
	{
		wr_ref = 0;    //stop
     }
	
}

/****************************************************************************/
/*                                                                          */
/*      main subroutine         Just for debug without UART!                 */
/*                                                                          */
/****************************************************************************/
void    main_pwm_120slc20(void)
{
    SINT_16    w_si16;
    static UINT_16 motorsimstep = 0;
    static TIMEBASE rpm3000hold_pretimer ,rpm3000hold_curtimer;
/*    
    //2005-10-26 19:57
    	UINT_16 motorsimstep = 0;
    	TIMEBASE rpm3000hold_pretimer ,rpm3000hold_curtimer;
    //end of 2005-10-26 19:57
*/    
    #include "ioport.h"
    
    	/* to run fan */
   // VAL_OP(1);	/* to open val */
        
   // PWM_initial();	/* 3-ph pwm output initialization*/
    
//    wr_ref = cal_wr_ref(3000);	/* the initial wr command is 3000 rpm */
    
   // while(1)
   // {
    	
    	#include "systimer.h"

		FAN_OP(1);
    	switch (motorsimstep)
    	{
    		case 0 :		      	
		      	if ( 3000 > cal_wract_ref(wr_act) )
		      	{
		      		motorsimstep = 0;
		      	}
		      	else
		      	{
		      		get_curtime (&rpm3000hold_curtimer);
		      		rpm3000hold_pretimer = rpm3000hold_curtimer;
		      		motorsimstep = 1;
		      		
		      	}
		      	
		      	break;
    		case 1:    			
    			if ( SUB(rpm3000hold_curtimer,rpm3000hold_pretimer) <100  ) //10s,600,1min
    			{
    				get_curtime (&rpm3000hold_curtimer);
    				motorsimstep = 1;
    			}
    			else
    			{
    				{
						UINT_16 rpm_temp;
						rpm_temp = (UINT_16)g_RxdDat[0] * 36;

					wr_ref = 315;//1269;//2387;//cal_wr_ref(rpm_temp);//1759;////1269;//2010  ;//(80HZ) 1507--(60hz)--1269(50hz);//2327;//cal_wr_ref(5700);//1825;//cal_wr_ref(4000); //95Hz*60rpm = 5700 //7131
					}
				
    				// to improve the current 2005-11-10 22:41
		      		//if ( pwm_duty < UP_PWM_DUTY)	pwm_duty = UP_PWM_DUTY;
		      		//end of to improve the current 2005-11-10 22:41
    				motorsimstep = 2;
    			}
    			break;
    		case 2:
    			motorsimstep = 2;
    			break;
    		default:
    			wr_ref = 0;
    	}    	  
    //}
}

static UINT_8 ReStaTim = 1;
/****************************************************************************/
/*                                                                          */
/*      initialize                                                          */
/*                                                                          */
/****************************************************************************/
void    PWM_initial(void)
{
    SINT_16    i;
    
    out_mode = STOP_MODE;
    mot_theta = 0;
    out_theta = 0;
    stop_mode = 0;
    wr_ref = 0;
   
    sw_tim = 1;
  
    /* induced voltage signal input setting */
    int4ic = 0x00;                      /* set both edge */
    int3ic = 0x00;
    int5ic = 0x00;
    ifsr = 0xf8;                       
    
    /* three-phase PWM initial setting */
    ictb2 = 1;                          /* one TB2 underflow interrupt */
    prcr  = 0x02;
    invc0 = 0x54 ;                    /* sawtooth modulation mode, no two active at an instance */
    invc1 = (0x20|SET_ACTIVE);          /* invalid short-circuit protection time, active */
    prcr  = 0x00;
    idb0 = 0x3f;                        /* set three-phase output buffer register 0 */
    idb1 = 0x3f;                        /* set three-phase output buffer register 1 */
    prcr  = 0x02;
    tb2sc = 0x00;
    prcr  = 0x00;
    ta1mr = 0x12;                       /* one-shot pulse mode */
    ta2mr = 0x12;                       /* one-shot pulse mode */
    ta4mr = 0x12;                       /* one-shot pulse mode */
    tb2mr = 0x00;                       /* timer mode */
    trgsr &= 0x30;
    trgsr |= 0x45;                      /* trigger select register TB2 trigger */
    tb2 = CARR_CNT_4K - 1;             /* carrier cycle */
    ta4 = ta1 = ta2 = CARR_CNT_4K - ((INI_DUTY_120 * (SINT_32)CARR_CNT_4K) >> Sft_DUTY_120_TIME);    /* initial DUTY */
    
   
    
    tb2ic = 0x06;	                    /* TB2 interrupt enable */
	tabsr |= 0x96;	                    /* tiemr count start */
    prcr  = 0x02;
	invc0 |= 0x08;                      /* output enable */
    prcr  = 0x00;
    
   
	
}

/****************************************************************************/
/*                                                                          */
/*      PWM output interrupt                                                */
/*                                                                          */
/****************************************************************************/


void    pwm_int(void)
{
     
     #ifdef DEBUG_SIM
    TIMEBASETEST1;
    #endif
   
    switch(out_mode)
    {
        case    STOP_MODE:
            pwm_stop();            
            break;
        case   BOOTSTRAP_MODE:
            pwm_bootstrap();
            break;
        case    START_MODE:
            pwm_start();
            break;
        case    KIDO_MODE:
            pwm_kido();
            break;
        case    TUJO_MODE:
            pwm_tujo();
            break;
        default:
            pwm_stop();
            break;	
    }
    #ifdef DEBUG_SIM
    TIMEBASETEST1;
    #endif
}


extern SINT_16    stop_chk(void);
static UINT_8 tb2chg = 0;
static UINT_8 tb2chg1 = 0;
/****************************************************************************/
/*                                                                          */
/*      stop function                                                       */
/*                                                                          */
/****************************************************************************/
static  void    pwm_stop(void)
{
    SINT_16 set_tim;
    /* stop processing */
    STP_TB(1);
     /* initial DUTY */	
    pwm_duty =  MIN_DUTY_120;
    set_tim = CARR_CNT_4K - ((pwm_duty * (SINT_32)CARR_CNT_4K) >> Sft_DUTY_120_TIME);
    if(set_tim >= (CARR_CNT_4K - 1))   set_tim = CARR_CNT_4K - 1;
    if(set_tim <= 1)                    set_tim = 1;
    ta4 = ta1 = ta2 = set_tim; 
       
    idb0 = 0x3f;                        /* set three-phase output buffer register 0 */
    idb1 = 0x3f;                        /* set three-phase output buffer register 1 */
    prcr  = 0x02;
	invc0 |= 0x08;                      /* output enable */
    prcr  = 0x00;

    wr_act = 0;
    ActSpdCnt = 0;
    if(wr_ref == 0) stop_mode = 0;
    
    if(stop_mode == 0)
    {
        if(wr_ref != 0)
        {
              wr_soft.wrd.hi = KIDO_Hz * 2 ;
              wr_act = KIDO_Hz;
			  ActSpdCnt = 150; /* 750rpm/60 * 2 *6  */
              out_mode =  BOOTSTRAP_MODE;//START_MODE;//KIDO_MODE;//
              stop_mode = 1;   
              mot_theta = 0;
	out_theta = 0;
	kido_cnt = 0;
	cnt_wr_act = 0;	
	
	dlt_sum = 0;
	
	cal_cnt = 0;
	
	dlt_FLAG = 0;
	
	commutation_FLAG = 0;
	
	dlt_30deg_cnt = 0;
	
	dlt_30deg_cntmap = 0;
	
	{
		UINT_8 dlt_array_index;
		for ( dlt_array_index = 0; dlt_array_index < 12; dlt_array_index ++ )
		{
			dlt_cnt_array[dlt_array_index] = 0;
		}
	}
	//JUST for TEST reload_cnt SHIFT
	reload_cnt_offset = 4;//0; 
	//end of JUST for TEST reload_cnt SHIFT
        } 
		ReStaTim = 1;      

⌨️ 快捷键说明

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