PDA

View Full Version : Light dimmer problem



FromTheCockpit
- 5th July 2012, 14:49
I need some help in finding out how to connect zero-detector circuit to my PIC.
I do not wish to use any transformer in this circuit.

The circuit gets it's 12V from an external source which is reduced to 5V using 7805 in my circuit. I tried connecting 4 x 4.7Meg directly from mains to my PIC just to check if it works and it does, but not perfectly as I need to supply full-wave rectified voltage.

The problem:

I am not sure of where to connect the ground connection of the bridge rectifier.
Once the ground is connected to where it should, should I use the same resistance from the +ve side of the bridge to the PIC?

dhouston
- 5th July 2012, 15:15
Look for Microchip AN236 X-10® Home Automation Using the PIC16F877A. It includes schematics which should cover everything you need to know.

FromTheCockpit
- 5th July 2012, 16:01
Thanks. I checked your referred document. It doesn't seem to solve my problem. It does not provide full-wave rectification.

dhouston
- 5th July 2012, 20:12
Full-wave rectification of what? You said you were using an external power supply.

Numerous people have used the circuits in that appnote to control triac dimmers using the X10 powerline protocol.

FromTheCockpit
- 5th July 2012, 20:23
OK :smile:
I managed to tweak the code to fit in the direct resistance from the mains without the need for the bridge. The problem of flickering is still there, though not a lot but is still noticeable. Is something wrong with the code? I want to control 2 channels minimum with 1 IC, so I have set timer0 interrupt to happen @ 340uS approximately. This gives me approximately 29 steps for a 10mS interval. I just toggle the trigger edge at every Zero Crossing.



DEFINE OSC 20 ' OSCCON defaults to 20MHz on reset
DEFINE NO_CLRWDT 1
Include "modedefs.bas"

#CONFIG
ifdef PM_USED
device pic16F676, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
else
__CONFIG _HS_OSC & _WDT_OFF & _MCLRE_OFF & _BODEN & _CP & _CPD
endif
#ENDCONFIG


'----------Other pins Declared Here--------------
Dimmer1 VAR PortA.0 ' dimmer channel 1
Dimmer2 VAR PortC.0 ' dimmer channel 2

'----------Variables declared here----------------
Dimmer var Byte[2] ' timer value for 4 dimmer channels
Count var Byte ' Dimmer working variable

define INTHAND _ISR

Goto main

ISR:
asm
' Context saving happens here

btfsc INTCON, INTF
goto ZeroCrossingInt

T0Over
bcf INTCON, T0IF ; clear the timer overflow flag
movlw 203
movwf TMR0
incf _Count ; Increment Count

; check if channel1 value is reached
movf _Dimmer+0,w
subwf _Count,w
btfsc STATUS,C
bsf _Dimmer1

; check if channel2 value is reached
movf _Dimmer+1,w
subwf _DimrWork,w
btfsc STATUS,C
bsf _Dimmer2

goto EndInt


Set_Bit
bsf OPTION_REG,6
clrf STATUS
Goto EndInt


ZeroCrossingInt
bcf INTCON, INTF ; clear the interrupt
clrf _Count ; Dimmer Working variable

movlw 0
bcf STATUS,Z
addwf _Dimmer+0,w
btfss STATUS,Z
bcf _Dimmer1

movlw 0
bcf STATUS,Z
addwf _Dimmer+1,w
btfss STATUS,Z
bcf _Dimmer2

bsf STATUS,RP0
btfss OPTION_REG,6
Goto Set_Bit
bcf OPTION_REG,6
clrf STATUS


EndInt
; Context Restore here
retfie
endasm

main:
'----------Processor Initialisation---------------
PAUSE 50
TRISA = %001100
TRISC = 0
CMCON = 7
ANSEL = 0
OPTION_REG = %10000100
PORTA=%001100
PORTC=0

INTCON= %10110000
' Global interrupts enabled
' Timer0 interrupt enabled
' Zero Crossing interrupt enabled
' Flags are cleared


