Dimmer


Closed Thread
Results 1 to 40 of 68

Thread: Dimmer

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink Got it !!!

    Hi, Reven

    Just understand what the interrupt routine does instead of should have done ...

    ""
    ' ACDetect
    ' --------
    '
    ' Interrupt routine called by ACLine (GP4) pin state change
    '
    disable
    ACDetect:
    if ACline==1 then ' Check for rising edge of AC signal
    if triacdelay > 0 then
    Triac=1 ' Activate TRIAC

    Alain's : ;;; No,No,No ... here we have to wait for ( Maxdelay - Triacdelay ) !!! THEN fire the Triac for, say, 20µs ... then let things quiet.

    if FullBright==0 then ' In case Brightness flag is not set
    pauseus triacdelay ' do the selected delay
    triac=0 ' Disable TRIAC
    endif
    else
    triac=0
    endif
    endif
    INTCON.0=0 ' Clear GPIF (interrupt on GP4 change)
    resume
    enable

    ""


    *** This part of program smells to have been taken from a heather using burst mode dimming ...

    Sorry, Steve ... je t'aimais bien ( avec la musique de circonstance ... )

    Alain
    Last edited by Acetronics2; - 13th December 2005 at 12:15.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm, sorry all. something should be wrong in what i posted. I used that program in various app and it worked... let me the time to return at home(Next week) and i'll compare the posted version and what i use...

    Many thousands of appologies.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by mister_e; - 18th December 2005 at 11:39.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Reven's Avatar
    Reven Guest


    Did you find this post helpful? Yes | No

    Thumbs up Ok!

    First, I write something like this:

    ' Interrupt routine called by ACLine (GP4) pin state change
    disable
    ACDetect:

    if ACline=1 then ' Check for rising edge of AC signal

    pauseus triacdelay ' do the selected delay
    Triac=1 ' Activate TRIAC
    pauseus 20
    Triac=0 ' Disable TRIAC

    endif


    INTCON.0=0 ' Clear GPIF (interrupt on GP4 change)
    resume
    enable



    and because I use half wave signal from the AC line on GP4, finaly something like this:


    ' Interrupt routine called by ACLine (GP4) pin state change
    disable
    ACDetect:

    if ACline=1 then ' Check for rising edge of AC signal

    pauseus triacdelay ' do the selected delay
    Triac=1 ' Activate TRIAC
    pauseus 20
    Triac=0 ' Disable TRIAC


    'send a second pulse to triac,after 10ms, like the full wave
    pause 10
    Triac=1 ' Activate TRIAC
    pauseus 20
    Triac=0 ' Disable TRIAC


    endif


    INTCON.0=0 ' Clear GPIF (interrupt on GP4 change)
    resume
    enable





    Again, thanks all of you!
    Reven

  5. #5
    Join Date
    Sep 2006
    Location
    Florida, USA
    Posts
    94


    Did you find this post helpful? Yes | No

    Default Problem with config fuse

    Hello - I am trying to compile the dimmer program and I am getting an error at the CONFIG fuse:

    @ __CONFIG _INTRC_OSC_CLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF

    It's giving me:

    Error ACLAMP~1.ASM 60: [235] opcode expected instead of '__config'

    Can anyone tell me what I am doing wrong?

    PBP 2.43 - PIC12F675

    Atom058

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Can anyone tell me what I am doing wrong?
    You're using PM instead of MPASM to compile your code

    if you want to use PM, you must use the @ DEVICE directive instead.

    See the Faq about that. There's a whole thread about how to set config fuses in your code.
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Sep 2006
    Location
    Florida, USA
    Posts
    94


    Did you find this post helpful? Yes | No

    Talking

    You're the MAN! Totally missed that one. Thanks!

  8. #8


    Did you find this post helpful? Yes | No

    Question With DT_Interrupts added

    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.

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by FromTheCockpit View Post
    P.S. I am using full wave with few high value resistance connected to phase and zeners to drop the voltage further.
    What size zeners are you using?

    The INT input is Schmidt trigger, so it has to get above 4.0V to trigger the interrupt.
    It may not make it, or cause a delay after zero-crossing that could affect the timing.

    Have you tried it without the zeners?
    DT

  10. #10


    Did you find this post helpful? Yes | No

    Question

    Quote Originally Posted by Darrel Taylor View Post
    What size zeners are you using?

    The INT input is Schmidt trigger, so it has to get above 4.0V to trigger the interrupt.
    It may not make it, or cause a delay after zero-crossing that could affect the timing.

    Have you tried it without the zeners?
    Hello Darrel, I made a slight mistake in the above post, it's not full wave rectified. The circuit goes like this - Phase->1.5Meg->12V zener->1K->4.7V zener->3.3Meg->PIC

    No I have not tried it without zeners yet. Will it be OK to remove the zeners from the above equation - the place where I am gets heavy voltage fluctuations - The variation could be from 170V - 280V AC (I am serious!)

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    According to the simulator, your resistors/zeners should give 4.4v, so that's ok. (but you shouldn't need the zeners)

    mister-e was using INT ON CHANGE, so it triggered on both edges.
    To get INT to do the same thing you have to toggle INTEDG on each interrupt.

    This modification of the handler works in the SIM.
    Code:
    INTEDG  VAR OPTION_REG.6
    ; ...
    
    ACDetect: 
        if INTEDG then
            if triacdelay > 0 then
                if triacdelay=8000 then
                    triac=1 ' Activate TRIAC
                else
                    maxdelay=8000-triacdelay
                    pauseus maxdelay
                    triac=1
                endif
            else
                triac=0
            endif
        else
            if triacdelay != 8000 then triac=0
        endif
    
        INTEDG = !INTEDG
    @ INT_RETURN
    In the scope image, the blue line shows the triac ON time.
    It's only on during the positive half of the cycle.
    Doesn't seem right, but that's the way mister-e had it.

    Name:  dimmer.JPG
Views: 3678
Size:  137.5 KB

    HTH,
    DT

Similar Threads

  1. PICDIM Lamp Dimmer for the PIC12C508 - PICREF-4
    By charudatt in forum General
    Replies: 8
    Last Post: - 2nd September 2015, 07:14
  2. Dimmer switch
    By iugmoh in forum Off Topic
    Replies: 4
    Last Post: - 20th March 2009, 16:02
  3. Ideas on ir-code for dimmer
    By tirithen in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th February 2009, 23:22
  4. 50hz sync for light dimmer
    By tirithen in forum General
    Replies: 2
    Last Post: - 6th September 2008, 19:29
  5. Dimmer Circuit
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th January 2007, 14:37

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts