Ways to Display Power Supply Voltage

hal8000

Member
I don't know what the maximum input voltage is per pin on a 20M2 picaxe,
but if the picaxe was powered from 5V and I wanted to read a 15V supply
then I would use an attenuator of say 4.7k resistor pin C.1 to Ov
and 10k resistor from Vcc to pin C.1

This would give 4.79 V on pin C.1 (no load or high impedance input).

I have been thinking of ways to convert this voltage to read on an OLED display.
My power supply typically only varies by by 0.3V so I only really need to convert
3 values:

(Have not measured this yet, so values below are just examples.)


;C.2 is OLED display C.1 is input attenuator
If readadc C.1 < 51 then
serout C.2,N2400, (" Vcc = 15.0V")
If readadc C.1 < 50 then
serout C.2,N2400, (" Vcc = 14.9V")
If readadc C.2 <49 then
serout C.2,N2400, (" Vcc = 14.8V")
etc

This is possibly one way of getting an accurate reading, but code
looks sloppy, any more ways to read a higher voltage?
Thanks in advance.
 

hippy

Technical Support
Staff member
From the ADC reading (Nadc) and knowing the PICAXE power supply (Vpsu) you can determine the ADC pin voltage (Vadc), and from that can determine the voltage into the potential divider. Nmax is the max reading from ADC, 255 for READADC, 1023 for READADC10 ...

Nadc = Vadc * Nmax / Vpsu

Vadc = Nadc * Vpsu / Nmax
 

SAborn

Senior Member
Set your voltage divider up with the 2 resistors and then check the voltage with a meter before you plug the chip into the socket to ensure its under 5 volts.

Its better to use Readadc10 as this will give a higher resolution.
Then times the reading by 10 and divide it by a calibration value to give correct volts, then simply sertxd the correct value to the display.
 
Top