-
DT CMP Interrupt Problem
I'm using PIC16F877, and have 2 analog inputs IN1 and IN2. I want to generate interrupt if voltage IN1 > IN2. Do I keep reading the AD register and compare it with IN2 voltage during each CMP interrupt? Or is there a more efficient way to implement this?
Code:
define OSC 20
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler CMP_INT, _Int_Cmp, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_DISABLE CMP_INT ;Comparator int
ADCON1= %00000000 'enable all analog inputs
LED var PORTB.7
loop:
'start ad here
'end ad
pause 50
goto loop
'---[CMP - interrupt handler]----------------------------------------------
Int_Cmp:
toggle LED
'read and store ad result here
@ INT_RETURN
I haven't finish the code above, but am getting a compilation error in Microcode "symbol not previously defined [CMIF]". PLease help.
-
The 16F877 doesn't have a Comparator module.
The 16F877A does.
<br>
-
I don't have 16F877A now. If I continue to use 16F877, what is the best method to detect IN1>IN2?
This means I don't have any interrupt, and I have to poll the go/done bit in ADCON0 while sacrificing on executing other task?
-
The A/D module has an interrupt that fires when a conversion is complete.
You don't have to sit in a loop polling the Go/Done bit.
<br>
-
Oh, that's great. How do I implement this using DT interrupt?
Below is what I'm currently doing, using pause 25ms before the next AD.
Code:
define OSC 20
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
ADCON1= %00000111 'PIC16F877 all analog input except RE1,RE2
'start AD here
ADCIN 0, adval ' Read channel0 RA.0 to adval
pause 25
ADCIN 1, adval2 ' Read channel1 RA.1 to adval
pause 25