cancel
Showing results for 
Search instead for 
Did you mean: 

STM8L051 ADC Pin current consumption when HALT

vegetableswim
Associate

Using STM8L051 ADC PD0, 3.7V~4.2V Li-Po battery, 1M+1M resistor to divde the battery voltage, 100nF capacitor to GND.

If set PD0 floating input and halt, total current 40uA, if set PD0 push-pull output LOW, 10uA. But the drawback of output LOW is that I have to wait 350ms for the 100nF cap charging before a new ADC reading.

Is there any method to reduce current consumption and remain floating input?

  GPIOD->CR2 &= ~0x01; // External interrupt disable
  GPIOD->CR1 &= ~0x01; // Floating input
  GPIOD->DDR &= ~0x01; // Input
  delay_ms(350); //Waiting capacitor charging and stable
  
  /* Enable ADC1 peripheral clock*/
  CLK->PCKENR2 |= 1<<0;
  /*clear CR1 register */
  ADC1->CR1 = 0x00;
  /* set the resolution and the conversion mode */
  ADC1->CR1 |= 1<<2; //continuous mode, 12bit
  //ADC1->CR1 &= ~(1<<2); //single mode, 12bit
  /*clear CR2 register */
  ADC1->CR2 &= ~0x80;
  /* set the Prescaler */
  ADC1->CR2 |= 0x80; //CLK/2
  /* Configures the sampling time for the Slow ADC channel group. */
  ADC1->CR2 &= ~0x07;
  ADC1->CR2 |= 0x07; //384 cycles
  /* Set the ADON bit to wake up the specified ADC from power down mode */
  ADC1->CR1 |= 0x01;
  /* Enable the selected ADC channel(s). */
  ADC1->SQR[1] |= 1<<6;  //SQR2, PD0 channel 22
  /* Clear EOC flag */
  //ADC1->SR &= ~0x01;
  /*  Start the ADC software conversion */
  ADC1->CR1 |= 0x02;
 
  
  for(i=0;i<8;i++)
  {
    //ADC1->CR1 |= 0x02;
    while((ADC1->SR & 0x01) == 0x00);
    temp = (uint16_t)(ADC1->DRH);
    temp = (uint16_t)((uint16_t)((uint16_t)temp << 8) | ADC1->DRL);
    ADCdata += temp;
  }
  ADCdata >>= 3;
  
  
  /* power down mode */
  ADC1->CR1 &= ~0x01;
  /* Disable the selected ADC channel(s). */
  ADC1->SQR[1] &= ~(1<<6);  //SQR2, PD0 channel 22
  /* Disable ADC1 peripheral clock*/
  CLK->PCKENR2 &= ~0x01;
  
  // PD0, ADC_IN
  GPIOD->CR2 &= ~0x01; // 2MHz slow
  GPIOD->CR1 |= 0x01;  // Push-pull
  GPIOD->ODR &= ~0x01; // Output Low
  GPIOD->DDR |= 0x01;  // Output

1 REPLY 1
RusikOk
Associate III

to control the supply voltage, you can use the following approach https://electronix.ru/forum/index.php?app=forums&module=forums&controller=topic&id=128726