Dear Dialogue support,
So far we are struggling to get ADC on P02/P01 working using external divider - tried both da14585 basic kit and our own board, same behavior.
When we use to external divider, we always get battery reading of 0 while the voltage on the pin is 1.050v - used 2M/1M ohm voltage divider to connect to P02 or P01.
Switching to internal ADC_CHANNEL_VBAT3V reading 100%. With 1.050v applied on P02 and using internal GP_ADC_ATTN3X enabled, always get raw adc (8 bit) about 0x2F.
And have configured the following in user_periph_setup.h:
#define ADC_PORT GPIO_PORT_0
#define ADC_PIN GPIO_PIN_2
and
RESERVE_GPIO( ADCX, ADC_PORT, ADC_PIN, PID_ADC);
in GPIO_reservation function, and
GPIO_ConfigurePin( ADC_PORT, ADC_PIN, INPUT, PID_ADC, false);
in set_pad_function.
Here is the modified adc_get_vbat_sample.
uint32_t adc_get_vbat_sample(bool sample_vbat1v)
{
#define TEST_BATT 1
uint32_t adc_sample, adc_sample2;
#if TEST_BATT
adc_init(GP_ADC_SE, GP_ADC_SIGN, 0);
#else
adc_init(GP_ADC_SE, GP_ADC_SIGN, GP_ADC_ATTN3X);
#endif
adc_usDelay(20);
if (sample_vbat1v)
adc_enable_channel(ADC_CHANNEL_VBAT1V);
else
#if TEST_BATT
#warning "used p02"
adc_enable_channel(ADC_CHANNEL_P02);
#else
adc_enable_channel(ADC_CHANNEL_VBAT3V);
#endif
adc_sample = adc_get_sample();
adc_usDelay(7);
#if TEST_BATT
adc_init(GP_ADC_SE, 0, 0);
#else
adc_init(GP_ADC_SE, 0, GP_ADC_ATTN3X );
#endif
if (sample_vbat1v)
adc_enable_channel(ADC_CHANNEL_VBAT1V);
else
#if TEST_BATT
adc_enable_channel(ADC_CHANNEL_P02);
#else
adc_enable_channel(ADC_CHANNEL_VBAT3V);
#endif
adc_sample2 = adc_get_sample();
//We have to divide the following result by 2 if
//the 10 bit accuracy is enough
adc_sample = (adc_sample2 + adc_sample);
adc_disable();
return adc_sample;
}
Please note we have " #define TEST_BATT 1 " above.
Is there anything else we've missing?
Thanks for your attention,
uta_lc
Hi uta_lc,
I am working on your issue, and I made some measurements, so I will let you know as soon as possible.
Thanks, PM_Dialog
Thanks, already got it working.
Hi uta_lc,
Glad to get it working. Could you please let us know how you fixed this problem?
Thanks, PM_Dialog
Hi PM,
The h/w and s/w are both OK - it is the SDK behaviour change from 5.0.4 to 6.0.6:
In SDK 5.0.4 we could return any value for battery percentage - we've tried to return raw ADC (8 bit) to customize battery percentage.
However in SDK 6.0.6, it has been changed in such a way that any value > 100 is returned as 0. We thought the raw adc value was 0 but after some debugging we found raw adc is correctly read, it is just the database does not allow value > 100 is returned in battery level UUID.
Cheers,
uta_lc
Hi uta_lc,
Thanks for the indication.
Best regards,
PM_Dialog