PDA

View Full Version : Dimmer



BMIelektonik
- 28th October 2005, 23:01
What would be the solution for following problem. I want to controll 2 opto SCR connected to RB1 RB2. I want one to increase light at the same time as the other Decrease light. The zero detection works perfect and also the delay for the ignition puls for scr1 but what about no 2.How do I solve it with Picbasic pro

Thanks





DELAY_1 = 8500 : us

POS_FLNK:IF ZERODETECT = 0 Then POS_FLNK
NEG_FLNK:IF ZERODETECT = 1 Then NEG_FLNK
DELAY_1 = DELAY_1 - 1

IF DELAY_1 < 7000 Then DELAY_1 = 7000

PauseUs DELAY_1
High out_1
"High out_2"
PauseUs 100
"Low out_1"
Low out_2

GoTo POS_FLNK

ardhuru
- 29th October 2005, 18:28
Hi,

Since you want to basically complement the 2 outputs, the timing part is easy; assuming you are on 50 Hz, your circuit should see a zero crossing every 10 ms. Therefore, if the delay for one output is X, the other would be (10000-X) us.

Now, the difficult part is that at times X will be less than (10000-X), and more than (10000-X) the other times.

You'll need to therefore determine the sequence of servicing the 2 outputs.

E.g., IF X < (10000-X) THEN PAUSEUS X, SWITCH ON TRIAC1, PAUSEUS (10000-X), SWITCH ON TRIAC2.

IF X > (10000-X) THEN PAUSEUS (10000-X), SWITCH ON TRIAC1, PAUSEUS X, SWITCH ON TRIAC2.

Take care of the situation when X = (10000-X) !

Also allow for the time taken for the actual execution, or else you'll miss the subsequent zero crossing. This you could do by taling the half cycle width to be, say, 9000 us seconds instead of 10000.

Hope this helps!

Regards,

Anand Dhuru

BMIelektonik
- 31st October 2005, 10:16
What about the timing of the trigger pulse when they meet in the center "50%dutycyle". At one point the pic will be busy with 100us pulse for SCR1 and at the same time SCR2 should be triggerd. this might give some flicker. maybe the solution would be to make the dimfunction in lets say 10 or 20 steps and then take care of the overlap instead of a linear dimfuntion


Thanks

ardhuru
- 31st October 2005, 13:57
I've found that the trigger pulse can be as narrow as 5uS; therefore the flicker you refer to is imperceptible.

Also, you could put in a line that caters specifically to this situation; e.g., if X = (1000-X) then High Out1 - Pauseus 5 - Low OUt1 - High Out2 - Pauseus 5 - Low Out2.

BTW, I am using traics, not SCRs. Any particular reason you are using SCRs?

Regards,

Anand

BMIelektonik
- 31st October 2005, 16:16
I am using a opto triac Sharp S216S01 so its not a SCR. have to check what the shortest triggpulse can be

Thanks for you input

sougata
- 31st October 2005, 18:11
Hi there,

Which PIC are you using ayway and how are you detecting the zero cross.

It is also important if you are detecting every or alternate zero crosses.

If you are using an interrupt based routine then do the following

1. Play with Timer0 and reset it every zero cross. All turn off the outputs. Its best to do it in assembly.
2. Thus your timer functions as a digital ramp generator now use to loop to detect if the timer has reached the desired value. In this way you do not have to care about the glitches.
3. A 5us time might be not enough. It is best to keep the outputs latched till the next zero cross. This will also let you use low loads under the latching current of the SCR.

Regards

Sougata

BMIelektonik
- 31st October 2005, 21:08
I use a 16F84 8Mhz.Zero detection with an opto coupler after rectifyer 100Hz and then a schmittrigger to get the levels right. Have a <1ms puls around zero.
It might be a good idea to make the pulse as long as it can be ,and bring it low just before zero. Sharp "s216s01" recomends 1mS min ,
Assembly might be the best way of solving this ,since my goal is to control 5 outputs , I start with one then work my way up

thanks

George
- 31st October 2005, 21:27
I use a resistor as zero detect, 1 meg from phase straight into the port, I then have a 470K resistor on the pin next door to it and swing the bias in an opposite direction to the mains ie:

