aljamri
Member
Hi,
I've tried to test the PIC comparator facility but not succeeded . At the begiging I've used mikroC with PIC12F675 and failed. This made me to go back to the datasheet and tried this time 16F628 and copied exactly the given example in page 55 with only two changes. Firstly I could not make a 10µ Second delay, instead I've put a 'nop' . Secondly I used mode 4 ( Two independent Comparators ) instep of mode 3 (Two common Reference comparators ) and the code is as follows:
but regardless the change in Vin+, no any output is observed. is this has any thing to do with FUSE setting as I copied the first 7 lines from NG tutorials. Any problem ? Thanks
I've tried to test the PIC comparator facility but not succeeded . At the begiging I've used mikroC with PIC12F675 and failed. This made me to go back to the datasheet and tried this time 16F628 and copied exactly the given example in page 55 with only two changes. Firstly I could not make a 10µ Second delay, instead I've put a 'nop' . Secondly I used mode 4 ( Two independent Comparators ) instep of mode 3 (Two common Reference comparators ) and the code is as follows:
Code:
LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
ERRORLEVEL 0, -302 ;suppress bank selection messages
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)
cblock 0x20 ;start of general purpose registers
FLAG_REG
endc
CLRF FLAG_REG ;Init flag register
clrf FLAG_REG
CLRF PORTA ;Init PORTA
MOVF CMCON,W ;Load comparator bits
ANDLW 0xC0 ;Mask comparator bits
IORWF FLAG_REG,F ;Store bits in flag register
MOVLW 0x04 ;Init comparator mode
MOVWF CMCON ;CM<2:0> = 011
BSF STATUS,RP0 ;Select Bank1
MOVLW 0x07 ;Initialize data direction
MOVWF TRISA ;Set RA<2:0> as inputs
;RA<4:3> as outputs
;TRISA<7:5> always read ‘0’
BCF STATUS,RP0 ;Select Bank 0
CALL DELAY10 ;10µs delay
MOVF CMCON,F ;Read CMCON to end change condition
BCF PIR1,CMIF ;Clear pending interrupts
BSF STATUS,RP0 ;Select Bank 1
BSF PIE1,CMIE ;Enable comparator interrupts
BCF STATUS,RP0 ;Select Bank 0
BSF INTCON,PEIE ;Enable peripheral interrupts
BSF INTCON,GIE ;Global interrupt enable
DELAY10
nop
end
but regardless the change in Vin+, no any output is observed. is this has any thing to do with FUSE setting as I copied the first 7 lines from NG tutorials. Any problem ? Thanks
Last edited: