Light dimmer not working


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2004
    Posts
    440

    Default Light dimmer not working

    I am unable to get the following code to work properly.
    Full brightness and off work however in between the 7 1/2 watt test light bulb flickers in place of dimming.
    A scope shows the half wave signal input on pin 3 is cycling between 0 and 4 VDC.
    I have tried both a MOC3043 optoisolater and a CX240D5 solid state relay to directly drive the bulb.

    What is wrong with this setup?

    Norm




    Code:
      ' Lamp dimmer
        ' ===========
        '
        ' File name : LampDim.bas
        ' Company : Mister E
        ' Programmer : Steve Monfette
        ' Date : 23-12-2004
        ' Device : PIC12F675
        '
        '
        ' This program is use to dim intensity of an AC line load
        ' like lamp, motor and other.  Developped for 60 Hz line.
        '
        ' This allow to increase or decrease intensity.
        ' If the user doesn't held at least 0.5 sec:
        '    1. "Increase" : we will set the output for full brightness
        '    2. "Decrease" : we will turn off the output
        '
        '
        ' The software need :
        '     1. A full wave signal from the AC line on GP4
        '
        ' The software use :
        '     1. TIMER1 overflow to check if pushbutton are hold for
        '        more than 0.5 Sec
        '     2. Interrupt on GP4 (AcLine input) to synchronise Triac
        '
    
      '<FL_PIC12F675>'
      '<FL_MPASM>'
      '<FL_PBPW>'
      '<FL_PREPBP3>'
    
        '        Device programming mode and hardware definition
        '        ===============================================
                 ' Using Internal Clock, no clock out
                 ' Enable Watch dog timer
                 ' Disable MCLR pin
                 ' Enable Power-up timer
                 ' Enable Brown-out detect
                 '
      @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _PWRTE_ON & _BODEN_ON
                 '
                 '
      TRISIO = %11111011
      OPTION_REG.7=0	' Enable pull-ups
      WPU=%00000011	' Enable pull-ups on GP0, GP1
      CMCON=7	' Disable analog comparator
      ANSEL=0	' Disable analog converter
    
      Pb_Inc	var	GPIO.0 ' Input for INCREMENT/ON push button
      Pb_Dec	var	GPIO.1 ' Input for DECREMENT/OFF push button
      Triac	var	GPIO.2 ' Output to TRIAC gate
      ACLine	var	GPIO.4 ' Input for the FullWave rectify AC line
        '
        '        Software definition
        '        ===================
                 '
                 '
                 '
      MaxDelay                    var word
      TriacDelay                  var Word
      Debounce_AutoRepeatDelay	var	word
      FullBright                  var bit
        '
        '
        '        Interrupts definition
        '        =====================
                 '
                 '
                 '
      INTCON=%10001000 ' Enable interrupt on GPIO change
      IOCB.4=1	     ' Enable interrupt on GP4 change
      PIE1.0=0 	     ' disable TMR1 overflow interrupt
      T1CON=%00110100  ' Set TIMER1
    				 ' prescaler 1:8
    				 ' internal clock (Fosc/4) 1MHZ
    				 ' synchro internal
    				 ' we will use TIMER1 overflow
    				 ' $ffff * 8* (1/(4MHZ / 4)) = 0.524 Sec
      ON INTERRUPT GOTO ACDetect
       '
       '          Hardware and variable initialisation
       '          ====================================
                  '
                  '
      Maxdelay=6000 ' Set Maximum delay (set to 8000 for 50Hz)
      FullBright=0  ' disable Full Brightness flag
      triac=0       ' disable Triac Gate
      triacdelay=0  ' Set delay to minimum
      gosub ResetTimer1 ' reset Timer1
       '
       '      Main
       '      ====
       ' Get entry from user to Increment of Decrement intensity
       '
       '
      start:
       '
       ' Test Increment push button
       ' --------------------------
       ' If hold more than .5 Sec, increment triac gate delay by 500 uSec
       ' case else Full brightness at output
       '
      while Pb_inc=0
        gosub TestTimer1 ' test status of TIMER1
        while (Pb_inc==0) AND (PIR1.0==0) 'loop while holding push button
    									  'and no TIMER1 overflow
    
        wend
    
        if PIR1.0==1 then ' If timer overflow (pushbutton hold for > 0.5 sec),
          T1CON.0=0     ' disable TMR1
          gosub Debounce_AutoRepeat
          if (triacdelay<Maxdelay) then
            triacdelay=triacdelay+500 'increment Triac gate delay
          else
            triacdelay=maxdelay ' if triacDelay>MaxDelay,
            fullbright=1        ' set the full brightness Flag
          endif
        else
          triacdelay=maxdelay ' If pushButton was hold less than .5 sec
          Fullbright=1 ' Set the full brightness flag
        endif
      wend
      gosub ResetTimer1
       '
       ' Test Decrement push button
       ' --------------------------
       ' If hold more than .5 Sec, increment triac gate delay by 500 uSec
       ' Case else, turn off output
       '
      while Pb_dec=0
        gosub TestTimer1 ' Test status of TIMER1
        while (Pb_dec==0) AND (PIR1.0==0) 'loop while holding push button
    									  'and no TIMER1 overflow
    
        wend
    
        if PIR1.0==1 then ' If timer overflow (pushbutton hold for > 0.5 sec),
          T1CON.0=0 ' disable TIMER1
          gosub Debounce_AutoRepeat
          if (triacdelay>0) then
            Fullbright=0 ' Reset TRIAC always ON flag
            triacdelay=triacdelay-500
          endif
        else
          Fullbright=0 ' Reset TRIAC always ON flag
          triacdelay=0
        endif
      wend
      gosub ResetTimer1
      goto start
        '
        '
        '     TestTimer1
        '     ----------
        '
        ' Enable TIMER1 if :
        '    not enable and not in overflow
        '
      TestTimer1:
      if (T1CON.0==0) AND (PIR1.0==0) then 'if TIMER1 not enable
        									 'and TIMER1 not overflow
        T1CON.0=1 'enable TIMER1
      endif
      return
        '
        '
        '     ResetTimer1
        '     -----------
        '
        ' Subroutine to clear Timer1
        '    1. Overflow flag
        '    2. Disable Timer
        '    3. Clear counter
        '
      ResetTimer1:
      PIR1.0=0  'clear timer overflow
      T1CON.0=0 'disable timer
      TMR1L=$00 'clear counter
      TMR1H=$00 '
      return
        '
        '
        '     Debounce_AutoRepeat
        '     -------------------
        '
        ' Subroutine to debounce push button.
        ' Also provide kind of auto-repeat when push button
        ' are held down.
        '
        ' each delay = 20 mSec
        ' Use of PAUSEUS to be sure getting ACLine interrupt
        '
      Debounce_AutoRepeat:
    
      for Debounce_AutoRepeatDelay=1 to 2000
        pauseus 10
      next
      return
        '
        '
        '       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
          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
    
      END
    Last edited by Normnet; - 30th December 2012 at 10:48.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,580


    Did you find this post helpful? Yes | No

    Default Re: Light dimmer not working

    Hi Norm,
    The MOC3043 is a zero crossing triac driver, meaning it will only switch when the AC at ~0V - not that great for phase angle controller. The datasheet for the CX240D5 is a little bit unclear as it says zero crossing (for resistive loads) and random fire (for inductove loads) but it doesn't say if it's two different versions or if it just works in two different ways depending on the type of load connected. Anyway, a light bulb is pretty resistive so.

    The MOC3022N shown in the schematic is a random fire opto-triac and should work.

    Another thing to look out for is that a triac may need a certain current to actually stay ON. So if you only pulse the gate of the triac the small 7.5W load may not provide enough current to allow the triac to stay on untill next zero-crossing. Not saying this is the case here but something to be aware of.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Light dimmer not working

    +1 ...

    the zero crossing opto triacs or SSR's won't do anything good on this one !!!

    change for MOC 3023 or " 3023 " root ...

    BTW ... did you understand how the dimmer works ???

    and do not forget to wish Steve a Happy New Year !!!

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Re: Light dimmer not working

    and the ACDetect routine will need to be changed... burst mode as it is right now... not sure why this version is still hanging around... might have forgot to upload the right version again lol
    Steve

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

  5. #5
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Light dimmer not working

    I had suspected the zero crossing.

    Steve's code is from my archived files (12-23-2004).
    Where can I download a more recent version?
    The newest post I have found so far is PICDIM Lamp Dimmer for the PIC12C508 - PICREF-4

    Thanks for the fast help!
    This board rocks.

    Norm

  6. #6
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Light dimmer not working

    I have an older Triac the L2004L3.

    What voltage AC or DC and value should be applied to the gate?
    At present I am only looking for a full on or off condition.

    Norm

  7. #7
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Light dimmer not working

    General information can be found here: http://en.wikipedia.org/wiki/TRIAC
    Information specific to your device can be usually found on the manufacturer's website.
    Google is your friend.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,038


    Did you find this post helpful? Yes | No

    Default Re: Light dimmer not working

    Norm, it seems that this is a sensitive triac.

    On page 2 it says that for a trigger pulse of 1.3V and a 100mA current the holding current of the load will be 5mA only.

    But as you can see it needs 100mA trigger pulse!

    On page 4 on the top diagram, there is a relation of the temperature to the holding current, which fall as the temperature rises.

    To seems more appropriate to drive it with a small transformer, so that a 5V pulse will be lowered to 1.3 but with an increase in current drive. A 5V at 20mA will be transformed to a 1.3 at about 70mA.

    HTH,
    Ioannis

  9. #9
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Light dimmer not working

    Quote Originally Posted by mister_e View Post
    and the ACDetect routine will need to be changed... burst mode as it is right now... not sure why this version is still hanging around... might have forgot to upload the right version again lol
    I now have an optoisolator MOC3021 and a triac Q4010L4 which switch the lamp on and off OK however no dimming.
    An LED connected to the PIC output to the optoisolator however does brighten and dim.
    What needs to be changed on the ACDetect routine?
    I did a site search for a newer version but no luck.


    Norm

Similar Threads

  1. Light dimmer problem
    By FromTheCockpit in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 9th July 2012, 13:36
  2. Dimmer
    By BMIelektonik in forum mel PIC BASIC Pro
    Replies: 67
    Last Post: - 10th August 2010, 17:16
  3. Dimmer switch
    By iugmoh in forum Off Topic
    Replies: 4
    Last Post: - 20th March 2009, 17:02
  4. 50hz sync for light dimmer
    By tirithen in forum General
    Replies: 2
    Last Post: - 6th September 2008, 20:29
  5. Dimmer Circuit
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th January 2007, 15: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