Hi #ArudinoTeam
I'm working on a project where I'm using ATMega328P to control 2 dimmers using 2 relays.
If I'm using a single dimmer and controlling the load then there is no problem even if it runs for 2hours.
But when I try to dim the loads simultaneously then when 1 load dims then the second load is also varying.
What may be the reasons why this is being effected?
Hi
We need to see your code and a complete diagram including your two loads.
How do you control the dimming?
What is your inputs, please include them in your diagram.
Thanks ... Tom...
Please use code tags when posting your code.
What may be the reasons why this is being effected?
If the code and circuit are correct, then it is probably interference between the two dimmers. Try snubber circuits on the load and run wth wires away from each other.
But we need to see you are doing the fundamentals right first.
Thanks @Tom & @Mike
I'm attaching the code and 2 dimmers circuit
#include <Wire.h>
#define DIM_Relay 4
#define SC_Relay 10
#define DIM_AC_LOAD 11
#define SC_AC_LOAD 9
int volatile dimming = 128;
int volatile specon = 127;
int data_in;
void setup()
{
Serial.begin(9600);
Wire.begin(8);
Wire.onReceive(receiveEvent);
pinMode(DIM_AC_LOAD, OUTPUT);
pinMode(SC_AC_LOAD, OUTPUT);
pinMode(DIM_Relay, OUTPUT);
pinMode(SC_Relay, OUTPUT);
digitalWrite(DIM_Relay, 1);
digitalWrite(SC_Relay, 1);
attachInterrupt(digitalPinToInterrupt(2), dim_zero_crosss_int, RISING);
attachInterrupt(digitalPinToInterrupt(3), sc_zero_crosss_int, RISING);
}
void loop()
{
if (data_in == 5)
{
digitalWrite(DIM_Relay, 0);
dimming = 5;
}
else if (data_in == 6)
{
digitalWrite(SC_Relay, 0);
specon = 6;
}
else if (data_in == 25)
{
specon = 25;
}
else if (data_in == 30)
{
dimming = 30;
}
else if (data_in == 50)
{
specon = 50;
}
else if (data_in == 55)
{
dimming = 55;
}
else if (data_in == 75)
{
specon = 75;
}
else if (data_in == 80)
{
dimming = 80;
}
else if (data_in == 100)
{
specon = 100;
}
else if (data_in == 105)
{
dimming = 105;
}
else if (data_in == 127)
{
digitalWrite(SC_Relay, 1);
specon = 127;
}
else if (data_in == 128)
{
digitalWrite(DIM_Relay, 1);
dimming = 128;
}
}
void receiveEvent()
{
int x = Wire.read();
Serial.println(x);
data_in = x;
}
void dim_zero_crosss_int()
{
int dimtime = (75 * dimming);
delayMicroseconds(dimtime);
digitalWrite(DIM_AC_LOAD, HIGH);
delayMicroseconds(10);
digitalWrite(DIM_AC_LOAD, LOW);
}
void sc_zero_crosss_int()
{
int sctime = (75 * specon);
delayMicroseconds(sctime);
digitalWrite(SC_AC_LOAD, HIGH);
delayMicroseconds(10);
digitalWrite(SC_AC_LOAD, LOW);
}
The inputs are being given from Raspberry Pi through I2C.
#Mike, According to MOC3021 Datasheet I've included snubber circuit that is R6,C1 & R16,C2
Thanks for your help guys
Opto currents are very low with blue LEDs (Vf of ~3.3volt).
~0.5mA for the relay opto LEDs and ~2.3mA for the opto triac.
Normally red indicator LEDs are used for that (Vf of ~1.8volt).
~2mA for the relay opto LEDs and 9mA for the opto triac.
Leo..
Three issues.
- What Leo mentioned above about your gate control.
- You have two zero crossing detectors, you only need one.
2 Your code uses the delayMicroseconds() function.
The result is that each load is only being controlled every other line cycle. In time it looks like this:
Cycle 1 2 3 4 5 6
Load1 1 1 1
Load2 1 1 1
Look at the "Blink without Delay()" example in the IDE for how to solve this.
ThankYou @Leo, I'll be using Red Led's...
Thanks @avr_fred,
one zero crossing detector?
but I'm using two dimmer circuit and each requires ZCD right?
what happens if I use 1 or 2?
So how should I use this function so that it shouldn't effect the other load when running simultaneously?
but I'm using two dimmer circuit and each requires ZCD right?
As the electricity feeding the each zero crossing detector is coming from the same source why would the zero crossing time be any different?
But I actually don't want both the dimmers should have the same dimming.
Like say if I'm using Bulb as Load1 and Fan as Load2, if I give ZCD as common to both and try to control dimming of Bulb then even Fan will dim with the same value.
I actually want to control both the Loads differently.
No you don't get it. The zero crossing time is a reference point, you control the dimming by delaying the turn on point from the zero crossing point. With two different delays you have two different dimming values.
I think this misunderstanding has permeated into your writing of the software where you take it in turns to fire the dimmers.
OH!
Thanks but still I'm unable to get done in software
Can you help me through that plz?
Thanks in advance
You have to throw away the idea of using a delay function and take the blink without delay approach. This would involve waiting until he zero crossing point happened. Then looking at the millisecond or microsecond timer until it is time to fire each of the triacs. Once a Triac is fired then you don't look at that value anymore until the next cycle.
Hi,
I think you need to research how Triac control works, and why you need zero crossing detection.
If you look at your circuit both of your detectors will output exactly the same signal, that is when the AC MAINS POWER SUPPLY crosses the zero volts potential, it has nothing to do with how many loads or type of load you are controlling.
On your diagram you show two AC MAINS SUPPLIES, but they are both the same supply.
Tom...
Because in your code dimtime and sctime always differ by at least 75 microseconds, you might be able to operate the two triac triggers from within the same zero crossing ISR using the delayMicroseconds() method you are using.
You can do something like this
void triacTriggers() { //Function fired by zero crossing interrupt
delayMicroseconds(shorter delay time);
digitalWrite(shorterTimeTriggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(shorterTimeTriggerPin, LOW);
delayMicroseconds(longer delay time - (shorter delay time+10));
digitalWrite(longerTimeTriggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(longerTimeTriggerPin, LOW);
}