GPIO.5 is the output pin with the 470K on it - trigger is GPIO.4 which is connected upto the 1M which goes straight to phase. The triac is triggered by a BC327 and i trigger by turning pic from high impedance to low by changing from input to output.

LowSide: 'look for trigger points and trigger triac

IF trigger = 1 Then lowside 'wait for phase to go low
GPIO.5 = 0 'weight input to sense zero crossing
PauseUs dim 'wait for dim period
Output triac 'fire triac
triac = 0
PauseUs 400
Input triac


HighSide:

IF trigger = 0 Then HighSide
GPIO.5 = 1
PauseUs dim
Output triac
triac = 0
PauseUs 400
Input triac

GoTo start

sougata
- 1st November 2005, 00:58
Hi there,

Having the opto-triac driven till the zero cross would take care of inductive loads also.
Provide me with the following :

1. How the outputs would be controlled? (Internal timer /push button etc)
2. Your line frequency

I would try to play with the interrupt part simulate it.

Regards

Sougata

BMIelektonik
- 1st November 2005, 07:15
What i wanted to do is a controller for some decorative lights. I want to make a pattern where light fade in / out.
Powersupply = 50 hz 220V

My first plan was to fade in/out between 2 limits on 1 channel "this works ok".
then i wanted to try 2 channels to push the limit "a bit"
Now I can see this extend to like 5 output creating a wave like motion.
may be it will end up with a lot of assembly code and also lower the demands
on "linear control" and go over to fixed steps and a data table


could even parallell 5 pics to achive my goal this would be the last solution

Thanks

sougata
- 1st November 2005, 10:05
Hi,

Understood. The only problem is that I don't have 16F84 ready. However it should work. Do you have a PIC18F452 ready? This is where I am most comfortable. I also have 16F676, 16F73, 16F619 handy. BTW you don't need five PICs.

Regards

Sougata

Ioannis
- 1st November 2005, 10:41
I have not done this but may be my idea could help.

Using Interrupts, when there is pulse from zero-crossing detector, you could succeed in your house keeping, timing that is.

Entering the ISR, the relevant registers would increment or decrement according the flags you have set in your main program. So there is accurate timing to fire every SCR even 5 or more since the ISR would be triggered every 10ms.

Ioannis

sougata
- 1st November 2005, 18:26
Hi Everybody,

It is possible to trigger n numbers of SCRs within the 10ms(50Hz) time frame. My DMX Dimmer handles 48 of them. There I use a bubble sort algo and actually different interrupt sources. One for syncing the timer with ac, one for firing, listening to USART, fader read and so on. All this handled by two PICs 18F452 @ 40MHZ. The second one is mainly for the download and running of pattern or randomizing them.

I am working on a simplified version using a PIC16F84A (Yes I found one) and trying to acheive a 100% PBP code using the On-Interrupt function. I have no idea about the latency till I get my code running tomorrow and checking on scope. Even the asm interrupt would be quite easy.

You see with a clock frequency of 8MHz--> 2MHz(Fosc/4) / 128 (prescale) / 100 (reset every 10miliseconds), the timer0 would count 156 (50Hz) or 130(60Hz max). Compare this constantly in a loop with preset or increasing / decreasing values and fire the appropriate port.On interrupt

1. Clear all outputs
2. Reset Timer0
3. Return

Thats it. It will be done before the new cycle begins!!!!!!!!!2MIPS

I am working on a two channel version and let you all guys out there juice it up.

BTW most of the PICs have an inbuilt Schmidt Trigger on input ports so the interfacing is pretty easy. I use a couple of resistors a diode bridge and an optocoupler to derive the zero cross sync. It is accurate without any phase latency (as in the case of transformer based).Direct AC feed through high value resistor is also possible and practical but the circuit becomes live and is not recommended for experimenters.(I use it in my remote controlled fan/light dimmer to keep costs under control. It retails for about 18USD!!!!)

The toughest part is possibly randomizing the paterns or using pschychedelic effect with beat detection within the scope of the chosen processor (clock code space, instruction set).

We are having Diwali (the festival of lights) and a holiday to work with a fun project. The entire town is having myriads of lighting displays so why not doing one for the forum. Happy Diwaly to guys out there.

It is midnight now and I can get my hands on the PIC only tomorrow when I get the lunch break. So till then....

Bye!!

Regards

Sougata

BMIelektonik
- 2nd November 2005, 20:35
Hello everybody
What happend here , did the the project stall

RGDS
BG

sougata
- 5th November 2005, 04:15
Sorry guys,

I could not keep up to my commitments. I lost a very near and dear friend. Give me a couple of days, I will get back with something working.

Regards

mister_e
- 5th November 2005, 16:30
A previous thread ==> http://www.picbasic.co.uk/forum/showthread.php?t=1026

Schematic + code (Dimmer.zip) ==> http://www.melabs.com/resources/samples.htm#submitted

Maybe not exactly what you need but should be enough to start

sougata
- 17th November 2005, 08:44
Sorry guys although I did a testing for a single channel version, I couldn't test the five channel one. I am posting the circuit and the code. I request the PIC gurus to have a look at the code and point the flaws. Please do read the notes.doc file for important information.

Regards

Sougata

BMIelektonik
- 21st November 2005, 21:34
Thank´s for the code Sougata. I will test it later. However I wrote some code myself and it works.I did not use Interupt´s.. There are some similaritys to what you wrote.

But As i say I will try out your code later

thanks
BG

Reven
- 10th December 2005, 19:59
Can someone help me?
I build the circuit from (Dimmer.zip) ==> http://www.melabs.com/resources/samples.htm#submitted,
and I have this problem:
If I press the increase button (<500ms) ,the lamp go on,full and if I press the decrease button, the lamp go off (normal).
If I try to decrease the intensity from full on, or increase the intensity from off state, the lamp it fllash fast without decreasing/increasing brightness, until the lamp go on or off.
On GP4 I have 50hz, and value at the pin GP2 while press the buttons, increment/decrement pulses by 500 uSec,until the maximum/minimum value, everything look ok.

Any Help?

Thanks!

Ioannis
- 10th December 2005, 20:58
Have you adapted the program for the 50Hz line freq?

Ioannis

Reven
- 11th December 2005, 01:29
If you mean the maxdelay value, yes.

But if you conect osciloscope and take a look at the pulses from the pic output and the 50Hz at the same time, you will see that the maxdelay value is only for the maximum brightness.

mister_e
- 11th December 2005, 08:56
Looks like a bad signal level to me...

What is the voltage of your transformer?
What are your R3 and R4 value?

Try decrease R3 and post your results.

Reven
- 11th December 2005, 12:01
This is the osciloscope measures from the GP4 (AcLine input), and from GP2 (Output to TRIAC).
I use tranformer 8Vac, R3=4k7 and R4=10k.

Look the pictures from 0 to 4. Is from value off to on through 3 steps.


But the lamp still flashing...

HenrikOlsson
- 12th December 2005, 06:58
Reven,
I've not used that circuit or code you are reffering to but by just looking at your waveforms it seems that the triac is triggered at the same phase angle in case 1, 2, 3 & 4.

The triac only needs a short pulse on the gate and will then hold itself 'on' untill the AC-line crosses zero, at which point it will turn 'off'. That short pulse should be delayed a certain amount of time from the zero crossing.

On your scope pics the triac seems to be triggered exactly 1div from the zero crossing in all cases except full on and full off.

/Henrik Olsson.

Acetronics2
- 12th December 2005, 09:18
Hi, reven

Henrik is right ...

Here, the pulse length is not the thing to be variable.

but you must vary the time between zero voltage detection and triac gate firing ...

Long time = weak light
short time = full light

remember once the triac is turned on it stays turned ON until current becomes null.


Alain

Here, you had programmed a ... DC Dimmer !!!

Reven
- 12th December 2005, 21:51
I think you have right...
As Henrik says ,now the triac is triggered at the same phase angle in all cases.
I must change my code to put the pulse position in a variable.
Thanks all of you!
I will inform you about my progress!




BTW, take a look at the code,bacause I checked it many times and I could not find where the problem is.

http://www.picbasic.co.uk/forum/attachment.php?attachmentid=160&d=1103787743

Thanks again,
Reven

Acetronics2
- 13th December 2005, 10:13
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

mister_e
- 16th December 2005, 16:25
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.

mister_e
- 18th December 2005, 11:32
Can't wait to return home... use the following ACDetect routine instead.
this should work.


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.

Reven
- 18th December 2005, 15:56
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

