|
@@ -109,11 +109,11 @@ static void PrepareForLed(void);
|
|
__IO uint16_t ConversionBuffer[ADC_SMPLS];
|
|
__IO uint16_t ConversionBuffer[ADC_SMPLS];
|
|
__IO uint8_t BufferIndex = 0;
|
|
__IO uint8_t BufferIndex = 0;
|
|
__IO uint8_t LedCnt = 0;
|
|
__IO uint8_t LedCnt = 0;
|
|
-static uint16_t Current = 0;
|
|
|
|
-static uint32_t Capacity = 0;
|
|
|
|
|
|
+static float Current = 0.0;
|
|
|
|
+static float Capacity = 0.0;
|
|
static uint8_t LedDigits[3] = {0, 0, 0};
|
|
static uint8_t LedDigits[3] = {0, 0, 0};
|
|
static uint8_t LedPoint = 3;
|
|
static uint8_t LedPoint = 3;
|
|
-static uint16_t SubSecondBfr = 0;
|
|
|
|
|
|
+static float SubSecondBfr = 0.0;
|
|
static uint8_t SubSecondCnt = SUB_SECOND_CNT;
|
|
static uint8_t SubSecondCnt = SUB_SECOND_CNT;
|
|
static uint16_t ADC_ZeroFix = 0;
|
|
static uint16_t ADC_ZeroFix = 0;
|
|
|
|
|
|
@@ -175,7 +175,7 @@ void main(void)
|
|
BufferIndex = 0;
|
|
BufferIndex = 0;
|
|
|
|
|
|
/* Oversampling */
|
|
/* Oversampling */
|
|
- uint32_t tbuf = 0;
|
|
|
|
|
|
+ uint16_t tbuf = 0;
|
|
uint8_t i = 0;
|
|
uint8_t i = 0;
|
|
for(i=0; i<ADC_SMPLS; i++){
|
|
for(i=0; i<ADC_SMPLS; i++){
|
|
tbuf += ConversionBuffer[i];
|
|
tbuf += ConversionBuffer[i];
|
|
@@ -194,26 +194,21 @@ void main(void)
|
|
tbuf -= ADC_ZeroFix;
|
|
tbuf -= ADC_ZeroFix;
|
|
|
|
|
|
tbuf >>= 3; // pre div
|
|
tbuf >>= 3; // pre div
|
|
- tbuf *= 3335; // Vref = Vcc
|
|
|
|
- tbuf = (tbuf + 4096) / 8191; // get ADC input voltage in mV
|
|
|
|
- tbuf *= 1000; // -- for OU divider //get voltage in uV
|
|
|
|
- tbuf = (tbuf + 3147) / 6294; // get voltage from shunt
|
|
|
|
|
|
+ Current = tbuf * 3.335; // Vref = Vcc
|
|
|
|
+ Current /= 8191; // get ADC input voltage in mV
|
|
|
|
+ Current /= 6.29412; // get voltage from shunt
|
|
/* â Current òîê â ìèëèàìïåðàõ */
|
|
/* â Current òîê â ìèëèàìïåðàõ */
|
|
- tbuf *= 1000; // get voltage in uV
|
|
|
|
- Current = (tbuf + 25) / 50; // shunt resistance in mOhms
|
|
|
|
|
|
+ Current /= 0.05; // shunt resistance in mOhms
|
|
|
|
|
|
SubSecondBfr += Current;
|
|
SubSecondBfr += Current;
|
|
|
|
|
|
- } else {
|
|
|
|
- tbuf = 0;
|
|
|
|
- Current = 0;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
SubSecondCnt --;
|
|
SubSecondCnt --;
|
|
|
|
|
|
if(SubSecondCnt == 0){
|
|
if(SubSecondCnt == 0){
|
|
Capacity += ( (SubSecondBfr + (SUB_SECOND_CNT/2)) / SUB_SECOND_CNT );
|
|
Capacity += ( (SubSecondBfr + (SUB_SECOND_CNT/2)) / SUB_SECOND_CNT );
|
|
- SubSecondBfr = 0;
|
|
|
|
|
|
+ SubSecondBfr = 0.0;
|
|
SubSecondCnt = SUB_SECOND_CNT;
|
|
SubSecondCnt = SUB_SECOND_CNT;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -262,7 +257,7 @@ static void ADC_CorrectZero(void) {
|
|
|
|
|
|
/** Prepare current value for output ot led */
|
|
/** Prepare current value for output ot led */
|
|
static void PrepareForLed(void) {
|
|
static void PrepareForLed(void) {
|
|
- uint16_t value;
|
|
|
|
|
|
+ float value;
|
|
|
|
|
|
if((BTN_PORT->IDR & BTN_PINS) == 0){
|
|
if((BTN_PORT->IDR & BTN_PINS) == 0){
|
|
value = Capacity / 3600;
|
|
value = Capacity / 3600;
|
|
@@ -270,27 +265,55 @@ static void PrepareForLed(void) {
|
|
value = Current;
|
|
value = Current;
|
|
}
|
|
}
|
|
|
|
|
|
- if(value > 9999){
|
|
|
|
|
|
+ LedDigits[0] = 0;
|
|
|
|
+ LedDigits[1] = 0;
|
|
|
|
+ LedDigits[2] = 0;
|
|
|
|
+
|
|
|
|
+ if(value >= 10.0){
|
|
/* XX.X Amper */
|
|
/* XX.X Amper */
|
|
LedPoint = 1;
|
|
LedPoint = 1;
|
|
- LedDigits[0] = value / 10000;
|
|
|
|
- value = value % 10000;
|
|
|
|
- LedDigits[1] = value / 1000;
|
|
|
|
- LedDigits[2] = (value % 1000) / 100;
|
|
|
|
- } else if(value > 999){
|
|
|
|
|
|
+ while(value >= 10.0){
|
|
|
|
+ LedDigits[0] ++;
|
|
|
|
+ value -= 10.0;
|
|
|
|
+ }
|
|
|
|
+ while(value >= 1.0){
|
|
|
|
+ LedDigits[1] ++;
|
|
|
|
+ value -= 1.0;
|
|
|
|
+ }
|
|
|
|
+ while(value >= 0.1){
|
|
|
|
+ LedDigits[2] ++;
|
|
|
|
+ value -= 0.1;
|
|
|
|
+ }
|
|
|
|
+ } else if(value >= 1.0){
|
|
/* X.XX Amper */
|
|
/* X.XX Amper */
|
|
LedPoint = 0;
|
|
LedPoint = 0;
|
|
- LedDigits[0] = value / 1000;
|
|
|
|
- value = value % 1000;
|
|
|
|
- LedDigits[1] = value / 100;
|
|
|
|
- LedDigits[2] = (value % 100) / 10;
|
|
|
|
|
|
+ while(value >= 1.0){
|
|
|
|
+ LedDigits[0] ++;
|
|
|
|
+ value -= 1.0;
|
|
|
|
+ }
|
|
|
|
+ while(value >= 0.1){
|
|
|
|
+ LedDigits[1] ++;
|
|
|
|
+ value -= 0.1;
|
|
|
|
+ }
|
|
|
|
+ while(value >= 0.01){
|
|
|
|
+ LedDigits[2] ++;
|
|
|
|
+ value -= 0.01;
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
/* XXX mili Amper */
|
|
/* XXX mili Amper */
|
|
LedPoint = 3;
|
|
LedPoint = 3;
|
|
- LedDigits[0] = value / 100;
|
|
|
|
- value = value % 100;
|
|
|
|
- LedDigits[1] = value / 10;
|
|
|
|
- LedDigits[2] = value % 10;
|
|
|
|
|
|
+ while(value >= 0.1){
|
|
|
|
+ LedDigits[0] ++;
|
|
|
|
+ value -= 0.1;
|
|
|
|
+ }
|
|
|
|
+ while(value >= 0.01){
|
|
|
|
+ LedDigits[1] ++;
|
|
|
|
+ value -= 0.01;
|
|
|
|
+ }
|
|
|
|
+ while(value >= 0.001){
|
|
|
|
+ LedDigits[2] ++;
|
|
|
|
+ value -= 0.001;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|