PDA

View Full Version : 12F683 Comparator Problems



morethanenuf
- 8th September 2005, 22:21
I'm relatively new to PICBasic Pro. I am having a very hard time initializing the comparator and then using it. I want to run a test using the 12F683's comparator and a digital pot as a reference voltage. The digital pot would be programmed by a 16F877 running the main program while the 12F683 will be running monitor program and send an interrupt to the 877 when the comparator is toggled. I would like the output of the comparator to be available outside the PIC. In reading the spec I found that "CMCON0 = 1" is the only thing I could find to initialize the comparator. After this I am at a loss for how to use the comparator. If anyone can help or point me to a webpage or an article I would be forever greatful. Thanks in advance.

mister_e
- 8th September 2005, 23:38
really far of what you need but here's an example with a 12f675 i did many months ago using the internal comparator


@ __config _INTRC_OSC_NOCLKOUT & _MCLRE_OFF ;config fuse

TRISIO = %11001111 ;GPIO.4, GPIO.5 as output
CMCON=%00000010 ;COUT=1 when Vin+(GPIO.0) > Vin- (GPIO.1)
;comparator mode :comparator without output
ANSEL=0 ;turn off analog to digital

Clip var GPIO.4
Normal var GPIO.5
Speaker var byte

start:
speaker=CMCON.6 ;read from internal comparator
Select case speaker
case 0
clip=0
normal=1
case 1
clip=1
normal=0
pause 100
Clip=0
end select
goto start

morethanenuf
- 9th September 2005, 15:30
Thanks for the help. I understand how your code works, but I still can't get the comparator to work as far as I can tell. All I'm trying to do now is use 2 pots as the analog inputs Vin+ and Vin- and use COUT to turn an led on and off. Is there a drive problem with the comparator? Do I have to use the internal output as a signal to drive a separate pin HIGH or LOW?

mister_e
- 9th September 2005, 15:36
By looking the datasheet, the comparator will be GP2 and must be set as digital and can sink/source +/- 25mA