
Originally Posted by
Kamikaze47
This may be more helpful to you. This is the same thing, but done using DT's instant interrupts. You also need to INCLUDE the DT_INTS and ReEnterPBP files relevant to your PIC.
Code:
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR0_INT, tmr0_handler, PBP, yes
INT_Handler INT_INT, int_handler, PBP, yes
endm
INT_CREATE
ENDASM
@ INT_ENABLE TMR0_INT
@ INT_ENABLE INT_INT
main:
' your main program
goto main
tmr0_handler:
oDimmer=1
@ INT_RETURN
int_handler:
TMR0=DimmerVal
oDimmer=0
@ INT_RETURN
I am still trying to understand the above code -
Is this code running timer0 interrupt all the time?
I learnt that in DIMMERS, you have to control the +ve half of the cycle only, so timer0 should be loaded after checking the positive half making the PIC pin HIGH and keeping the triac ON for that period.
ALSO FOR THE ASM PART:
Code:
btfsc INTCON, INTF ; If INTF=1 THEN GOTO ZeroCrossingInt (1)
goto ZeroCrossingInt ; (2)
btfss INTCON, T0IF ; If T0IF=0 THEN GOTO EndInt (3)
goto EndInt ; (4)
T0Overflow ; T0Overflow: (5)
bcf INTCON, T0IF ; T0IF=0 (6)
bsf _oDimmer ; oDimmer=1 (7)
goto EndInt ; GOTO EndInt (8)
ZeroCrossingInt ; ZeroCrossingInt: (9)
bcf INTCON, INTF ; INTF=0 (10)
movf _DimmerVal,w ; TMR0=DimmerVal(11)
movwf TMR0 ;(12)
bcf _oDimmer ; oDimmer=0(13)
I believe everytime this interrupt will be entered: (Please correct me where I go wrong)
--- Statement (1) in the code will always be true (this is the reason why interrupt has happened), so the code will jump to (9), it will act on (10) & then (11) & (12) -- SO WHERE DOES IT WAIT FOR TIMER0 TO RUN OUT & WHY STATEMENT (13) IS THERE CLEARING _oDimmer when this bit is not set in the sequence I just understood and explained above.
--- When does code enters (5) ? Does after (13) code goes to (3)?
Bookmarks