DIMMER[0]=0 : DIMMER[1]=25

Pause 3000
Start:
DIMMER[0]=DIMMER[0]+1
DIMMER[1]=DIMMER[1]-1

Pause 3000

If Dimmer[0]=25 then
Dimmer[0]=0 : Pause 3000 : Endif
If Dimmer[1]=0 then
Dimmer[1]=25 : Pause 3000 : Endif

Goto start

END


I am using 16f676 and 4 x 4.7Meg from Mains - Direct to PortA.2.

FromTheCockpit
- 6th July 2012, 16:59
Full-wave rectification of what? You said you were using an external power supply.

Numerous people have used the circuits in that appnote to control triac dimmers using the X10 powerline protocol.

Full wave rectification of mains, I needed it for Zero-Crossing of mains. External power supply only provides 12V to my circuit. I checked the X-10 circuit but it has it's own transformer-less power supply and from there direct resistance is coming for Zero-crossing without any sort of rectification. I don't know much about X-10 so I am sorry if there is something I missed which you were trying to point out.

Anyways, since I have modified the code now the problem is of flickering of the bulb. Any comments about could be wrong?
:rolleyes::rolleyes:

dhouston
- 6th July 2012, 19:00
Full wave rectification of mains, I needed it for Zero-Crossing of mains.
You do not need full wave rectification for zero-crossing detection. The circuit shown on p3, FIG3 of AN236 works fine for zero crossing. The appnote even details the inaccuracies inherent in the circuit, saying...
On a rising edge, RB0 will go high about 64 µS after the zero-crossing, and on a falling edge, it will go low about 16 µS before the zero-crossing.You'll find similar inaccuracies in most methods for zero-crossing detection. Their calculations are for 120VAC/60Hz. You'll need to adjust for 220V/50Hz (and maybe use a larger current limiting resistor).

One possible cause of flicker is failing to compensate for inaccurate zero crossing detection.

You can ignore the X10 communications circuitry and code but I suggest you study the code used for the triac dimmer circuit in AN236 (p6) or in the referenced PICREF-4 Reference Design, “PICDIM Lamp Dimmer for the PIC12C508”. The Microchip engineers frequently know what they are doing. ;)

ardhuru
- 7th July 2012, 07:17
Instead of feeding the mains to the pic pin, drive an opto like the PC814.

This has 2 LEDs in anti-parallel at the input, so you'd get 2 pulses for each mains cycle, one each for positive and negative. This will also give you a bonus of isolating your circuit from the mains.

Regards,

Anand Dhuru

FromTheCockpit
- 7th July 2012, 14:55
I played around with the circuit a little and it seems that the problem is with the circuit only.
My reason for saying this is because as soon as I connected the ground of my oscilloscope with the 12V ground which comes from an external source (smps), the flickering suddenly stopped and glowing of the bulb at different brightness levels was just as expected, smooth and perfect. As soon as I removed the ground of my oscilloscope the flickering started again.

FromTheCockpit
- 7th July 2012, 15:25
Instead of feeding the mains to the pic pin, drive an opto like the PC814.

This has 2 LEDs in anti-parallel at the input, so you'd get 2 pulses for each mains cycle, one each for positive and negative. This will also give you a bonus of isolating your circuit from the mains.

Regards,

Anand Dhuru
Thanks for the reply. What resistance values normally goes for the opto side of the PC814 and what should be the wattage of this resistance values. I am @ 240VAC

ardhuru
- 9th July 2012, 10:12
I'd used 100K, 1W on 240 VAC.

Reducing the resistance would get you sharper edges, but then one needs a resistance of a higher wattage, so I finally settled on these, and its worked great for me.

Megahertz
- 9th July 2012, 10:49
I wonder if 4n25 can be used the same way?
(with 100k direct to Live and other end to neutral)

ardhuru
- 9th July 2012, 12:36
Looks like the 4n25 has only 1 diode at the input. You'd get only 1 pulse per cycle. If thats acceptable, I dont see why the 4n25 shouldnt work.

Regards,

Anand