Page 3 of 3

Re: Read VCC

Posted: Mon Sep 05, 2016 5:30 am
by bubulindo
I was looking at this same features of the ADC (after managing to get interrupts from it and Analog Watchdog) and one can measure the internal temperature of the chip by reading channel 16 instead of channel 17. There is a formula and some parameters to calculate a number, but even then it should only be used for detecting temperature increases.

One thing that stands out is that the adc core was quite undeveloped. It does have a couple of functions that are interesting, but it seems as if the only development was done to get the equivalent of analogRead().

I managed to get the interrupts working and will be starting to look into the scan mode soon. :)

Re: Read VCC

Posted: Tue Jan 10, 2017 10:42 pm
by victor_pv
ahull wrote:Nice! Good for checking battery health and pre-empting power watchdog switching us off. I'll need to file that in my cluttered mental archive for later. :D
Andy, for that purpose there is something even better. I was looking at something else today and found it in the datasheet:
The device features an embedded programmable voltage detector (PVD) that monitors the
VDD/VDDA power supply and compares it to the VPVD threshold. An interrupt can be
generated when VDD/VDDA drops below the VPVD threshold and/or when VDD/VDDA is
higher than the VPVD threshold. The interrupt service routine can then generate a warning
message and/or put the MCU into a safe state. The PVD is enabled by software.
That's in the datasheet for apparently all the F103 series.
So you don't need to have your software read the VCC level, but rather set the PVD threshold, set the ISR, and enable it, and the hardware monitors it for you.

Re: Read VCC

Posted: Tue Jan 10, 2017 11:42 pm
by ahull
Good find. I'll have to have a play with that. I wonder how quickly it can react.

Re: Read VCC

Posted: Wed Jan 11, 2017 1:35 pm
by victor_pv
ahull wrote:Good find. I'll have to have a play with that. I wonder how quickly it can react.
I would guess real fast, since it is a hardware compare triggering an interrupt. If you get to try it let us know if it works. Could be good to add some functions to the core to set it up.