Compare commits

...

7 Commits

Author SHA1 Message Date
YiChin 0259d3ec61 TODO: delete auto gain 2019-11-11 19:11:12 +08:00
YiChin 8bc43f1bb0 [CC] This is a stable version 2019-11-11 11:06:55 +08:00
weiting2 50acc23eb1 [CC mode] read Vin 2019-11-11 10:52:21 +08:00
YiChin a26bad68a6 [CC] everything well, return Vin works ^^ 2019-11-11 10:46:13 +08:00
weiting2 f5796e8ac5 [CC mode] read Vin 2019-11-11 10:26:13 +08:00
YiChin c862e6790f [CC] everything well, NEED RETURN VIN 2019-11-08 17:38:55 +08:00
YiChin fb43ec6ac3 [CC] Vin + V_(Iin-GND) = battery V 2019-11-08 16:09:09 +08:00
3 changed files with 59 additions and 63 deletions
@@ -6,7 +6,7 @@ static void CCModeDACControl(int32_t IUC_Measure_Difference);
static int32_t CCModeReadCurrent(CCMode *CC){
static bool IVSwitch = false;
static uint8_t VoltCurrentSwitch = 0;
CCModeDACEnable = 1; // This flag will control DAC working
@@ -14,8 +14,15 @@ static int32_t CCModeReadCurrent(CCMode *CC){
CCCurrent2IUC(CC);
// decode ADC value and put it into notify buffer
if(IVSwitch){
IVSwitch = false;
// Use 9-th measure value as real-measure value
// because some value in the begin are garbage
if(VoltCurrentSwitch < 9){
ReadCurrent(spi_ADC_rxbuf);
VoltCurrentSwitch ++;
}
else if(VoltCurrentSwitch == 9){
// read current
if(INSTRUCTION.AutoGainEnable){
CC->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
}
@@ -23,21 +30,38 @@ static int32_t CCModeReadCurrent(CCMode *CC){
ReadCurrent(spi_ADC_rxbuf);
CC->_MeasureData = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
VoltCurrentSwitch ++;
}
else if(VoltCurrentSwitch <18){
// read volt
ReadVolt(spi_ADC_rxbuf);
VoltCurrentSwitch++;
}
else if(VoltCurrentSwitch == 18){
// read volt
ReadVolt(spi_ADC_rxbuf);
CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
// if Iin connect to battery +, Vout connect to battery -
// CC->BatteryV = CC->BatteryV - (CC->value - CC_ZERO_POINT)*10/1e5; // I_set * 10R = V_Iin2GND (mA * ohm)
// if Iin connect to battery -, Vout connect to battery +
CC->BatteryV = CC->BatteryV + (CC->value - CC_ZERO_POINT)*10/1e5; // I_set * 10R = V_Iin2GND (mA * ohm)
VoltCurrentSwitch++;
}
else{
IVSwitch = true;
/** read battery voltage **/
// read ADC volt
ReadVolt(spi_ADC_rxbuf);
// decode ADC value and put it into notify buffer
CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
VoltCurrentSwitch = 0;
}
NotifyCurrent[0] = (uint8_t) (CC->_MeasureData >> 24);
NotifyCurrent[1] = (uint8_t) ((CC->_MeasureData & 0x00FF0000) >> 16);
NotifyCurrent[2] = (uint8_t) ((CC->_MeasureData & 0x0000FF00) >> 8);
NotifyCurrent[3] = (uint8_t) (CC->_MeasureData & 0x000000FF);
// /** read battery voltage **/
// // read ADC volt
// ReadVolt(spi_ADC_rxbuf);
//
// // decode ADC value and put it into notify buffer
// CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
//
NotifyVolt[0] = (uint8_t) (CC->BatteryV >> 24);
NotifyVolt[1] = (uint8_t) ((CC->BatteryV & 0x00FF0000) >> 16);
NotifyVolt[2] = (uint8_t) ((CC->BatteryV & 0x0000FF00) >> 8);
@@ -59,24 +83,29 @@ static int32_t CCModeVoltOut(CCMode *CC){
MeasureCurrent = CC->_MeasureData;
CCModeDACControl(IUCCurrent - MeasureCurrent);
// NotifyCurrent[0] = (uint8_t) (IUCCurrent >> 24);
// NotifyCurrent[1] = (uint8_t) ((IUCCurrent & 0x00FF0000) >> 16);
// NotifyCurrent[2] = (uint8_t) ((IUCCurrent & 0x0000FF00) >> 8);
// NotifyCurrent[3] = (uint8_t) (IUCCurrent & 0x000000FF);
//
// NotifyImpedance[0] = (uint8_t) (MeasureCurrent >> 24);
// NotifyImpedance[1] = (uint8_t) ((MeasureCurrent & 0x00FF0000) >> 16);
// NotifyImpedance[2] = (uint8_t) ((MeasureCurrent & 0x0000FF00) >> 8);
// NotifyImpedance[3] = (uint8_t) (MeasureCurrent & 0x000000FF);
NotifyCurrent[0] = (uint8_t) (IUCCurrent >> 24);
NotifyCurrent[1] = (uint8_t) ((IUCCurrent & 0x00FF0000) >> 16);
NotifyCurrent[2] = (uint8_t) ((IUCCurrent & 0x0000FF00) >> 8);
NotifyCurrent[3] = (uint8_t) (IUCCurrent & 0x000000FF);
NotifyImpedance[0] = (uint8_t) (MeasureCurrent >> 24);
NotifyImpedance[1] = (uint8_t) ((MeasureCurrent & 0x00FF0000) >> 16);
NotifyImpedance[2] = (uint8_t) ((MeasureCurrent & 0x0000FF00) >> 8);
NotifyImpedance[3] = (uint8_t) (MeasureCurrent & 0x000000FF);
// DACCode2Real2Notify(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
// if(IUCCurrent > 1000){
// ADCRealVolt = 2*(INSTRUCTION.VoltConstant - 25000)/10 - IUCCurrent*200/1e6;
// }
// else{
// ADCRealVolt = 2*(INSTRUCTION.VoltConstant - 25000)/10 - IUCCurrent*200/1e7;
// CC->BatteryV = 2*(INSTRUCTION.VoltConstant - 25000)/10 - IUCCurrent*200/1e7;
// }
// NotifyVolt[0] = (uint8_t) (CC->BatteryV >> 24);
// NotifyVolt[1] = (uint8_t) ((CC->BatteryV & 0x00FF0000) >> 16);
// NotifyVolt[2] = (uint8_t) ((CC->BatteryV & 0x0000FF00) >> 8);
// NotifyVolt[3] = (uint8_t) (CC->BatteryV & 0x000000FF);
CCModeDACEnable = 0;
return MeasureCurrent;
}
@@ -109,11 +138,6 @@ static void CCModeDACControl(int32_t IUC_Measure_Difference){
INSTRUCTION.VoltConstant = INSTRUCTION.VoltConstant + step;
}
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
// NotifyCurrent[0] = (uint8_t) ( step >> 24);
// NotifyCurrent[1] = (uint8_t) (( step & 0x00FF0000) >> 16);
// NotifyCurrent[2] = (uint8_t) (( step & 0x0000FF00) >> 8);
// NotifyCurrent[3] = (uint8_t) ( step & 0x000000FF);
}
// XXX : should we reset DAC output after STOP?
@@ -29,7 +29,7 @@
*/
#define BOARD_EARTH
#define BOARD_MERCURY
typedef struct _formula{
@@ -141,8 +141,8 @@ struct _correction{
.ADC_current[0].coeff = 30022512,
.ADC_current[0].offset = -729552647201,
.ADC_current[1].coeff = 658398533,
.ADC_current[1].offset = -16001498741131,
.ADC_current[1].coeff = 658398533000,
.ADC_current[1].offset = -16001498741131000,
.ADC_current[2].coeff = 30908351000,
.ADC_current[2].offset = -746548614824000,
@@ -172,8 +172,8 @@ struct _correction{
.ADC_current[1].coeff = 652738209,
.ADC_current[1].offset = -15767733896990,
.ADC_current[2].coeff = 30959456,
.ADC_current[2].offset = -748026885843,
.ADC_current[2].coeff = 30959456000,
.ADC_current[2].offset = -748026885843000,
.DAC2RealV.coeff = (-18880478),
.DAC2RealV.offset = 629012735316,
@@ -507,34 +507,6 @@ struct _correction{
};
#endif
#ifdef BOARD_WATER_STAR
{
.ADC_volt.coeff = (-6259808),
.ADC_volt.offset = 102009860128,
.ADC_current[0].coeff = 31335917,
.ADC_current[0].offset = (-511426612252),
.ADC_current[1].coeff = 658172815,
.ADC_current[1].offset = (-10738251896209),
.ADC_current[2].coeff = 31482687000,
.ADC_current[2].offset = (-513650531545000),
.DAC2RealV.coeff = (-10548297),
.DAC2RealV.offset = 562611756757,
.Usercode2DAC.coeff = (-10500262),
.Usercode2DAC.offset = 559630236100,
.Gain0Boundary[0] = 0x5D96,
.Gain0Boundary[1] = 0x5DD9,
.Gain1Boundary[0] = 0x57CD,
.Gain1Boundary[1] = 0x639F
};
#endif
#ifdef BOARD_MARS
{
.ADC_volt.coeff = (-6270623),
@@ -879,7 +879,7 @@ static void update_ZM_instruction(uint8 *ins) {
case CONSTANT_CURRENT:{
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.SampleRate = 10;
INSTRUCTION.SampleRate = 6;
INSTRUCTION.ConstantCurrent = ( (uint32_t) (ins[3])<<24 | (uint32_t) (ins[4])<<16 | (uint32_t) (ins[5])<<8 | (uint32_t) (ins[6]) );
INSTRUCTION.NotifyRate = 1000;
// GetInstructionParameter(ins+2);