Measure the supply voltage of an AVR

Use this section to discuss your embedded Flowcode projects.
Post Reply
pantelispv5
Posts: 5
http://meble-kuchenne.info.pl
Joined: Thu Dec 17, 2020 9:14 pm

Measure the supply voltage of an AVR

Post by pantelispv5 »

Hi, There. I need to measure the voltage that supplies the AVR 8bit ATtiny series using this very same MCU. Maybe I can use the Vgap reference 1.1V But I would like to ask if this can be done directly in Flowcode 11?

Steve-Matrix
Matrix Staff
Posts: 1685
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 239 times
Been thanked: 398 times

Re: Measure the supply voltage of an AVR

Post by Steve-Matrix »

It should be easy to measure the Vcc within Flowcode using an analogue input and the voltage reference. A web search brought up this article and this article which might be of help.

chipfryer27
Valued Contributor
Posts: 1784
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 397 times
Been thanked: 610 times

Re: Measure the supply voltage of an AVR

Post by chipfryer27 »

Hi

Following on from above, I think Steve001 posted a solution in the old forum. A search there would probably be worth trying.

Regards

pantelispv5
Posts: 5
Joined: Thu Dec 17, 2020 9:14 pm

Re: Measure the supply voltage of an AVR

Post by pantelispv5 »

chipfryer27 wrote:
Tue Dec 16, 2025 10:23 am
Hi

Following on from above, I think Steve001 posted a solution in the old forum. A search there would probably be worth trying.

Regards
My question was only how to calculate in flowcode (if this is possible without C code) the difference voltage VDD-Vbg. Thanks

BenR
Matrix Staff
Posts: 2049
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 544 times
Been thanked: 727 times

Re: Measure the supply voltage of an AVR

Post by BenR »

If you have a spare ADC pin then the easy way is to connect the ADC pin to something like this.
Screenshot 2025-12-22 114355.png
Screenshot 2025-12-22 114355.png (10.59 KiB) Viewed 31 times
The diode will have a specific forward voltage drop across it, usually around 0.7V for a standard diode and more like 0.45V for a schottky. As your VCC drops the ADC reading will rise allowing you to calculate the value of VCC.

Assuming a 10-bit ADC and a 0.7V diode. ADC resolution is ((1 << 10) - 1) = 1023

Code: Select all

VCC Voltage = (0.7 / FLOAT ADC Reading) * 1023.0
A fixed voltage reference would be better then a diode but in a pinch a diode will work.

Note there is some variation of the forward voltage drop across a diode with temperature, hence why the diode isn't ideal. The resistor value doesn't really matter just keep it over 10K to reduce current usage.

If your device has an internal reference then it may be fairly simple to use this instead to do the same thing.

Post Reply