Atom058
- 28th September 2006, 01:20
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

mister_e
- 28th September 2006, 01:34
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

Atom058
- 28th September 2006, 02:00
You're the MAN! Totally missed that one. Thanks!

Atom058
- 11th October 2006, 02:52
Hello - I am trying to build the Dimmer Circuit as described and was wondering if someone could critique the attached circuit diagram. I have built this and do not seem to be able to get it to work and if it is not my design then it must be my code (both of which I obtained here). Any comments will be appreciated. I am using part numbers, schematic and code that are described here: http://www.melabs.com/resources/samples.htm#submitted
Thanks! Atom058

Atom058
- 11th October 2006, 02:53
Here's the schematic....

mister_e
- 11th October 2006, 03:35
%%^%^&*&!#@$! it's my silly mistake. I will have to update the whole thing soon. Use...
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1116&stc=1&d=1160534077">

You only have to move 1 wire...

PCB mod... really easy
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1117&stc=1&d=1160534528">
SORRY SORRY SORRY SORRY SORRY SORRY SORRY SORRY SORRY SORRY

Atom058
- 11th October 2006, 22:54
Mister-E - No harm done! Thanks for the quick response! I will give it a try tonight and we'll see what happens.

Atom058

Atom058
- 12th October 2006, 01:56
I was trying to program a PIC12F675 to work with this dimmer design and I am obviously missing something. I copied the code from the Dimmer example and it was not working so I moved to a breadboard to do some testing. I can not even make an output on these PIC's go high! I know I am missing something but I can't imagine what it is! Here is the code - as simple as it is:

@ DEVICE INTRC_OSC_NOCLKOUT & WDT_ON & MCLR_OFF & PWRT_ON & BOD_ON

PAUSE 500
CMCON=7 ' Disable analog comparator
ANSEL=0 ' Disable analog converter

TRISIO = %11111111
TRISIO.0 = 0
TRISIO.1 = 0
TRISIO.2 = 0
TRISIO.3 = 0
TRISIO.4 = 0

HIGH GPIO.0
HIGH GPIO.1
HIGH GPIO.2
HIGH GPIO.3
HIGH GPIO.4

Start:
GOTO Start

END

Now, correct me if I am wrong, but I should be able to measure 5V at each of the 5 outputs above. I get nothing. I have tried several PICs and get the same results. I've written hundreds of programs for different PICs and this one has beaten me. I know the solution is unbelieveabley simple, but GEEZ!

sayzer
- 12th October 2006, 03:35
...
@ DEVICE INTRC_OSC_NOCLKOUT & WDT_ON & MCLR_OFF & PWRT_ON & BOD_ON...


Hi Atom,

First thing, try these instead of the line above.



@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F675, WDT_ON
@ DEVICE pic12F675, PWRT_ON
@ DEVICE pic12F675, MCLR_OFF
@ DEVICE pic12F675, BOD_ON
@ DEVICE pic12F675, CPD_OFF
@ DEVICE pic12F675, PROTECT_OFF

These should fix your problem.


Second thing, GP3 is an input-only pin. Never goes high.



----------------------

mister_e
- 12th October 2006, 03:37
Your @ device line is faulty...
If you'e using PM to compile your code you must use something like


@ device pic12F675, intrc_osc_noclkout, wdt_on, mclr_off, protect_off


With MPASM


@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF


OUPS! SAYZER WHY YOU REPLYED AT THE SAME TIME :D

i know this one is familiar to you :D:D

sayzer
- 12th October 2006, 06:13
Hi Steve,

As you well know, it took about a month for me to figure out that this line does not work:

@ device intrc_osc_noclkout, wdt_on, mclr_off, protect_off

It should be either like
@ device pic12F675, intrc_osc_noclkout, wdt_on, mclr_off, protect_off
or
like

@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F675, WDT_ON
@ DEVICE pic12F675, PWRT_ON
@ DEVICE pic12F675, MCLR_OFF
@ DEVICE pic12F675, BOD_ON
@ DEVICE pic12F675, CPD_OFF
@ DEVICE pic12F675, PROTECT_OFF

Atom058
- 12th October 2006, 23:32
Thanks guys! I knew I would be embarrased by the solution and I was right!

OK, Now I have made the circuit change and have made the switch changes. I get the 5V outputs on pins GPIO.0 and .1 which go low when I press the up or down buttons. I do not, however, get any output from GPIO.2 which is the triac trigger. My guess is that the problem lies in the ACDetect routine. I see in previous posts that there were many references to this routine and it went through several revisions. Can someone verify that I have the correct routine?

I have attached the code as a text file and the circuit design as a pdf. Would appreciate comments.

Thanks again! Atom058

Atom058
- 14th October 2006, 22:13
Hello again - Did I stump everyone? Surely someone has a comment...

Would really like to get this working!

Thanks in advance! Atom058

mister_e
- 15th October 2006, 09:11
You have the right version.

It's suppose to work unless you have some hardware issue OR device prograemmer issue.

Atom058
- 15th October 2006, 17:28
Mister-e - Thanks! I will go over my circuit again. It helps knowing that the code I am trying to run is the correct version - I can focus my attention elsewhere. If you (or anyone else) can offer some troubleshooting ideas, they would be appreciated.

Atom058

Atom058
- 17th October 2006, 00:58
Well, I did find (part of) my problem - It was a bad solder at GPIO.4 so it was never seeing the zero crossing. Having fixed that, I now can dim the light up and down just like it is supposed to. However, (bet you saw this coming) when it is between full on and full off, it flickers randomly. The dimming works but it flickers until it gets to full on or full off. I am sure that this is a timing issue but can't see where to get at it. I am at 60 Hz, 120V. I am using the code as previously posted.

I know that some of you (Mister_e) feel like you are beating a dead horse with this dimmer project, but if you can help me get through this, I will post my final code, circuit diagrams and parts lists so that anyone can build this and you will never have to deal with it again (hopefully!).

Thanks (Mister_e)!

Atom058

mister_e
- 17th October 2006, 04:47
interesting. to me it's sounds like a an delay offset in the Zero Crossing. Done by the transformer AND the 470uF cap.

Can be solved in software.

Give me the transformer information, part #, voltage etc. I will work on this.

Atom058
- 17th October 2006, 12:05
Steve - Thanks for your reply - The transformer is from Jameco (www.jameco.com), P/N: 249412. The spec sheet says that I should be getting 8VAC @ 1.6A (I know that is a little over-kill on the amperage, but it is what I had lying around), but I am measuring 9.8VAC across the input to my bridge rectifier. Using a voltage divider (4k7 & 10K), that gets the DC voltage to GPIO.4 down to 4.33VDC. The cap is a 470 uF 25V electrolytic.

Let me know if you need anything else... Thanks!

Atom058

Atom058
- 21st October 2006, 17:27
Steve - Any luck with the info that I posted?

I've been looking at some related posts and I am wondering if the timing problem is related to the maxdelay value. If I am running at 60 hz, that means that I complete 1 cycle every 16.7 mS. Or, I cross zero every 8.35 mS (8350 uS). Is that correct? In the code, MaxDelay is 6000 uS. Is this where my problem is?

Can you tell me why the transformer and 470 uF cap is of interest to you? How does this affect my timing?

Every day is a learning experience and I'm always looking for more!

Thanks! Atom058

Atom058
- 24th October 2006, 00:35
I would love to hear from anyone that has successfully built this dimmer that is discussed on this thread. I have followed the code and schematics (as well as the changes to both) and can not achieve the end result. The circuit and code, as it stands now, will allow me to go to full on and full off by quickly tapping the inc/dec buttons. This part works perfectly. If I press and hold the inc/dec buttons, the lighting level changes gradually, just like it is supposed to, but I get flickering. Mister-e seems to think that it is a timing issue - and I am in agreement, but I do not know where to make adjustments. If anyone can give me some trouble-shooting ideas, I would greatly appreciate it.

I think this is a great design that has many uses. I would love to get it to work and post my final results!

This circuit, once I get it right, is going to be the basis for a larger design, But until I get this part working, I can not move forward.

Please help!
Atom058

mister_e
- 25th October 2006, 15:45
Yes it's a timing problem, and there's no way to determine the exact one between all transformer brand and model. Adding a calibration process is possible but... usefull?

grabbing the signal directly from the li ne is the only way i see to make it work with all transformer.

Transformerless PSU is another way.... i hate that but if everything is properly done and insulated, the user shouldn't be hurt one day.

