Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4745

Enabling Comparator / Disabling Comparator PIC 16f1829 Problem

$
0
0
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

Viewing all articles
Browse latest Browse all 4745

Trending Articles