Robinwithu
New Member
Hello everybody i am new on this forum and checked also topic related with comparator and didnt find any solution's so here i am posting my code ..please have a look and give me suggestion ...to work my comparator of 16F684.............
Rc0--analog input
Rc1--internal ref voltage
Rc4--comparator output.
using intenal comparator at 8mhz ..
not using any interrupt..of ocmparator
MAIN CODE
start
;***********************define pin direction, and initialization *************************
clrf PORTA
clrf PORTC
movlw 0x02
movwf PORTA ;;RA1 as supply power which is supply voltage for melexis
clrf ANSEL
movlw 0x05 ;enable comparator(one independent comparator enabled)
movwf CMCON0
bsf STATUS, RP0 ;change bank0 to bank1
bcf TRISC,RC3 ;set RC3 as output--WAKE-UP
bcf TRISC,RC4 ;set RC4 as output--comparator output
bcf TRISA,RA1 ;set RA1 as output--Power Supply to Switch
bsf TRISC,RC0 ;set RC0 as input---Switch analog output
bsf ANSEL, RC0 ;set RC0 as analog input
movlw 0x71 ;8Mhz
movwf OSCCON ;1-HTS stable bit and 1-internal clock
movlw 0x0F ;x0F ---max frequency
movwf OSCTUNE ;to select the max frequency tunning bit register
bcf STATUS, RP0
clrf INTCON
;*****************************************************************************************
comparator:
bsf STATUS, RP0
movlw 0x86 ;internal voltage reference
movwf VRCON ;internal voltage reference set to(x86) 2,1875 volts
bcf STATUS, RP0 ;Cvref=((Vdd\4)+((Vrr[3:0]*Vdd)\32))
Check_comp:
btfsc CMCON0, C2OUT ;when the internal ext vtg is greater than 2,1875 v ;btfsc PORTC,RC4
goto WU_OFF ;than only we will get output from op-amp.
goto WU_ON
WU_ON:
bsf PORTC,RC3
goto Check_comp
WU_OFF:
bcf PORTC,RC3
goto Check_comp
please reply me as soon as possible.....request!!!!!!!!!!!!!!
Rc0--analog input
Rc1--internal ref voltage
Rc4--comparator output.
using intenal comparator at 8mhz ..
not using any interrupt..of ocmparator
MAIN CODE
start
;***********************define pin direction, and initialization *************************
clrf PORTA
clrf PORTC
movlw 0x02
movwf PORTA ;;RA1 as supply power which is supply voltage for melexis
clrf ANSEL
movlw 0x05 ;enable comparator(one independent comparator enabled)
movwf CMCON0
bsf STATUS, RP0 ;change bank0 to bank1
bcf TRISC,RC3 ;set RC3 as output--WAKE-UP
bcf TRISC,RC4 ;set RC4 as output--comparator output
bcf TRISA,RA1 ;set RA1 as output--Power Supply to Switch
bsf TRISC,RC0 ;set RC0 as input---Switch analog output
bsf ANSEL, RC0 ;set RC0 as analog input
movlw 0x71 ;8Mhz
movwf OSCCON ;1-HTS stable bit and 1-internal clock
movlw 0x0F ;x0F ---max frequency
movwf OSCTUNE ;to select the max frequency tunning bit register
bcf STATUS, RP0
clrf INTCON
;*****************************************************************************************
comparator:
bsf STATUS, RP0
movlw 0x86 ;internal voltage reference
movwf VRCON ;internal voltage reference set to(x86) 2,1875 volts
bcf STATUS, RP0 ;Cvref=((Vdd\4)+((Vrr[3:0]*Vdd)\32))
Check_comp:
btfsc CMCON0, C2OUT ;when the internal ext vtg is greater than 2,1875 v ;btfsc PORTC,RC4
goto WU_OFF ;than only we will get output from op-amp.
goto WU_ON
WU_ON:
bsf PORTC,RC3
goto Check_comp
WU_OFF:
bcf PORTC,RC3
goto Check_comp
please reply me as soon as possible.....request!!!!!!!!!!!!!!