Give me a couple of days.. i'm on a rush now.

Atom058
- 27th October 2006, 00:53
Steve - Thanks for your reply - I was actually on the path of a transformerless supply like you suggested. I have built the design that was presented by Melanie in another thread and get a nice clean 5VDC to drive my pic. I am pulling the AC for the trigger and putting it through a 20M dropping resistor (to go to pin 3 of my pic) per the schematic for the PIC REF-4 application note. However, this only drops the voltage to around 30V AC. Do I need to get it down to <= 5VAC or is 30VAC OK?

Atom058

mister_e
- 27th October 2006, 03:03
I did something like that for one user here that use a 10Meg directly from the main to a PIC input. The PIC internal diode do their job. As now it seems to works. The user is still alive... Just make sure you properly insulate your stuff.....

The 30VAC you get is without load...just your voltmeter.

Atom058
- 27th October 2006, 12:13
Thanks Steve! I will give it a try and let you know what happens!

Atom058
- 28th October 2006, 19:21
Steve! The transformerless supply did the trick! Works like a charm now. In the next couple of days, I will post everything I have so that anyone can build this (and not bug you about it anymore).

Thanks for all your help! Atom058

mister_e
- 30th October 2006, 03:55
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=881&d=1148640458">

Atom058
- 31st October 2006, 02:49
Here is the artwork, BOM and code for the new-and-improved AC Lamp Dimmer. Everything you need to make one. There is only one issue that I have with this but it is not important for my use, but maybe someone else can shed some light (!) on it. When going from full bright and dimming down, it makes a small "jump" down in brightness but then dims nice and smooth the rest of the way. I am sure it's a timing thing but I could not figure it out. Anyway, enjoy! And thanks to Steve (Mister_e) for his help and patience (nice dancing letters, by the way)!

You'll be hearing more from me!

Atom058

Pic_User
- 4th August 2007, 05:27
<img src=" http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1906&stc=1&d=1186201559">

FromTheCockpit
- 7th August 2010, 17:28
Can't wait to return home... use the following ACDetect routine instead.
this should work.


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.

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.

Darrel Taylor
- 8th August 2010, 18:48
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?

FromTheCockpit
- 8th August 2010, 20:30
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!)

Darrel Taylor
- 9th August 2010, 03:36
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.


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.

4684

HTH,

Darrel Taylor
- 9th August 2010, 04:49
Read the previous post first.
Then if you want both halves of the cycle, try this ...

INTEDG VAR OPTION_REG.6
; ...

ACDetect:
if triacdelay != 8000 then triac = 0
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

INTEDG = !INTEDG
@ INT_RETURN

4685

FromTheCockpit
- 9th August 2010, 10:21
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.


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.

4684

HTH,

Thanks Darrel, I just noticed that in your simulation there is no 1k between the two zeners, instead there is 3.3Meg. I will try the code and update here.

FromTheCockpit
- 9th August 2010, 13:43
Hi, I tried the following first:

INTEDG VAR OPTION_REG.6
; ...

ACDetect:
if triacdelay != 8000 then triac = 0
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

INTEDG = !INTEDG
@ INT_RETURN

RESULT: The bulb attached to the output did not responded to the change in triac delay value, it just kept glowing at the same intensity.

Then I experimented a little and came up with the following:

while 1

pause 3000
high buz: pause 500 : low buz
triacdelay=8000 : pause 15000 :high buz: pause 50 : low buz
triacdelay=7998 : pause 15000 :high buz: pause 50 : low buz
triacdelay=7950 : pause 15000 :high buz: pause 50 : low buz
triacdelay=7900 : pause 15000 :high buz: pause 50 : low buz
triacdelay=7850 : pause 15000 :high buz: pause 500 : low buz
triacdelay=0 : pause 12000

wend


ACDetect:
; if triacdelay != 8000 then triac = 0
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

INTEDG = !INTEDG
@ INT_RETURN

RESULT: The bulb responded to the changing value of triac delay, at value of 8000 it goes full bright which is normal BUT when at first lower value than 8000, it dims quiet a lot. I want it to dim a only a little at first step. I even tried 7998 after 8000 but no luck i.e. 2 uS delay.

