Skip to content

Commit e74074e

Browse files
committed
[HAL][K20XX/KLXX] Fixed deepsleep power consumption when AnalogIn is used
The power consumption was reported by Paul Staron to be 100uA higher when an AnalogIn was used previously. Problem 1 is that 40uA was used by the async ADC clock, which is never actually used, so it is disabled. Problem 2 is that setting it for high speed mode increased it by another 60uA while in deepsleep. This currently seems to me to be possibly a bug in the design, but the workaround is checking if this is the case before going to deepsleep, and if yes, disable it. Afterwards it is re-enabled.
1 parent d1d900d commit e74074e

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20XX/analogin_api.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void analogin_init(analogin_t *obj, PinName pin) {
5151
| ADC_CFG1_ADICLK(clkdiv >> 2); // Input Clock
5252

5353
ADC0->CFG2 = ADC_CFG2_MUXSEL_MASK // ADxxb or ADxxa channels
54-
| ADC_CFG2_ADACKEN_MASK // Asynchronous Clock Output Enable
5554
| ADC_CFG2_ADHSC_MASK // High-Speed Configuration
5655
| ADC_CFG2_ADLSTS(0); // Long Sample Time Select
5756

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20XX/sleep.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ void sleep(void)
2929
//Very low-power stop mode
3030
void deepsleep(void)
3131
{
32+
//Check if ADC is enabled and HS mode is set, if yes disable it (lowers power consumption by 60uA)
33+
uint8_t ADC_HSC = 0;
34+
if (SIM->SCGC6 & SIM_SCGC6_ADC0_MASK) {
35+
if (ADC0->CFG2 & ADC_CFG2_ADHSC_MASK) {
36+
ADC_HSC = 1;
37+
ADC0->CFG2 &= ~(ADC_CFG2_ADHSC_MASK);
38+
}
39+
}
40+
3241
//Check if PLL/FLL is enabled:
3342
uint32_t PLL_FLL_en = (MCG->C1 & MCG_C1_CLKS_MASK) == MCG_C1_CLKS(0);
3443

@@ -67,4 +76,8 @@ void deepsleep(void)
6776
while((MCG->S & MCG_S_LOCK0_MASK) == 0u) { } // Wait until locked
6877
#endif
6978
}
79+
80+
if (ADC_HSC) {
81+
ADC0->CFG2 |= (ADC_CFG2_ADHSC_MASK);
82+
}
7083
}

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/analogin_api.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ void analogin_init(analogin_t *obj, PinName pin) {
5858
| ADC_CFG1_ADICLK(clkdiv >> 2); // Input Clock: (Bus Clock)/2
5959

6060
ADC0->CFG2 = cfg2_muxsel // ADxxb or ADxxa channels
61-
| ADC_CFG2_ADACKEN_MASK // Asynchronous Clock Output Enable
6261
| ADC_CFG2_ADHSC_MASK // High-Speed Configuration
6362
| ADC_CFG2_ADLSTS(0); // Long Sample Time Select
6463

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/sleep.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ void sleep(void)
3030
//Very low-power stop mode
3131
void deepsleep(void)
3232
{
33+
//Check if ADC is enabled and HS mode is set, if yes disable it (lowers power consumption by 60uA)
34+
uint8_t ADC_HSC = 0;
35+
if (SIM->SCGC6 & SIM_SCGC6_ADC0_MASK) {
36+
if (ADC0->CFG2 & ADC_CFG2_ADHSC_MASK) {
37+
ADC_HSC = 1;
38+
ADC0->CFG2 &= ~(ADC_CFG2_ADHSC_MASK);
39+
}
40+
}
41+
3342
#if ! defined(TARGET_KL43Z)
3443
//Check if PLL/FLL is enabled:
3544
uint32_t PLL_FLL_en = (MCG->C1 & MCG_C1_CLKS_MASK) == MCG_C1_CLKS(0);
@@ -54,4 +63,8 @@ void deepsleep(void)
5463
MCG->C1 &= ~MCG_C1_CLKS_MASK;
5564
}
5665
#endif
66+
67+
if (ADC_HSC) {
68+
ADC0->CFG2 |= (ADC_CFG2_ADHSC_MASK);
69+
}
5770
}

0 commit comments

Comments
 (0)