Electronic – Analog values without adc

adcmicrocontroller

I have a voltage divisor to measure the voltage of my battery which serves as a battery level detector and it is connected to a GPIO pin in a microcontroller which does not have an ADC. Is it possible to obtain the analog value? And if not is there another way to obtain the value without an ADC?

I have seen a way that will compare the voltage of the Vref of my microcontroller. Is it possible this way?

For the MCU, im using a STM32WB55CGU6 and the pin used is the PB6 (pin 46)

Best Answer

Applied my comment as an answer, with improved wording.

If it does not need to be that precise, or this is a one-off project so you can calibrate it, would the following work: make sure battery voltage is above logic 1 threshold.

After the voltage divider, put capacitor from the MCU pin to GND. Set pin to output low. Wait for capacitor discharge. Set pin to input. Wait in a loop, counting, how long it takes for the capacitor to charge to logic 1. Counter gives a time reading you can convert to voltage