Quote Originally Posted by mister_e View Post
Can't wait to return home... use the following ACDetect routine instead.
this should work.
Code:
disable
ACDetect:
if ACline==1 then 
    '
    '    Rising edge of AC signal
    '    ========================
	if triacdelay then              ' A delay is set by user
                                        '  
	    if FullBright==0 then       ' Full Brightness flag is not set
            pauseus maxdelay-triacdelay '    do the selected delay
            triac=1                     '    enable TRIAC	    	
            else                        '
    	        triac=1                 ' Full Brightness flag is set
                                        '    enable triac
            endif                       '
                                        '
        else                            '
    	    triac=0                     ' No Delay set by user... disable Triac
        endif                           '
    
    else                                
    '
    '    Falling edge of AC signal
    '    =========================
        if fullbright==0 then triac=0   ' Disable the Triac on falling edge of 
                                        ' Ac signal
    endif
INTCON.0=0 ' Clear GPIF (interrupt on GP4 change)
resume
enable
Yeah i know you can also use Pulsout and forget the Falling edge detection... as you wish. Both will work.
Very interesting thread I must say. I am trying to do the same and have added DT_INTERRUPTS to manage the ac detect....But my lamp is not dimming at all, also when in the code 'triacdelay=0', my lamp does not go off........ Can someone spot the error please.
Code:
INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
Include "modedefs.bas"
@ __Config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN & _CP & _CPD

TriacDelay                  var Word
maxdelay                    var word

Triac	var	PortA.1 ' Output to TRIAC gate
ACLine	var	PortA.2 ' Input for the FullWave rectify AC line
Buz		var PortC.2

TRISA = %001100
TRISC = 0
CMCON = 7
ANSEL = 0
OPTION_REG = %11000000  ' RAPU = off, PS WDT
PORTA=0
PORTC=0

ASM
INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
        INT_Handler    INT_INT,  _ACDetect,   PBP,  yes
    endm
    INT_CREATE               ; Creates the interrupt processor
ENDASM

@   INT_ENABLE   INT_INT     ; enable external (INT) interrupts

Triac=0            ' disable Triac Gate
triacdelay=0  ' Set delay to minimum

while 1

pause 3000
high buz: pause 500 : low buz
triacdelay=8000     : pause 10000 :high buz: pause 50 : low buz 
triacdelay=5000     : pause 10000 :high buz: pause 50 : low buz 
triacdelay=4500     : pause 10000 :high buz: pause 50 : low buz 
triacdelay=4000     : pause 10000 :high buz: pause 50 : low buz
triacdelay=3500     : pause 10000 :high buz: pause 50 : low buz
triacdelay=0 : pause 7000

wend

ACDetect:
	if triacdelay > 0 then
			if triacdelay=8000 then
				triac=1 ' Activate TRIAC
			else
				maxdelay=8000-triacdelay
				pauseus maxdelay
				triac=1
				pauseus 50
				triac=0
   	     	endif
    else
 		     triac=0
    endif
@ INT_RETURN
P.S. I am using full wave with few high value resistance connected to phase and zeners to drop the voltage further.