Use your compare module in special event trigger
Hi Squibcakes,
You can use your compare module to automatically fire your ADC at a given interval. So the ADC will automatically generate interrupts. In your interrupt routine compare the current value with the old value. Keep some margin as two consecutive results may be different even if your pot is unchanged. When a change is found set a flag and process it in your main loop.
Darrels' Bring Together Interrupts
Hello,
I have been toying with Darrels' interrupts and the elapsed timer
programs. It's an amazing piece of work and just what I need at the
moment. Thanks!
Going on, I tried the "bring together" demo but that didn't go so
well. It won't compile using MPASM. The error messages are ;
FATAL ERROR too many errors
Error line 15: redefination of VAR. (DT_INTS-14.bas)
Error line 26: redefination of VAR. (DT_INTS-14.bas)
Error line 27: redefination of VAR. (DT_INTS-14.bas)
........Etc.
I am using the Pic 16f877 but that shouldnt matter at this point.
Any ideas?
Thanks John
On Change style Int with RB0
Hi,
I hope this is the right place to grab your attention. I am using a 16F73 @ 20Mhz with Hardware USART @ 115Kbps. I am using RB0 external interrupt portb.0 (can't help it only it is available) . Initially it is set to fire interrupt on a Low2High edge. Now when inside the interrupt I want to toggle the INT edge bit in the option_reg to have an interrupt on High2Low edge. The simple idea is to reset a timer when a variable duty cycle pulse begin and read the timer value when it turns off. Can't sit in a tight loop to watch if portb.0 = 0 cause got other tasks to do. So I am using Darrel's INT in both ASM and PBP. Here is the code:
Code:
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, INT_ASM, ASM, NO
INT_Handler INT_INT, _INT_PBP, PBP, YES
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
; BELOW IS THE ASM INTERRUPT HANDLER
ASM
INT_ASM
BSF STATUS, RP0 ; SELECT BANK 1
BTFSS OPTION_REG, INTEDG ; CHECK THE INTERRUPT EDGE
GOTO EDGE_LOW
; IF HERE THEN EDGE IS HIGH2LOW AND INT OCCURED AND NEEDS TO BE ALTERED/////////
EDGE_HIGH
BCF OPTION_REG, INTEDG ; SET TO INTERRUPT ON LOW2HIGH TRANSITION
CLRF STATUS ; SELECT BANK0
CLRF TMR0 ; CLEAR TIMER0
BSF _HIGH_EDGE ; SET FLAG THAT THIS IS A LOW2HIGH_EDGE INT
INT_RETURN ; RETURN FROM THE ASM INTERRUPT
; IF HERE THEN EDGE IS LOW2HIGH AND INT OCCURED AND NEEDS TO BE ALTERED ////////
EDGE_LOW
; BANK1 IS ALREADY SELECTED
BSF OPTION_REG, INTEDG ; SET TO INTERRUPT ON LOW
CLRF STATUS ; SELECT BANK0
MOVF TMR0, 0 ; MOVE TIMER0 TO W
MOVWF _TIMER ; MOVE TO THE TIMER VARIABLE IN BANK 0
BCF _HIGH_EDGE ; SET FLAG THAT THIS IS HIGH2LOW_EDGE INT
INT_RETURN ; RETURN FROM THE ASM INTERRUPT
ENDASM
INT_PBP: ' PBP INTERRUPT HANDLER
IF HIGH_EDGE = 1 THEN '
HSEROUT [10,"L2H",10] '
@ INT_RETURN ; RETURN FROM INSTANT INTERRUPT
ELSE
HSEROUT [10,"H2L",#TIMER, 10]
ENDIF
@ INT_RETURN ; RETURN FROM INSTANT INTERRUPT
Now my questions are :
1. Will this work ? Chances of false interrupt should not be, cause anyway while changing the option_reg the INT0 flag is not cleared and taken care of in the next PBP slice. Am I right ?
2. Should I manually check the transmit buffert (TRMT) and do the transmission to make things faster or let it be handled by PBP (keeps my hairfall under control ;))
P.S. : Actually I am counting on the email notification and everybody working with Darrel's II :D. Lester/Darrel please move this thread if you think that this should go as a new thread.