164 lines
4.9 KiB
C
164 lines
4.9 KiB
C
|
|
#include "main.h"
|
|||
|
|
|
|||
|
|
//LED<45><44>
|
|||
|
|
#define LED_GPIO_PIN GPIO_PIN_13
|
|||
|
|
#define LED_GPIO_PORT CW_GPIOC
|
|||
|
|
#define LEDON() {GPIO_WritePin(LED_GPIO_PORT,LED_GPIO_PIN,GPIO_Pin_RESET);}
|
|||
|
|
#define LEDOFF() {GPIO_WritePin(LED_GPIO_PORT,LED_GPIO_PIN,GPIO_Pin_SET);}
|
|||
|
|
#define LEDTOG() {GPIO_TogglePin(LED_GPIO_PORT,LED_GPIO_PIN);}
|
|||
|
|
//BKIN<49>˿ڶ<CBBF><DAB6><EFBFBD>
|
|||
|
|
#define BKIN_GPIO_PIN GPIO_PIN_11
|
|||
|
|
#define BKIN_GPIO_PORT CW_GPIOA
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ư<EFBFBD><C6B0><EFBFBD>IO<49><4F><EFBFBD><EFBFBD>
|
|||
|
|
#define DR_GPIO_PIN GPIO_PIN_5
|
|||
|
|
#define DR_GPIO_PORT CW_GPIOB
|
|||
|
|
|
|||
|
|
//ʹ<>ܿ<EFBFBD><DCBF>ƶ˰<C6B6><CBB0><EFBFBD>IO<49><4F><EFBFBD><EFBFBD>
|
|||
|
|
#define EN_GPIO_PIN GPIO_PIN_14
|
|||
|
|
#define EN_GPIO_PORT CW_GPIOC
|
|||
|
|
|
|||
|
|
//<2F><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>IO<49><4F><EFBFBD><EFBFBD>
|
|||
|
|
#define VOUT_EN_GPIO_PIN GPIO_PIN_6
|
|||
|
|
#define VOUT_EN_GPIO_PORT CW_GPIOF
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ָʾ<D6B8><CABE>IO<49><4F><EFBFBD><EFBFBD>
|
|||
|
|
#define LEDDIR_GPIO_PIN GPIO_PIN_12
|
|||
|
|
#define LEDDIR_GPIO_PORT CW_GPIOA
|
|||
|
|
|
|||
|
|
//<2F><>ָͣʾ<D6B8><CABE>IO<49><4F><EFBFBD><EFBFBD>
|
|||
|
|
#define LEDSTSTO_GPIO_PIN GPIO_PIN_11
|
|||
|
|
#define LEDSTSTO_GPIO_PORT CW_GPIOB
|
|||
|
|
|
|||
|
|
|
|||
|
|
//<2F><>·PWM IO<49><4F><EFBFBD><EFBFBD>
|
|||
|
|
#define PWM_AP_PORT (CW_GPIOA)
|
|||
|
|
#define PWM_AP_PIN (GPIO_PIN_8)
|
|||
|
|
#define PWM_AN_PORT (CW_GPIOB)
|
|||
|
|
#define PWM_AN_PIN (GPIO_PIN_13)
|
|||
|
|
|
|||
|
|
#define PWM_BP_PORT (CW_GPIOA)
|
|||
|
|
#define PWM_BP_PIN (GPIO_PIN_9)
|
|||
|
|
#define PWM_BN_PORT (CW_GPIOB)
|
|||
|
|
#define PWM_BN_PIN (GPIO_PIN_14)
|
|||
|
|
|
|||
|
|
#define PWM_CP_PORT (CW_GPIOA)
|
|||
|
|
#define PWM_CP_PIN (GPIO_PIN_10)
|
|||
|
|
#define PWM_CN_PORT (CW_GPIOB)
|
|||
|
|
#define PWM_CN_PIN (GPIO_PIN_15)
|
|||
|
|
|
|||
|
|
|
|||
|
|
#define PWM_AH_OFF GPIO_WritePin(PWM_AP_PORT,PWM_AP_PIN,GPIO_Pin_RESET)
|
|||
|
|
#define PWM_BH_OFF GPIO_WritePin(PWM_BP_PORT,PWM_BP_PIN,GPIO_Pin_RESET)
|
|||
|
|
#define PWM_CH_OFF GPIO_WritePin(PWM_CP_PORT,PWM_CP_PIN,GPIO_Pin_RESET)
|
|||
|
|
|
|||
|
|
#define PWM_AH_ON GPIO_WritePin(PWM_AP_PORT,PWM_AP_PIN,GPIO_Pin_SET)
|
|||
|
|
#define PWM_BH_ON GPIO_WritePin(PWM_BP_PORT,PWM_BP_PIN,GPIO_Pin_SET)
|
|||
|
|
#define PWM_CH_ON GPIO_WritePin(PWM_CP_PORT,PWM_CP_PIN,GPIO_Pin_SET)
|
|||
|
|
|
|||
|
|
//<2F>Ϲܵ<CFB9><DCB5>ƣ<EFBFBD><C6A3>¹ܿ<C2B9><DCBF>ؿ<EFBFBD><D8BF><EFBFBD>, <20>ϸߵ<CFB8>ƽ<EFBFBD>µ͵<C2B5>ƽ
|
|||
|
|
#define PWM_AL_OFF GPIO_WritePin(PWM_AN_PORT,PWM_AN_PIN,GPIO_Pin_RESET)
|
|||
|
|
#define PWM_BL_OFF GPIO_WritePin(PWM_BN_PORT,PWM_BN_PIN,GPIO_Pin_RESET)
|
|||
|
|
#define PWM_CL_OFF GPIO_WritePin(PWM_CN_PORT,PWM_CN_PIN,GPIO_Pin_RESET)
|
|||
|
|
|
|||
|
|
#define PWM_AL_ON GPIO_WritePin(PWM_AN_PORT,PWM_AN_PIN,GPIO_Pin_SET)
|
|||
|
|
#define PWM_BL_ON GPIO_WritePin(PWM_BN_PORT,PWM_BN_PIN,GPIO_Pin_SET)
|
|||
|
|
#define PWM_CL_ON GPIO_WritePin(PWM_CN_PORT,PWM_CN_PIN,GPIO_Pin_SET)
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
//<2F>ز<EFBFBD>Ƶ<EFBFBD><C6B5>20k
|
|||
|
|
#define PWM_PERIOD 2399
|
|||
|
|
// (48000000 / 20000 ) - 1;
|
|||
|
|
#define OnepercentPWM (PWM_PERIOD+1)/100
|
|||
|
|
|
|||
|
|
#define STATESTARTCHECK 0
|
|||
|
|
#define STATESTARTPID 1
|
|||
|
|
#define STATERUNPID 2
|
|||
|
|
#define STATESTOP 3
|
|||
|
|
#define STATEERROR 5
|
|||
|
|
#define STATEERROROVER 6
|
|||
|
|
|
|||
|
|
//<2F><>λ<EFBFBD><CEBB>
|
|||
|
|
#define NMAXVD 2950
|
|||
|
|
#define NMINVD 750
|
|||
|
|
//0.4V~3.2V<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
#define RS (float)0.005
|
|||
|
|
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
#define AP 21
|
|||
|
|
//<2F>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
#define Ikvalue (float)1200/(float)AP/RS
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㳣<EFBFBD><E3B3A3> <20>ڲ<EFBFBD><DAB2>ο<EFBFBD>1.2V
|
|||
|
|
|
|||
|
|
#define NumErr 2
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
//#define VSh 60
|
|||
|
|
//<2F><>ѹֵ<D1B9>趨
|
|||
|
|
#define RV1 1
|
|||
|
|
#define RV2 20
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ѹ֮<D1B9>ȣ<EFBFBD>ΪRV1:(RV1+RV2)
|
|||
|
|
|
|||
|
|
#define Kvvalue (float)1.2/RV1*(RV1+RV2)
|
|||
|
|
|
|||
|
|
|
|||
|
|
extern uint8_t ADC_CR1Array[4] ; // ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ADC<44><43>CR1<52>Ĵ<EFBFBD><C4B4><EFBFBD>ʵ<EFBFBD><CAB5>ADCͨ<43><CDA8><EFBFBD>Զ<EFBFBD><D4B6>л<EFBFBD>
|
|||
|
|
extern uint8_t ADC_Start ;
|
|||
|
|
|
|||
|
|
extern unsigned int TimeCountCompuSpeed,TimeCountTemp,TimeCountkey;
|
|||
|
|
extern unsigned int TimeCountRealSpd,TimeCountPID,TimeCountAvgSpd,TimeCountVI;
|
|||
|
|
|
|||
|
|
extern unsigned char MOTORSTATE;
|
|||
|
|
|
|||
|
|
extern const unsigned int PWM_EN_TAB[6];
|
|||
|
|
extern const unsigned char STEP_TAB[2][6];
|
|||
|
|
|
|||
|
|
extern uint16_t SampleData[4];
|
|||
|
|
|
|||
|
|
extern unsigned char ErrorCode; //<2F><><EFBFBD><EFBFBD>״̬
|
|||
|
|
extern unsigned int Motor_Start_F; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ״̬
|
|||
|
|
extern unsigned int Cur_step; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
extern unsigned char Dir; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
extern unsigned int HALLcount,HALLcount1,HALLcountTemp; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>ٶȺ<D9B6>˲ʱ<CBB2>ٶ<EFBFBD>
|
|||
|
|
extern unsigned int TargS1;//PIDĿ<44><C4BF><EFBFBD>ٶ<EFBFBD>
|
|||
|
|
extern unsigned int RealS1;//ʵʱ˲ʱ<CBB2>ٶ<EFBFBD>
|
|||
|
|
extern unsigned int RealS;//ƽ<><C6BD><EFBFBD>ٶ<EFBFBD>
|
|||
|
|
extern unsigned int SetSpeed;
|
|||
|
|
extern float KKN,KPWMN;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ٶ<EFBFBD>ʱ<EFBFBD><CAB1>б<EFBFBD><D0B1>
|
|||
|
|
|
|||
|
|
extern unsigned int OutPwmValue;//<2F><><EFBFBD><EFBFBD>ռ<EFBFBD>ձ<EFBFBD>ֵ
|
|||
|
|
|
|||
|
|
extern unsigned char ErrCleFlag;
|
|||
|
|
|
|||
|
|
extern unsigned int SpeedD;//
|
|||
|
|
|
|||
|
|
extern unsigned int DIin; //<2F><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>
|
|||
|
|
extern unsigned int CanshuV;//ĸ<>ߵ<EFBFBD>ѹ100mVΪ<56><CEAA>λ
|
|||
|
|
extern unsigned int CanshuI;//ĸ<>ߵ<EFBFBD><DFB5><EFBFBD>mA
|
|||
|
|
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>²<EFBFBD><C2B2><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>籣<EFBFBD><E7B1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
extern unsigned int MPolePairs; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
extern unsigned int MAXSPEED; //<2F>ת<EEB6A8><D7AA>
|
|||
|
|
extern unsigned int CanshuTimeDelay;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>MS
|
|||
|
|
|
|||
|
|
extern unsigned int ISH;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ A
|
|||
|
|
extern unsigned int VSH;//<2F><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>ֵ V
|
|||
|
|
extern unsigned int LSH;//Ƿѹ<C7B7><D1B9><EFBFBD><EFBFBD>ֵ V
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
extern unsigned int PWMMin;//<2F><><EFBFBD><EFBFBD>ռ<EFBFBD>ձ<EFBFBD>
|
|||
|
|
extern unsigned int PWMMax;//<2F><><EFBFBD><EFBFBD>ռ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
extern unsigned int TImeUP;//<2F><><EFBFBD><EFBFBD>Сռ<D0A1>ձȵ<D5B1><C8B5><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>ձȵ<D5B1>ʱ<EFBFBD><CAB1>
|
|||
|
|
//<2F>ٶȱջ<C8B1><D5BB><EFBFBD><EFBFBD><EFBFBD> ʵ<><CAB5><EFBFBD><EFBFBD>С1000<30><30>
|
|||
|
|
extern unsigned int MINSPEED; //<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
|
|||
|
|
extern unsigned int CanshuSTT;//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>MS ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
extern unsigned int SP,SI,SD;
|
|||
|
|
|
|||
|
|
extern unsigned int STEP_last;
|
|||
|
|
extern unsigned int startflag,dirflag;
|
|||
|
|
extern unsigned int LevelSet;
|