PDA

View Full Version : Light dimmer not working



Normnet
- 30th December 2012, 09:39
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 (http://www.fairchildsemi.com/ds/MO/MOC3042M.pdf) optoisolater and a CX240D5 (http://www.crydom.com/en/Products/Catalog/c_x.pdf) solid state relay to directly drive the bulb.

What is wrong with this setup?

Norm

http://norm-online.net/2012-12-30_lampdimer.JPG



' 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

HenrikOlsson
- 30th December 2012, 10:05
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.

Acetronics2
- 30th December 2012, 10:17
+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 ??? :rolleyes:

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

Alain

mister_e
- 30th December 2012, 10:30
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

Normnet
- 30th December 2012, 11:53
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 (http://www.picbasic.co.uk/forum/showthread.php?t=1026)

Thanks for the fast help!
This board rocks.

Norm

Normnet
- 1st January 2013, 14:03
I have an older Triac the L2004L3. (http://www.littelfuse.com/data/en/Data_Sheets/Littelfuse_Thyristor_Lxx04xx_Qxx04xx.pdf)

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

Charlie
- 1st January 2013, 21:22
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.

Ioannis
- 2nd January 2013, 09:32
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

Normnet
- 13th January 2013, 17:26
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 (http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/MOC302x.pdf) and a triac Q4010L4 (http://www.littelfuse.com/data/en/Data_Sheets/Littelfuse_Thyristor_Qxx10xx_Qxx10xHx.pdf) 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