#ifndef _VID29_H_
#define _VID29_H_

#include "stdint.h"
#include "Motor_Controller.h"

/******************************************************************************
����������Բ���
******************************************************************************/
#define   STEPPER_MOTOR_TOTAL_PHASE         24        //ÿһ΢����Ӧת����ת15��,ת����תһ�ܹ�24΢��
#define   STEPPER_MOTOR_STEP_PER_10DEG      120       //������ת��ÿ10�ȶ�Ӧ120΢��
#define   STEPPER_MOTOR_SPEED_MAX           6000      //������ת��,��λ:΢��/��
#define   STEPPER_MOTOR_SPEED_MIN           10        //�����Сת��,��λ:΢��/��
#define   STEPPER_MOTOR_ACC_MAX             50        //�����ٶ�,�������Ƽ��ٶȷ�Χ

/******************************************************************************
�������Ӧ�ò���
******************************************************************************/
/*=============================================================================
���棺Ӧ�ò������������ڶ�Ӧ�����Բ�����Χ��
=============================================================================*/
#define   STEPPER_MOTOR_DIR_SWITCH_SPEED    120       //��������ת��,���ڴ�ת�ٵ���ſ����л���ת����,��λ:΢��/��
#define   STEPPER_MOTOR_CAL_SPEED_MIN       360       //�����СУ׼�ٶ�,У��ģʽʱ����Բ����ڴ��ٶ���ת,��λ:΢��/��
#define   STEPPER_MOTOR_FULL_RST_SPEED      5000      //�����Ƕȹ����ٶ�,��λ:΢��/��
#define   STEPPER_MOTOR_FINE_RST_SPEED      720       //���С�Ƕȹ����ٶ�,��λ:΢��/��
#define   STEPPER_MOTOR_SHDN_RST_SPEED      4320      //����ϵ�����ٶ�,��λ:΢��/��

#define   STEPPER_MOTOR_BRAKE_ACC           50        //����ƶ����ٶ�
#define   STEPPER_MOTOR_FULL_RST_ACC        30        //�����Ƕȹ�����ٶ�
#define   STEPPER_MOTOR_FINE_RST_ACC        10        //���С�Ƕȹ�����ٶ�
#define   STEPPER_MOTOR_SHDN_RST_ACC        5        //����ϵ������ٶ�

#define   STEPPER_MOTOR_DAMPING_FACTOR      2         //�������ϵ��,����ϵ��Խ��,�������Խ��

/******************************************************************************
����������ص���
******************************************************************************/
/*=============================================================================
���棺������������ý��п��ܵ��²������������������
      ��������ʱ��Ҫ����ͬ�������������Ӧ�ò���
=============================================================================*/
#define   STEPPER_MOTOR_MOMENT_FACTOR       75       //���ڷ�ΧΪ0 - 100(��Ӧ0% - 100%)

/******************************************************************************
����������
******************************************************************************/
static const uint16_t StepperMotorCosDutyCycleTable[STEPPER_MOTOR_TOTAL_PHASE]  =
{
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)100 / (uint32_t)10000) | 0x8000,
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000) | 0x8000,  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)0   / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000),   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000),  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000),   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)100 / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000),  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)0   / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000) | 0x8000,   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000) | 0x8000,  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000) | 0x8000,    
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000) | 0x8000,    
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000) | 0x8000,  
};

static const uint16_t StepperMotorSinDutyCycleTable[STEPPER_MOTOR_TOTAL_PHASE]  =
{
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)0   / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000),   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000),  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000),   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)100 / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000),  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000),
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)0   / (uint32_t)10000), 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000) | 0x8000,   
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000) | 0x8000,  
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000) | 0x8000,    
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000) | 0x8000,    
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000) | 0x8000,
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)100 / (uint32_t)10000) | 0x8000,
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)96  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)87  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)71  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)50  / (uint32_t)10000) | 0x8000, 
  (uint16_t)((uint32_t)MOTOR_CONTROLLER_PERIOD * (uint32_t)STEPPER_MOTOR_MOMENT_FACTOR * (uint32_t)26  / (uint32_t)10000) | 0x8000,
};

#endif