View previous topic :: View next topic |
Author |
Message |
shams
Joined: 30 Jun 2013 Posts: 11
|
A question about Triac triggering |
Posted: Sun Jun 30, 2013 7:39 am |
|
|
Hi:
I'm new to PIC MCU.
I'm doing an experiment with the PIC16F6886 to trigger a Triac to switch (ON/OFF) an AC lamp. But the triac is not correctly triggering. Actually triac is triggered at zero cross but the filament of the light is just red (not full bright).
Code: |
#include <16F886.h>
#fuses HS
#fuses NOMCLR, NOPROTECT, NOPUT
#use delay(clock=20M)
//#define zerocross PIN_B0
//#define gate PIN_C0
int ZC;
#INT_EXT //External Interrupt
void EXT_isr(void)
{
if (input(PIN_B0))
ext_int_edge(H_TO_L);
ZC = 1;
}
void main( void ) {
set_tris_B(0b00000001);
set_tris_C(0b00000000);
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while (1) {
if (ZC)
{
output_high(PIN_C0);
delay_ms(500);
output_low(PIN_C0);
delay_ms(500);
ZC = 0;
}
}
}
|
Would you please answer why the triac is not triggering correctly? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Jun 30, 2013 8:27 am |
|
|
Let's assume that you really are triggering on the zero-cross.
What do you think is happening during the two off delay_ms(500) intervals?
Mike
EDIT I'm surprised you can't see something else happening with your lamp.
Plus you've only given us a few clues about your hardware. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun Jun 30, 2013 9:18 am |
|
|
We'd have to know 'what kind of AC lamp'? 12V,120V, 240V? frequency of 'line or mains'? 50Hz,50Hz, 400Hz?
Actual schematic would help...Is PIC ground tied to line neutral?
Triac driver(ie. MOC3030) used ?
Do you have an oscilloscope to view waveform?
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sun Jun 30, 2013 10:47 am |
|
|
There are some obvious real problems though. After the first pass through the interrupt, it'll trigger in future on the falling edge. Is this what is wanted?. If so, set this in the main before starting.
Then the total of 1000mSec between triggers, means assuming the hardware fires the triac on (say) the rising edge of the pulse, it'll fire once every second, for one cycle. A typical triac pulse would be perhaps a few uSec, not 500mSec.
Code: |
#include <16F886.h>
#fuses HS
#fuses NOMCLR, NOPROTECT, NOPUT
#use delay(clock=20M)
int1 ZC=FALSE;
#INT_EXT //External Interrupt
void EXT_isr(void)
{
ZC = TRUE;
}
void main( void ) {
output_b(0);
output_c(0);
output_float(PIN_B0);
//drive all pins low, except B0, set as input
ext_int_edge(H_TO_L); //set the edge to trigger on the ZC signal
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while (1) {
if (ZC)
{
//delay_ms(something);
output_high(PIN_C0);
delay_uSec(5);
output_low(PIN_C0);
ZC = FALSE;
}
}
}
|
This will only work, if a lot of 'guesses' about your hardware are true, and will turn the light full on. If you delay for half a mains cycle where I show 'delay_ms(something)', it'll instead give half power etc... |
|
|
shams
Joined: 30 Jun 2013 Posts: 11
|
|
Posted: Sun Jun 30, 2013 10:57 am |
|
|
Many thanks buddy for your responses. I'm actually trying to learn about Triac firing by the PIC.
Here is the actual schematic. I hope zero crossing is ok. By the way, I forgot to draw the crystal part for the MCU.
http://liana-tech.com/temp/Image1.png
The AC mains are 220V/50Hz and PIC is totally isolated from AC mains. Unfortunately I do not have an oscilloscope.
I do really appreciate your feedback.
Last edited by shams on Sun Jun 30, 2013 11:42 pm; edited 1 time in total |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Jun 30, 2013 1:35 pm |
|
|
You have not answered my question!
Mike |
|
|
shams
Joined: 30 Jun 2013 Posts: 11
|
|
Posted: Sun Jun 30, 2013 11:38 pm |
|
|
@Mike:
Sorry I forgot to answer your question. I was just experimenting triac firing at zero from PIC. I added some delay (on/off) to make the light on/off visible. But I understand now, my thinking was wrong.
@Ttelmah:
My main goal was firing the triac at zero on rising edge then wait some time (so that I can see the light is ON) and turn it off.
I ran your code at the mentioned HW but still triac is not firing.
I uploaded the complete schematic. Please advice...why it is not working as expected.
Just one note, I used 100pF for crystal since I have it lowest in my stock at the moment. Can it be a problem?
Complete Schematic:
http://liana-tech.com/temp/Image2.png |
|
|
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
|
Posted: Mon Jul 01, 2013 3:16 am |
|
|
Some more questions / thoughts:
- Is the controller running at all and with the correct speed?
=> Add a blinking LED for test use...
- Why are you not using the internal oscillator?
(consider with 50Hz AC you have 100 zero crossings and 100 delayed switch-on's per second). |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon Jul 01, 2013 3:57 am |
|
|
Also the interrupt will need to be set to L_TO_H to detect the rising edge.
When you fire a TRIAC, it stays on till the next zero crossing. So full power is given by a pulse ASAP after the zero crossing point, Half power by turning it on 'mid cycle' etc..
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Mon Jul 01, 2013 5:44 am |
|
|
100 pf is way to high! typically 18-27 pf will work.
If your PIC has an internal oscillator , use that !!
1) Cut code for a simple 1Hz blinking LED to confirm both hardware and softeare is correct.
2)Add a red LED in series with the optocoupler LED, replace 330r to 230r. This will give you a 'free' visual indicator of signal to the triac driver electronics.
3)You should add a cap(say 100-500mfd) to the LM7805 output( Vdd, +5v).
hth
jay |
|
|
shams
Joined: 30 Jun 2013 Posts: 11
|
|
Posted: Mon Jul 01, 2013 8:33 am |
|
|
Thanks Jay.
I used an LED in series with the opto and that really helped.
I learnt the concept a bit now though still I have a few questions. Ttelmah suggested a 5uS delay (in while loop) to turn off the triac. I would like to know what is is the maximum time I can keep the triac ON. Is it less than 10mS for 50Hz?
Code: |
while (1) {
if (ZC)
{
//delay_ms(something);
output_high(PIN_C0);
delay_uSec(5) //I suppose it should be delay_uS(5)
output_low(PIN_C0);
ZC = FALSE;
}
}
|
I see that the triac is now firing. But the light is blinking. Is it because I use one edge (rising edge only) for firing? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon Jul 01, 2013 9:17 am |
|
|
The pulse has nothing to do with how long the TRIAC is on......
You send a single pulse to the gate of the TRIAC. It then _stays on_ to the next zero crossing.
At the next zero crossing it goes of, and a pulse is then needed to turn it on again.
So as I already said, for 'full on', you send the pulse as soon as possible after the zero crossing. For 50Hz mains, if instead you wait 1/200th second, and then turn the TRIAC on, it'll be on for the next 200th second till the zero crossing.
This is also why TRIAC's make so much buzz/hum. If you are at half power, you are switching it on 'bang in the middle', of the mains cycle peak....
Best Wishes |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Jul 01, 2013 10:25 am |
|
|
the 'on time' for the MOC3021 in your program,
is awfully short after a
careful reading of the datasheet ( Fairchild or Moto)
The D.S. will show you that this is a brutally short trigger time for this part, and with such short a brief LED on time TEMPERATURE will play a larger role than you might guess if attempting stable, very late triggering.
as is the on time is only about 1 part in 2000 for a 50hz mains freq.
another concern with the basic approach to phase angle detectionshown here is the significant Hfe variations over temperature in the transistor, which will strongly affect the timing and width of the narrow negative trigger pulse applied to the PIC.
to say nothing of the code |
|
|
shams
Joined: 30 Jun 2013 Posts: 11
|
|
Posted: Mon Jul 01, 2013 10:45 am |
|
|
Wonderful. Thanks Ttelmah. I really got it.
Quote: | as is the on time is only about 1 part in 2000 for a 50hz mains freq.
|
@asmboy: This is why I was asking about the max ON time.
By the way, I saw that some peoples also uses INT_EXT and timer INT both to fire the triac. Why a timer INT is needed? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon Jul 01, 2013 2:44 pm |
|
|
Because you want to adjust how long _after_ the zero cross, you fire the TRIAC.....
Surprised 5uSec is considered short. The units I use accept nSec trigger pulses. However they are very high power devices.
Best Wishes |
|
|
|