Light dimmer not working


Results 1 to 9 of 9

Threaded View

  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 09:48.

Similar Threads

  1. Light dimmer problem
    By FromTheCockpit in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 9th July 2012, 12:36
  2. Dimmer
    By BMIelektonik in forum mel PIC BASIC Pro
    Replies: 67
    Last Post: - 10th August 2010, 16:16
  3. Dimmer switch
    By iugmoh in forum Off Topic
    Replies: 4
    Last Post: - 20th March 2009, 16:02
  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 : 1

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