Elite change IV curve samplerate to average

This commit is contained in:
105042004
2019-08-23 10:26:50 +08:00
parent 43cb1a278b
commit 72d97ad288
2 changed files with 15 additions and 8 deletions
@@ -679,6 +679,7 @@ static uint16_t SampleRate = 1;
static uint16_t SampleRate_counter = 1;
// record real voltage and real current from DecodeADCValue()
static int16_t avg_number = 1;
static int32_t ADCRealCurrent_avg = 0;
static int32_t ADCRealCurrent = 0;
static int32_t ADCRealVolt = 0;
@@ -725,7 +725,9 @@ static void reset() {
StepTimeCounter = 1;
SampleRate = 1;
SampleRate_counter = 1;
avg_number = 1;
ADCRealCurrent = 0;
ADCRealCurrent_avg = 0;
ADCRealVolt = 0;
LEDPowerON();
@@ -766,7 +768,9 @@ static void Eliteinterrupt() {
StepTimeCounter = 1;
SampleRate = 1;
SampleRate_counter = 1;
avg_number = 1;
ADCRealCurrent = 0;
ADCRealCurrent_avg = 0;
ADCRealVolt = 0;
LEDPowerON();
@@ -805,7 +809,9 @@ static void CleanBuffer() {
Step = 0x9E; // 10 = 0x0A ~= 3.05 mv ~= 3 mv
StepTime = 20; // 0x30 = 2'd48 ~= 2 second, 24 = 0x18
StepTimeCounter = 1;
avg_number = 1;
ADCRealCurrent = 0;
ADCRealCurrent_avg = 0;
ADCRealVolt = 0;
for (int i = 0; i < SPI_LED_SIZE; i++) {
@@ -918,17 +924,17 @@ static void EliteNotifyControl() {
// }
if (SampleRate_counter == SampleRate) {
ADCRealCurrent = ADCRealCurrent / SampleRate;
ADCRealCurrent_avg = (ADCRealCurrent + ADCRealCurrent_avg*(SampleRate - 1)) / SampleRate;
ADCRealCurrent_avg = (ADCRealCurrent + ADCRealCurrent_avg*(avg_number - 1)) / avg_number;
ADCRealCurrent = 0;
}
if (StepTimeCounter == StepTime) {
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent >> 24);
NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent & 0x00FF0000) >> 16);
NotifyCurrent[2] = (uint8_t) ((ADCRealCurrent & 0x0000FF00) >> 8);
NotifyCurrent[3] = (uint8_t) (ADCRealCurrent & 0x000000FF);
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent_avg >> 24);
NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent_avg & 0x00FF0000) >> 16);
NotifyCurrent[2] = (uint8_t) ((ADCRealCurrent_avg & 0x0000FF00) >> 8);
NotifyCurrent[3] = (uint8_t) (ADCRealCurrent_avg & 0x000000FF);
avg_number = 1;
ADCRealCurrent_avg = 0;
ADCRealCurrent = 0;
SendNotify();
}