HelTecAutomation / CubeCell-Arduino

Heltec CubeCell Series (based on ASR6501, ASR6502 chip) Arduino support.
248 stars 137 forks source link

ADC battery value drops after a period on HTCC-AB02A #237

Open jezdd opened 2 years ago

jezdd commented 2 years ago

Added and fixed some function to Arduino format, such as: int analogRead(pin) -- return adc level 0 ~ 4096; float analogReadmV(pin) -- return adc voltage in mV; The ASR650x series ADC input pin range is 0 ~ 2400 mV; The ASR6601 series ADC input pin range is 100 ~ 1100 mV.

Something very frustrating happening around analogueRead/analogueReadmv on ADC on HTCC-AB02A - it works great for a short period but then drops in value for no apparent reason, starts off very accurate and then drops but about 0.5v - - something has introduced a bug, you wont spot it if your run for 5 mins. We are running a wake up every 30 seconds to sample temp and battery etc, the values are perfect except the batter will just drop off after a random period of time.

This is when under battery power, all works fine and then for no apparent reason the voltage drops by about 0.5v and continues and the new offset - if the device is reset the ADC reading restore and the process starts again.

USB powered device reading don't have the issue, only when on the battery - we have tested using precision power supply too, same result.

Why would ADC battery reading drop after say 30min? (the timing seems random but always within the first hour)

Please note the actual battery voltage has not dropped, its the output from analogueRead/analogueReadmv that is false.

Mr-HaleYa commented 1 year ago

post your code, please

jezdd commented 1 year ago

Will do, let me pull it together

jezdd commented 1 year ago

Battery ADC results do not return true values after a period, works for a short while but then the results drop by about 0.5v, every now and again it given an accurate result but then goes back to the lower voltage.

This issues only shows up when its run on battery, not via USB - to reproduce you need to run on battery and send data via Lorawan to say TTN, you need to leave it running for some time.

Tested on several HTCC-AB02A, I am working on latest PlatformIO release.

Payload code below, all the rest is standard from Lorawan examples:

/ Prepares the payload of the frame / static void prepareTxFrame( uint8_t port ) { pinMode(VBAT_ADC_CTL,OUTPUT); digitalWrite(VBAT_ADC_CTL,LOW); delay(50);

uint16_t BatteryVoltage = getBatteryVoltage();
Serial.print("Battery mV: ");
Serial.println(BatteryVoltage);

// Serial.println(BatteryMV); appDataSize = 2; appData[0] = (uint8_t)(BatteryVoltage>>8); appData[1] = (uint8_t)BatteryVoltage;

pinMode(VBAT_ADC_CTL,INPUT);
Serial.println();
Serial.flush();

}