Okay, after some more trials and a correct connection to GP1 (... not GP0!!!), I got it working.
BUT how do I improve the accuracy?
When the measured voltage ist between 2,3V and 2,6V, my led flickers.
How do I fix this?
Another strange thing: if I "forget" to set the GP1 input as Analog (ANSEL), it still works(!?).
BTW, here are my corrected schema and code:
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1708&stc=1&d=118097654 5">
Code:
' Fuses
@ DEVICE PIC12F675,INTRC_OSC_NOCLKOUT ;Internal oscillator 4MHz
@ DEVICE PIC12F675,WDT_OFF
@ DEVICE PIC12F675,PWRT_ON
@ DEVICE PIC12F675,MCLR_OFF
@ DEVICE PIC12F675,BOD_OFF
@ DEVICE PIC12F675,PROTECT_OFF
@ DEVICE PIC12F675,CPD_OFF
'-------------------------------------------------------------------------------
' Registers 76543210
OSCCAL = %10000000 'Center frequency - used with Internal 4MHz OSC
TRISIO = %00000010 'Set Input/Output
GPIO = %00000000 'Ports High/Low
WPU = %00000000 'Weak pull-ups (check OPTION_REG)
OPTION_REG = %10000000 'Pull-ups / Interrupt / Prescaler
ANSEL = %00000010 'Analog I/O
CMCON = %01000100 'Comparator Module settings
VRCON = %10101100 'Voltage reference (= 2.5V)
'-------------------------------------------------------------------------------
' Variables
BatVal var CMCON.6
BatLoLED var GPIO.2
'-----------------------------------------------------------------------------
' Program
Pause 1 'Delay to allow for VREF to settle
MAIN:
BatLoLED = BatVal
pause 10
Goto Main
End
Bookmarks