Read VCC

Post your cool example code here.
bubulindo
Posts: 33
Joined: Fri Sep 11, 2015 10:51 am

Re: Read VCC

Post by bubulindo » Mon Sep 05, 2016 5:30 am

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. :)

victor_pv
Posts: 1740
Joined: Mon Apr 27, 2015 12:12 pm

Re: Read VCC

Post by victor_pv » Tue Jan 10, 2017 10:42 pm

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.

User avatar
ahull
Posts: 1650
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Read VCC

Post by ahull » Tue Jan 10, 2017 11:42 pm

Good find. I'll have to have a play with that. I wonder how quickly it can react.
- Andy Hull -

victor_pv
Posts: 1740
Joined: Mon Apr 27, 2015 12:12 pm

Re: Read VCC

Post by victor_pv » Wed Jan 11, 2017 1:35 pm

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.

Post Reply