    //320 
    const INT16U Sin[TabNub] =                            
    {
         0x8000,0x8052,0x80a0,0x80e3,0x8116,0x8135,0x8140,0x8135,0x8116,0x80e3,0x80a0,0x8052,
         0x0000,0x0052,0x00a0,0x00e3,0x0116,0x0135,0x0140,0x0135,0x0116,0x00e3,0x00a0,0x0052,
    };
    
    const INT16U Cos[TabNub] =                            
    {
         0x8140,0x8135,0x8116,0x80e3,0x80a0,0x8052,0x0000,0x0052,0x00a0,0x00e3,0x0116,0x0135,
         0x0140,0x0135,0x0116,0x00e3,0x00a0,0x0052,0x8000,0x8052,0x80a0,0x80e3,0x8116,0x8135
    };
    //355 
    const INT16U Sin[TabNub] =                            
    {
         0x8000,0x805b,0x80b1,0x80fb,0x8133,0x8156,0x8163,0x8156,0x8133,0x80fb,0x80b1,0x805b,
         0x0000,0x005b,0x00b1,0x00fb,0x0133,0x0156,0x0163,0x0156,0x0133,0x00fb,0x00b1,0x005b,
    };
    
    const INT16U Cos[TabNub] =                            
    {
         0x8163,0x8156,0x8133,0x80fb,0x80b1,0x805b,0x0000,0x005b,0x00b1,0x00fb,0x0133,0x0156,
         0x0163,0x0156,0x0133,0x00fb,0x00b1,0x005b,0x8000,0x805b,0x80b1,0x80fb,0x8133,0x8156
    }; 
    
#define GLOBALS_API_TPM
#include "../App_Headers/includes.h"


