PDA

View Full Version : Comparator trouble with 16f628A



Davidmarks
- 8th March 2011, 23:30
I don't seem to be getting the hang of this comparator business. I have a progamme (apparently successfully used by its designer) which sets out tu use a comparato to detect a low voltage pulse (in my case this could be as low as 10mv) the relevant part of the program is as follows:
[@ device pic16f628a, hs_osc, wdt_off, mclr_on, protect_off ,pwrt_on, bod_on, lvp_off, cpd_off

define osc 4

CMCON=%00100101
VRCON=%11110001 ]
My interpretation of the data sheet is that the cmcon defined uses comparator 2 output inverse on RA0 and that the setting of vrcon is to use the low output set to .21 volts and input to Comparator 2. First problem is inconsistency. earlier today I measured 0.21 volts on RA2 but now when I come to check it it is 0.41 I have tried three other 16f628a's with the same result. Also the output on RA0 is logic lowhen according to my understanding it should be 1 (i.e 5 volts)

Second problem is that the 0.21 reference voltage is not low enough to detect my 10mV pulse so I thought I would set up a potential divideracross the supply to produce something less than 10mv. Presumably I then switch off the vrcon by setting bit 7 to 0 (possibly bit 6 as well) Do I then connect the tap on the divider to RA2 or if not where ? I think my brain must have died as thorough examination of the datasheet has failed to make this clear to me and no other articles I can find help either. I'm sure that (once again) I am doing something daft here