Enabling Comparator / Disabling Comparator PIC 16f1829 Problem


Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    May 2013
    Posts
    2

    Default Enabling Comparator / Disabling Comparator PIC 16f1829 Problem

    Here is a break down of what is going on.

    Using both comparators, one input is C12IN1 (portc.1) and the other is C12IN2 (portc.2).

    I am not having an issue with the comparators functions. They are fine but the issue I am having is that I need to read COUT and if it equals 0, I need to ouput on the comparator input pin. I know some of you may say "why?". Lets just say I am playing middle man with a signal.

    I thought this would be simple enough and wrote 2 sub-routines. One disables the comparator and sets the port up so I can output and the other re-enables the comparator for the next read. This does not seem to work at all. The program locks up and as far as I can tell, it happens after the comparator is disabled or when it is re-enabled.

    Below are my sub-routines for disabling and enabling the comparators and configuring the ports. The comparator enable routine is literally a copy and paste of the configuration at startup that I know works. Again, every part of the program is fine until I have to disable and re-enable comparators then it locks up.

    I use PICBasic PRO

    DISCOMP:
    '------------------
    'DISABLE COMPARATOR
    DACCON0 = %00000000
    DACCON1 = %00000000
    CM1CON0 = %00000000
    PIR2 = %00000000
    CM1CON1 = %00000000
    CM2CON0 = %00000000
    PIR2 = %00000000
    CM2CON1 = %00000000
    ''''''PORTC SETUP''''''''
    ANSELC = %00000000
    WPUC = %11111001
    INLVLC = %00000000
    LATC = %00000000
    TRISC = %11111111
    '------------------
    RETURN

    ENCOMP:
    '------------------
    ''''''PORTC SETUP''''''''
    ANSELC = %00000110
    WPUC = %11111001
    INLVLC = %00000000
    LATC = %00000000
    TRISC = %11111111
    '------------------
    'ENABLE COMPARATOR
    DACCON0 = %00000000
    DACCON1 = %00010000
    CM1CON0 = %10010110
    PIR2 = %00000000
    CM1CON1 = %00010001
    CM2CON0 = %10010110
    PIR2 = %00000000
    CM2CON1 = %00010010

    RETURN
    Last edited by ShizNiz; - 31st May 2013 at 16:40.

Similar Threads

  1. Use a PIC ADC like a fast interrupt comparator?
    By pxidr84 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th August 2011, 05:33
  2. PIC18F13K22 comparator problem
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th June 2011, 09:42
  3. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  4. PIC16F616 Comparator problem
    By JimA in forum General
    Replies: 0
    Last Post: - 15th October 2007, 14:56
  5. need help on comparator
    By bertus in forum General
    Replies: 1
    Last Post: - 21st October 2003, 10:25

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