/*-------------------------------------------------------------------------
* Function Name  : Api_Timer0_Init
* Description    : 定时器0初始化
* Input          : 
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
void Api_Timer0_Init(INT8U TPM_DIV)
{
      
    TIM0_TSCR1_TSWAI = !WaitRun; //timer 0 在MCU等待模式下不能运行
    TIM0_TSCR1_TSFRZ = Enable;   //timer 0 计数器在冻结模式下禁止运行
    TIM0_TSCR1_TFFCA = Disable;  //正常清除标志位
    TIM0_TSCR1_PRNT  = Disable;  // 
    TIM0_TSCR2_PR    = TPM_DIV;  //Bus Clock / X
    TIM0_TSCR2_TCRE  = Disable;
    TIM0_TTOV        = Disable;
   
    TIM0_TCTL1 = Disable;        //禁止输出比较功能
    TIM0_TCTL2 = Disable;
    
    TIM0_TFLG2_TOF   = ClearFlag;
    TIM0_TSCR1_TEN   = Enable;   //使能timer 0 正常功能
    TIM0_TSCR2_TOI   = Enable;   //溢出中断使能
      
    TIM0_PACTL_PAEN  = Disable;
    TIM0_TIOS_IOS4   = 0;     //设置相应的通道为输入捕捉或是输出比较   0:输入捕捉
    TIM0_TCTL3_EDG4A = 1;        //设置捕捉边沿为上升
    TIM0_TCTL3_EDG4B = 0;
    TIM0_TCTL4       = null;
    
    TIM0_OCPD        = 0xFF;     //禁止输出比较
    TIM0_TC4         = null;   
    TIM0_TFLG1_C4F   = 1;       //清除中断标志
    TIM0_TIE_C4I     = 1;       //使能输入捕捉中断
    TIM0_PACTL       = Disable;    
}
/*-------------------------------------------------------------------------
* Function Name  : Api_Timer1_Init
* Description    : 定时器1初始化
* Input          : 
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
void Api_Timer1_Init(INT8U TPM_DIV)
{
    TIM1_TSCR1_TSWAI = !WaitRun;  //timer 0 在MCU等待模式下不能运行
    TIM1_TSCR1_TSFRZ = Enable;    //timer 0 计数器在冻结模式下禁止运行
    TIM1_TSCR1_TFFCA = Disable;   //正常清除标志位
    TIM1_TSCR1_PRNT  = Disable;   // 
    TIM1_TSCR2_PR    = TPM_DIV;   //Bus Clock / X
    TIM1_TSCR2_TCRE  = Disable;
    TIM1_TTOV        = Disable;
   
    TIM1_TCTL1 = Disable;        //禁止输出比较功能
    TIM1_TCTL2 = Disable;
    
    TIM1_TFLG2_TOF   = ClearFlag;
    TIM1_TSCR1_TEN   = Enable;   //使能timer 0 正常功能
    TIM1_TSCR2_TOI   = Enable;   //溢出中断使能
      
    TIM1_PACTL_PAEN  = Disable;
    TIM1_TIOS_IOS7   = 0;     //设置相应的通道为输入捕捉或是输出比较   0:输入捕捉
    TIM1_TCTL3_EDG7A = 1;        //设置捕捉边沿为上升
    TIM1_TCTL3_EDG7B = 0;
    TIM1_TCTL4       = null;
    
    TIM1_OCPD        = 0xFF;     //禁止输出比较
    TIM1_TC7         = null;   
    TIM1_TFLG1_C7F   = 1;       //清除中断标志
    TIM1_TIE_C7I     = 1;       //使能输入捕捉中断
    TIM1_PACTL       = Disable;   
}
/*-------------------------------------------------------------------------
* Function Name  : Api_Timer0_isr
* Description    : 定时器中断
* Input          : None
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
interrupt void Api_Timer0_isr(void)
{

    CurRevCnt.dw.d16H++;
    if(InitEvt.InitRevTime < TT_30ms)
    {
        InitEvt.InitRevTime ++;
    }  
    TIM0_TFLG2_TOF = ClearFlag;  //清除中断标志位
}
/*-------------------------------------------------------------------------
* Function Name  : Api_Timer1_isr
* Description    : 定时器中断
* Input          : None
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
interrupt void Api_Timer1_isr(void)
{
    if(pBeep->Prio != Disable)
    {
        if(pBeep->BeepTime < TT_6s)
        {
            pBeep->BeepTime++;
        }
    }
    
    CurVehCnt.dw.d16H++; 
    if(InitEvt.InitVehTime < TT_30ms)
    {
        InitEvt.InitVehTime ++;
    }      
    TIM1_TFLG2_TOF = ClearFlag;  //清除中断标志位
}
/*-------------------------------------------------------------------------
* Function Name  : Api_RevCap_isr
* Description    : 转速捕捉中断
* Input          : None
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
interrupt void Api_RevCap_isr(void)
{
    CurRevCnt.dw.d16L = TIM0_TC4;
    
    if((TIM0_TCTL3_EDG4B == 0)&&(TIM0_TCTL3_EDG4A == 1))
    {
        if(CurRevCnt.dw32 > OldRevCnt.dw32)
        {
            RevFre.CyclL = CurRevCnt.dw32 - OldRevCnt.dw32;                     
        }       
        if(RevFre.CyclH < RevFreLimit)
        {
            RevFre.CyclH = null;
        }
        TIM0_TCTL3_EDG4B = 1;
        TIM0_TCTL3_EDG4A = 0;
    }
    else if((TIM0_TCTL3_EDG4B == 1)&&(TIM0_TCTL3_EDG4A == 0))
    {
        if(CurRevCnt.dw32 > OldRevCnt.dw32)
        {
            RevFre.CyclH = CurRevCnt.dw32 - OldRevCnt.dw32;          
        }
        if(RevFre.CyclL < RevFreLimit)
        {
            RevFre.CyclL = null;
        }        
        TIM0_TCTL3_EDG4B = 0;
        TIM0_TCTL3_EDG4A = 1;
    }
    OldRevCnt.dw32 = CurRevCnt.dw32;
    TIM0_TFLG1_C4F = ClearFlag;
}
/*-------------------------------------------------------------------------
* Function Name  : Api_VehCap_isr
* Description    : 转速捕捉中断
* Input          : None
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
interrupt void Api_VehCap_isr(void)
{
    CurVehCnt.dw.d16L = TIM1_TC7;
    
    if((TIM1_TCTL3_EDG7B == 0)&&(TIM1_TCTL3_EDG7A == 1))
    {
        if(CurVehCnt.dw32 > OldVehCnt.dw32)
        {
            VehFre.CyclL = CurVehCnt.dw32 - OldVehCnt.dw32;           
        }
        if(VehFre.CyclH < VehFreLimit)
        {
            VehFre.CyclH = null;
        }
        TIM1_TCTL3_EDG7B = 1;
        TIM1_TCTL3_EDG7A = 0;
    }
    else if((TIM1_TCTL3_EDG7B == 1)&&(TIM1_TCTL3_EDG7A == 0)) 
    {
        if(CurVehCnt.dw32 > OldVehCnt.dw32)
        {
            VehFre.CyclH = CurVehCnt.dw32 - OldVehCnt.dw32;  
            if(VehFre.CyclH > VehFreLimit)
            {                                                   
                AccPulse++;
            }                                   
        }
        if(VehFre.CyclL < VehFreLimit)
        {
            VehFre.CyclL = null;
        }             
        TIM1_TCTL3_EDG7B = 0;
        TIM1_TCTL3_EDG7A = 1;
    }
    OldVehCnt.dw32 = CurVehCnt.dw32;
    TIM1_TFLG1_C7F = ClearFlag;
}


    /*
    if((RevFre.CyclL > RevFreLimit)&&(RevFre.CyclH > RevFreLimit))
    {                  
        if((RevFre.CyclH/RevFre.CyclL <= 2)&&(RevFre.CyclL <= RevFre.CyclH)) 
        {
            RevFre.Cycl = RevFre.CyclH + RevFre.CyclL;
        } 
        else if((RevFre.CyclL/RevFre.CyclH <= 2)&&(RevFre.CyclH < RevFre.CyclL)) 
        {
            RevFre.Cycl = RevFre.CyclH + RevFre.CyclL;
        } 
        else
        {
            InitEvt.InitRevTime = null;
        }
        RevFre.CyclH = null;
        RevFre.CyclL = null;
    }                          
    if((VehFre.CyclL > VehFreLimit)&&(VehFre.CyclH > VehFreLimit))
    {                  
        if((VehFre.CyclH/VehFre.CyclL == 1)&&(VehFre.CyclL <= VehFre.CyclH)) 
        {
            VehFre.Cycl = VehFre.CyclH + VehFre.CyclL;
        } 
        else if((VehFre.CyclL/VehFre.CyclH == 1)&&(VehFre.CyclH < VehFre.CyclL)) 
        {
            VehFre.Cycl = VehFre.CyclH + VehFre.CyclL;
        } 
        else
        {
            InitEvt.InitVehTime = null;
            VehFre.Frequency = VehFre.OldFrequency;
        }                                   
        VehFre.CyclH = null;
        VehFre.CyclL = null;
    }                           
    */  

    