Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
134
Ver.1.0.0
5.2.2.1 Initialization of Low Battery Detect
Refer to function “adc_vbat_init”.
ADC initialization must always follow the flow: power off SAR ADC; configure ADC
parameters; power on SAR ADC. TLSR8232 sets SAR ADC as power down by default,
so “adc_vbat_init” does not set power down of “adc_power_on(0)”. TLSR8232 enables
ADC power Every time before reading ADC data and disables ADC power after reading
is completed.
It’s not recommended to modify the initialization setting of ADC, users can use the default
setting. However, users can select other GPIO input channel via the macro
“BATTERY_CHECK_PIN”.
If on HW design, supply is directly connected to GPIO input channel, high level output
needs to be removed from the “BATTERY_CHECK_PIN”.
Below is code of
“adc_vbat_init” in “battery_power_check”.
if
(!adc_hw_initialized){
adc_hw_initialized = 1;
adc_init();
adc_vbat_init(BATTERY_CHECK_PIN);
}
Herein a variable “adc_hw_initialized” is used to call one initialization. When the variable
is set to 0, one initialization is called, and then the variable should be set to 1 to disable
further initialization.
By using the
“adc_hw_initialized” ADC tasks can switch between Low Battery Detect and
other ADC task
s (“ADC other task”).
Due to dynamic ADC task switch, the “adc_vbat_init” may be executed multiple times, so
it must be implemented in the main_loop rather than user_init().
On first call
ing of “battery_power_check”, “adc_vbat_init” is executed and will not be
executed repeatedly.
To switch to
“ADC other task”, for proper initialization in new task, the
“adc_hw_initialized” will be set to 0.
After completion of
“ADC other task”, the “battery_power_check” will be executed again.
Since current adc_hw_initialized
is 0, the “adc_vbat_init” must be executed again, so as
to guarantee re-initialization on every switch back.
5.2.2.2 Low Battery Detect Processing
In main_loop, the
function “battery_power_check” is called to process Low Battery
Detect. Related code is shown as below:
if
(clock_time_exceed(lowBattDet_tick, 500*1000)){
lowBattDet_tick = clock_time();
battery_power_check(BATTERY_VOL_MIN);
}