Darrel Taylor
- 9th August 2010, 23:52
You're right, I had the resistors wrong.
Making the change brought it up to 4.6V.
But, having the zeners in there adds about 40uS to the zero-cross signal.
It takes 35uS without the zeners, and 75uS with them.

Add in the interrupt latency for PBP type interrupts, time to do math in the handler, the minimum pauseus of 24us, and taking into account that a half cycle of 60hz is 8,333uS ... I'm sure the first step was quite a bit dimmer.

But the biggest problem is delaying inside the interrupt handler.
When 90% of the time is spent in the handler, the pause 10000 in the main loop takes almost a minute.

So here's my next attempt.
It uses Timer1 for the delays, so the main program can keep running in the foreground.
The handlers have been changed to ASM type to minimize latencies.
And the math is done in a separate subroutine that only runs once when you change the brightness, instead of having to do the math on every zero-cross.

It should be pretty close to the MAX/MIN dimming, but you may need to adjust the MaxBright/MinBright constants a little.
If you adjust them too far, it will start flashing.


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

MaxBright CON 8250 ; maximum brightness
MinBright CON 200 ; minimum dimming
Brightness var word
TriacDelay var Word
AlwaysON var BIT
AlwaysOFF var BIT
OffPeriod var BIT ; used by timer1 periods

Triac var PortA.1 ' Output to TRIAC gate
ACLine var PortA.2 ' Input for the FullWave rectify AC line
Buz var PortC.2

INTEDG VAR OPTION_REG.6
TMR1ON VAR T1CON.0
TMR1IF VAR PIR1.0
Timer1 VAR WORD EXT
@Timer1 = TMR1L

TRISA = %001100
TRISC = 0
CMCON = 7
ANSEL = 0
PORTA=0
PORTC=0

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ACDetect, ASM, yes
INT_Handler TMR1_INT, _T1Handler, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT_INT ; enable external (INT) interrupts
@ INT_ENABLE TMR1_INT ; enable Timer1 interrupts

Triac=0 ' disable Triac Gate
brightness=0 ' Set delay to minimum
gosub SetDelay

while 1
pause 3000
high buz: pause 500 : low buz
brightness=MaxBright : gosub SetDelay : pause 10000 :high buz: pause 50 : low buz
brightness=MaxBright-2 : gosub SetDelay : pause 10000 :high buz: pause 50 : low buz
brightness=4500 : gosub SetDelay : pause 10000 :high buz: pause 50 : low buz
brightness=4000 : gosub SetDelay : pause 10000 :high buz: pause 50 : low buz
brightness=3500 : gosub SetDelay : pause 10000 :high buz: pause 50 : low buz
brightness=MinBright : gosub SetDelay : pause 10000 :high buz: pause 50 : low buz
brightness=0 : gosub SetDelay : pause 7000
wend

SetDelay:
Brightness = Brightness min MaxBright ; limit maximum brightness
AlwaysON = !(Brightness != MaxBright) ; MaxBright is always ON
AlwaysOFF = !(Brightness != 0) ; 0 is always OFF
if !AlwaysOFF then Brightness = Brightness max MinBright ; limit minimum dimming
triacdelay = -(MaxBright - Brightness) ; calc delay time
RETURN

;------------------------------------------
T1Handler:
if OffPeriod then ; triac delay finished
OffPeriod = 0
triac=1 ; turn on triac
Timer1 = -50 ; load timer for 50uS
else
triac = 0 ; turn off triac after 50uS
TMR1ON = 0
endif
@ INT_RETURN

;------------------------------------------
ACDetect:
if AlwaysON then
triac=1 ' Activate TRIAC
else
if AlwaysOFF then
triac = 0
else
Timer1 = triacdelay ; load delay into timer
TMR1IF = 0 ; clear the interrupt flag
TMR1ON = 1 ; start the timer
OffPeriod = 1 ; tell T1Handler this is the main delay
endif
endif

INTEDG = !INTEDG ; toggle INTEDG to get both edges
@ INT_RETURN

Hope that works better.

FromTheCockpit
- 10th August 2010, 10:12
Thanks Darrel, I am on 50Hz, do I need to change any value in the code for that??

Darrel Taylor
- 10th August 2010, 16:16
There's another reason for the first step being much dimmer.

Half a cycle of 50hz, is 10,000uS.
So take MaxBright up to 9900.