12F683 Comparator Problems


Closed Thread
Results 1 to 4 of 4
  1. #1
    morethanenuf's Avatar
    morethanenuf Guest

    Angry 12F683 Comparator Problems

    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.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    really far of what you need but here's an example with a 12f675 i did many months ago using the internal comparator
    Code:
    @ __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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    morethanenuf's Avatar
    morethanenuf Guest


    Did you find this post helpful? Yes | No

    Default

    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?

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    By looking the datasheet, the comparator will be GP2 and must be set as digital and can sink/source +/- 25mA
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. 12F683 - Pin1 not working
    By ruijc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th February 2014, 17:38
  2. Setting up a 12F683 to run at 20 Mhz
    By johnnylynx in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 3rd March 2009, 02:46
  3. 12F683 Programmer
    By Red_Stafford in forum Schematics
    Replies: 9
    Last Post: - 2nd October 2008, 21:44
  4. 12F683 HPWM Usage
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th November 2007, 02:16
  5. 16f677a to 12f683
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th July 2007, 06:16

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts