|
@@ -1,269 +0,0 @@
|
|
|
-/************************************************************************
|
|
|
- Project: Welling Motor Control Paltform
|
|
|
- Filename: adc.h
|
|
|
- Partner Filename: adc.c
|
|
|
- Description: The header file of adc.c
|
|
|
- Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems.
|
|
|
- CPU TYPE : GD32F3x0
|
|
|
-*************************************************************************
|
|
|
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
|
|
|
- All rights reserved.
|
|
|
-*************************************************************************
|
|
|
-*************************************************************************
|
|
|
-Revising History (ECL of this file):
|
|
|
-
|
|
|
-************************************************************************/
|
|
|
-
|
|
|
-/************************************************************************
|
|
|
- Beginning of File, do not put anything above here except notes
|
|
|
- Compiler Directives:
|
|
|
-*************************************************************************/
|
|
|
-#ifndef ADCDRV_H
|
|
|
-#define ADCDRV_H
|
|
|
-
|
|
|
-/************************************************************************
|
|
|
- Compiler Directives
|
|
|
-*************************************************************************/
|
|
|
-#ifdef _ADCDRV_C_
|
|
|
-#define _ADCDRV_EXT
|
|
|
-#else
|
|
|
-#define _ADCDRV_EXT extern
|
|
|
-#endif
|
|
|
-
|
|
|
-#include "typedefine.h"
|
|
|
-/************************************************************************
|
|
|
- Definitions & Macros (#define ...)
|
|
|
-*************************************************************************/
|
|
|
-#define SR_CURRENT_MAX_BAND -147 // 0.01A
|
|
|
-#define SR_CURRENT_MIN_BAND -4000 // 0.01A
|
|
|
-/************************************************************************
|
|
|
- TypeDefs & Structure defines (N/A)
|
|
|
-*************************************************************************/
|
|
|
-typedef struct
|
|
|
-{
|
|
|
- SWORD swIaPu; // Q14, Phase A current value
|
|
|
- SWORD swIbPu; // Q14, Phase B current value
|
|
|
- SWORD swIcPu; // Q14, Phase C current value
|
|
|
- SWORD swSampIaPu; // Q14, Phase A current sampling value
|
|
|
- SWORD swSampIbPu; // Q14, Phase B current sampling value
|
|
|
- SWORD swSampIcPu; // Q14, Phase C current sampling value
|
|
|
- UWORD uwIaAbsPu; // Q14, Phase A current absolute value
|
|
|
- UWORD uwIbAbsPu; // Q14, Phase B current absolute value
|
|
|
- UWORD uwIcAbsPu; // Q14, Phase C current absolute value
|
|
|
- UWORD uwIpeakPu; // Q14, Max value of phase current
|
|
|
-
|
|
|
- UWORD uwIaAvgPu; // Ia register value
|
|
|
- UWORD uwIbAvgPu; // Ib register value
|
|
|
- UWORD uwIcAvgPu; // Ic register value
|
|
|
-
|
|
|
- UWORD uwIaReg; // Ia register value
|
|
|
- UWORD uwIbReg; // Ib register value
|
|
|
- UWORD uwIcReg; // Ic register value
|
|
|
-
|
|
|
- UWORD uwFirstCurREG;
|
|
|
- UWORD uwSecondCurREG;
|
|
|
-
|
|
|
- UWORD uwADCSector;
|
|
|
-
|
|
|
- ULONG ulUaRegSum; // Ua register sum value when calibrate
|
|
|
- ULONG ulUbRegSum; // Ub register sum value when calibrate
|
|
|
- ULONG ulUcRegSum; // Uc register sum value when calibrate
|
|
|
- ULONG ulIdcRegSum; // Idc register sum value when calibrate
|
|
|
-
|
|
|
- ULONG ulIaRegSum; // Ia register value
|
|
|
- ULONG ulIbRegSum; // Ib register value
|
|
|
- ULONG ulIcRegSum; // Ic register value
|
|
|
- ULONG ulIdcAvgRegSum;
|
|
|
-
|
|
|
- UWORD uwADCCalibCt; // Current calib count
|
|
|
- BOOL blADCCalibFlg; // ADC calib flag
|
|
|
-} ADC_DOWN_OUT;
|
|
|
-
|
|
|
-typedef struct
|
|
|
-{
|
|
|
- SWORD uwUAPu;
|
|
|
- SWORD uwUBPu;
|
|
|
- SWORD uwUCPu;
|
|
|
- UWORD uwIbusAvgPu; // Q14, Ibus Average
|
|
|
- UWORD uwIbusAvgLpfPu; // Q14, Ibus Average after LPF
|
|
|
- UWORD uwVdcPu; // Q14, Vdc
|
|
|
- UWORD uwVdcLpfPu; // Q14, Vdc after LPF
|
|
|
- UWORD uwIbusPu; // Q14, Vdc
|
|
|
- UWORD uwIbusLpfPu; // Q14, Vdc after LPF
|
|
|
- UWORD uwU6VPu; // Q14, 12V power
|
|
|
- UWORD uwU5VPu; // Q14, 5V power
|
|
|
- UWORD uwU12VPu; // Q14, 5V power
|
|
|
- UWORD uwTrottlePu; // Q14, 5V power
|
|
|
- UWORD PCBTempR; // Not Pu 0.1kOhm
|
|
|
- UWORD MotorTempR; // Not Pu 0.1kOhm
|
|
|
- SWORD PCBTemp; // Not Pu, centigrade
|
|
|
- SWORD MotorTemp; // Not Pu, centigrade
|
|
|
- SWORD MosfestTempEst; // Not Pu, centigrade
|
|
|
-
|
|
|
- SWORD swCalibIaPu;
|
|
|
- SWORD swCalibIbPu;
|
|
|
- SWORD swCalibIcPu;
|
|
|
-
|
|
|
-// UWORD uwUAReg;
|
|
|
-// UWORD uwUBReg;
|
|
|
-// UWORD uwUCReg;
|
|
|
- UWORD uwIbusAvgReg; // Ibus Average register value
|
|
|
- UWORD uwVdcReg; // Vdc register value
|
|
|
- UWORD uwU6VReg; // 12 V register value
|
|
|
- UWORD uwU5VReg; // 5 V register value
|
|
|
- UWORD uwU12VReg; // Q14, 5V power
|
|
|
- UWORD uwThrottleReg; // Q14, 5V power
|
|
|
- UWORD PCBTempReg;
|
|
|
- UWORD MotorTempReg;
|
|
|
- UWORD TorqTempReg;
|
|
|
-
|
|
|
- UWORD uwADCCalibCt; // Current calib count
|
|
|
- BOOL blADCCalibFlg; // ADC calib flag
|
|
|
- SWORD swIPMTempCe; // PCB Temp to trig alam
|
|
|
-
|
|
|
- SWORD swSampCapIaPu;
|
|
|
- SWORD swSampCapIbPu;
|
|
|
-} ADC_UP_OUT;
|
|
|
-
|
|
|
-typedef struct
|
|
|
-{
|
|
|
- UWORD uwVdcReg2Pu; // Q24, Coefficient of Vdc register value to pu value
|
|
|
- UWORD uwCurReg2Pu; // Q24, Coefficient of current register value to pu value
|
|
|
- UWORD uwCurIdcReg2Pu; // Q24, Coefficient of Idc current register value to pu value
|
|
|
- UWORD uwCurIdcAvgReg2Pu;
|
|
|
- UWORD uwUabcReg2Pu; // Q24, Coefficient of Ua,Ub,Uc register value to pu value
|
|
|
- UWORD uwU6VReg2Pu; // Q24, Coefficient of Ua,Ub,Uc register value to pu value
|
|
|
- UWORD uwU5VReg2Pu; // Q24, Coefficient of Ua,Ub,Uc register value to pu value
|
|
|
- UWORD uwU12VReg2Pu; // Q24, Coefficient of Ua,Ub,Uc register value to pu value
|
|
|
- UWORD uwCalibcoefIA; // Q10, Coefficient of k = single resistance/Rdson
|
|
|
- UWORD uwCalibcoefIB; // Q10, Coefficient of k = single resistance/Rdson
|
|
|
- UWORD uwCalibcoefMax;
|
|
|
- UWORD uwCalibcoefMin;
|
|
|
-
|
|
|
- UWORD uwIaOffset; // Ia offset value
|
|
|
- UWORD uwIbOffset; // Ib offset value
|
|
|
- UWORD uwIcOffset; // Ib offset value
|
|
|
- UWORD uwUaOffset; // Ua offset value
|
|
|
- UWORD uwUbOffset; // Ub offset value
|
|
|
- UWORD uwUcOffset; // Ub offset value
|
|
|
- UWORD uwIdcOffset; // Idc offset value
|
|
|
- UWORD uwIdcAveOffset; // Idc offset value
|
|
|
-
|
|
|
- SWORD swPCBTempKcof;
|
|
|
- SWORD swMotorTempKcof;
|
|
|
- UWORD uwCalibCoefK;
|
|
|
-
|
|
|
-} ADC_COF;
|
|
|
-
|
|
|
-
|
|
|
-typedef struct
|
|
|
-{
|
|
|
- UWORD Start_Calc;
|
|
|
- UWORD RdsonGainCnt;
|
|
|
- UWORD RdsonGainCnt2;
|
|
|
- UWORD adc_RdsonADCGainMax;
|
|
|
- UWORD adc_RdsonADCGainMin;
|
|
|
- UWORD adc_RdsonADCGainSum2;
|
|
|
- UWORD adc_RdsonADCGainRecord[10];
|
|
|
- UWORD adc_RdsonADCGainSum;
|
|
|
- UWORD uwCalibcoef;
|
|
|
- ULONG GainTemp;
|
|
|
- UBYTE uwCalibcomplete;
|
|
|
-
|
|
|
-} ADC_SUMCOF;
|
|
|
-
|
|
|
-/************************************************************************
|
|
|
-Constant Table
|
|
|
-*************************************************************************/
|
|
|
-
|
|
|
-/************************************************************************
|
|
|
- Exported Variables:
|
|
|
-*************************************************************************/
|
|
|
-#ifdef _ADCDRV_C_
|
|
|
-_ADCDRV_EXT ADC_COF adc_stCof;
|
|
|
-_ADCDRV_EXT ADC_UP_OUT adc_stUpOut;
|
|
|
-_ADCDRV_EXT ADC_DOWN_OUT adc_stDownOut;
|
|
|
-_ADCDRV_EXT ADC_SUMCOF adc_LibSUMA;
|
|
|
-_ADCDRV_EXT ADC_SUMCOF adc_LibSUMB;
|
|
|
-_ADCDRV_EXT ADC_SUMCOF adc_LibSUMC;
|
|
|
-
|
|
|
-//_ADCDRV_EXT UWORD Start_Calc = 0;
|
|
|
-//_ADCDRV_EXT UWORD RdsonGainCnt = 0;
|
|
|
-//_ADCDRV_EXT UWORD RdsonGainCnt2 = 0;
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainMax;
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainMin;
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainSum2;
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainRecord[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainSum = 0;
|
|
|
-_ADCDRV_EXT UWORD adc_uwADDMAPhase1;
|
|
|
-_ADCDRV_EXT UWORD adc_uwADDMAPhase2;
|
|
|
-
|
|
|
-_ADCDRV_EXT UWORD adc_uwRdsonUReg;
|
|
|
-_ADCDRV_EXT UWORD adc_uwRdsonVReg;
|
|
|
-_ADCDRV_EXT UWORD adc_uwRdsonWReg;
|
|
|
-
|
|
|
-_ADCDRV_EXT UWORD adc_uwIaReg;
|
|
|
-_ADCDRV_EXT UWORD adc_uwIbReg;
|
|
|
-#else
|
|
|
-_ADCDRV_EXT ADC_COF adc_stCof;
|
|
|
-_ADCDRV_EXT ADC_UP_OUT adc_stUpOut;
|
|
|
-_ADCDRV_EXT ADC_DOWN_OUT adc_stDownOut;
|
|
|
-_ADCDRV_EXT ADC_SUMCOF adc_LibSUMA;
|
|
|
-_ADCDRV_EXT ADC_SUMCOF adc_LibSUMB;
|
|
|
-_ADCDRV_EXT ADC_SUMCOF adc_LibSUMC;
|
|
|
-
|
|
|
-//_ADCDRV_EXT UWORD Start_Calc;
|
|
|
-//_ADCDRV_EXT UWORD RdsonGainCnt;
|
|
|
-//_ADCDRV_EXT UWORD RdsonGainCnt2;
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainMax;
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainMin;
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainSum2;
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainRecord[10];
|
|
|
-//_ADCDRV_EXT UWORD adc_RdsonADCGainSum;
|
|
|
-_ADCDRV_EXT UWORD adc_uwADDMAPhase1;
|
|
|
-_ADCDRV_EXT UWORD adc_uwADDMAPhase2;
|
|
|
-
|
|
|
-_ADCDRV_EXT UWORD adc_uwRdsonUReg;
|
|
|
-_ADCDRV_EXT UWORD adc_uwRdsonVReg;
|
|
|
-_ADCDRV_EXT UWORD adc_uwRdsonWReg;
|
|
|
-
|
|
|
-_ADCDRV_EXT UWORD adc_uwIaReg;
|
|
|
-_ADCDRV_EXT UWORD adc_uwIbReg;
|
|
|
-
|
|
|
-#endif
|
|
|
-/************************************************************************
|
|
|
- RAM ALLOCATION:
|
|
|
-*************************************************************************/
|
|
|
-
|
|
|
-/************************************************************************
|
|
|
- Exported Function Call Prototypes (N/A)
|
|
|
-*************************************************************************/
|
|
|
-#ifdef _ADCDRV_C_
|
|
|
-_ADCDRV_EXT void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2); // Phase A and B current zero point, other A/D sample value
|
|
|
-_ADCDRV_EXT void adc_voSampleUp(ADC_COF *cof, ADC_UP_OUT *out);
|
|
|
-_ADCDRV_EXT void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out);
|
|
|
-_ADCDRV_EXT void adc_voSampleCoef(ADC_COF *cof);
|
|
|
-_ADCDRV_EXT void adc_voSampleInit(void);
|
|
|
-_ADCDRV_EXT void adc_voSRCalibration(ADC_COF *cof , ADC_SUMCOF *Sum_out);
|
|
|
-#else
|
|
|
-_ADCDRV_EXT void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2); // Phase A and B current zero point, other A/D sample value
|
|
|
-_ADCDRV_EXT void adc_voSampleUp(ADC_COF *cof, ADC_UP_OUT *out);
|
|
|
-_ADCDRV_EXT void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out);
|
|
|
-_ADCDRV_EXT void adc_voSampleCoef(ADC_COF *cof);
|
|
|
-_ADCDRV_EXT void adc_voSampleInit(void);
|
|
|
-_ADCDRV_EXT void adc_voSRCalibration(ADC_COF *cof , ADC_SUMCOF *Sum_out);
|
|
|
-#endif
|
|
|
-
|
|
|
-/************************************************************************
|
|
|
- Flag Define (N/A)
|
|
|
-*************************************************************************/
|
|
|
-
|
|
|
-/***********************************************************************/
|
|
|
-#endif
|
|
|
-/************************************************************************
|
|
|
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
|
|
|
- All rights reserved.
|
|
|
-*************************************************************************
|
|
|
- End of this File (EOF):
|
|
|
- !!!!!!Do not put anything after this part!!!!!!!!!!!
|
|
|
-*************************************************************************/
|