Yes, I had posted it before. But it was for a different chip, and I can't find it now.
It's not too difficult, so I re-wrote it for the 12F615 and tested it on a LAB-X4.
The idea is to use the internal 0.6V reference (ADC channel 5).
The reference stays the same as VDD changes, so with VDD as the ADC's Vref, the value read changes too. You can use that change to calculate actual VDD without needing an external Analog Pin.
The VDD result has 1 decimal place, so 5.0V will be 50.Code:DEFINE ADC_BITS 10 LCD VAR GPIO.1 ; serial pin for LCD LCDbaud CON 396 ; serial baud rate ADval VAR WORD VDD VAR WORD ANSEL = 0 ; All Pins are Digital ADCON0.7 = 1 ; Right Justify A/D result HIGH LCD : PAUSE 2 ; Initialize serial data level SEROUT2 LCD,LCDbaud,[$FE,1] : PAUSE 3 ; Clear LCD GOSUB GetVDD SEROUT2 LCD,LCDbaud,["A/D=",DEC ADval," ", _ "VDD= ",DEC VDD/10,".",DEC1 VDD] STOP ;------------------------------------------------------------------ Vref_AD CON 117 ; A/D reading for 0.6V Vref @ 5V VDD GetVDD: VRCON.4 = 1 ; Enable 0.6V Fixed reference PAUSE 10 ; allow reference to stabilize ADCIN 5, ADval ; read the 0.6V reference VDD = (Vref_AD * 50) / ADval ; convert to volts VRCON.4 = 0 ; turn off fixed reference RETURN
HTH,




Bookmarks