Set Firing Angle TRIAC using optocoupler with PWM

Hello I am back,
I tried to TRIAC test

the result so good
Thanks for everyone help :smiley:

actually, next I try to manage TRIAC trigger pulse,

I used this code for making TRIAC trigger pulse

const int ledPin =  13;      // the number of the LED pin

void setup() 
{
 pinMode(ledPin, OUTPUT);      

}

void loop()
{
digitalWrite ( ledPin, ( (millis() % 9) == 0 ) ) ;
}

That just code for single pin,

I need to 3 output trigger pulse with 4ms different each other...
to make it work in 3 phase control.
lets say...

A = 0 ms
B = 4 ms
C = 8 ms

How to make that code? without delay

Best Regard,

Ninonic

I used this code for making TRIAC trigger pulse

What is this line supposed to do?

digitalWrite ( ledPin, ( (millis() % 9) == 0 ) ) ;

Basically it is weird. Form what I can see it will be low for 8mS and high for 1mS. This is not the way to generate a pulse.

Is it because "ledPin" ?

And why not?

Ninonic:
Is it because "ledPin" ?

No.
It is the bit where you link the logic output to the System timer. This requires you to continuously call the digitalWrite function at least every mS.
There is no way you can synchronised this to the zero crossing which is what you need to do.
You have been continuously told this and yet you keep ignoring this. Until you get your head round this fact you are wasting everyone's time.

What a sad truth
I was not ignoring that, I just don't understand
Sorry for wasting your time,
Sorry

I dunno what to do....
God
Help me

Ok, maybe this my final question

Sir

What if I use 2 arduino,

1 for reading input and decision maker

Another just for digitalWrite output?

What if I use 2 arduino,

Then you make the problem 10 times harder to write.

I was not ignoring that, I just don't understand

By not saying that you don't understand you are ignoring me.
The way this forum works is that if you don't understand something you ask.

You need to be able to detect when the zero crossing of the AC waveform you want to control has occurred, and hang all your timing off that.

The simplest way is to get a logic level square wave generated from the AC signal, through an optical isolator.
Then the code needs to enter a loop that waits until the signal changes. This is simple, suppose the signal is coming in on pin 4 then the code:-

while( digitalRead(4) != lastRead) { } // this only exits when pin 4 changes state
lastRead = digitalRead(4);
// now do the delay and then fire the triac

where "lastRead" is a global or static int

Grumpy_Mike:
You need to be able to detect when the zero crossing of the AC waveform you want to control has occurred, and hang all your timing off that.

Look like we got misunderstanding here.
Ok
I did zero crossing, but just single zerocrossing(I prefer one, because using 3 zcross it change whole my circuit board).
Since I have 3 TRIAC to trigger(3 phase)

so I hang with 1 zerocross input, but need to write 3 output

*NOTE : 3 phase balanced with same load and measured phase before

lets say... for time delay like this

phase A to B 4ms, phase B to C 4ms
A = 0 ms
B = 4 ms
C = 8 ms

code I using :

int lastread = LOW;
unsigned long phaseA;
//unsigned long phaseB;
//unsigned long phaseC;
unsigned const interval = 1;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(4,INPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  while(digitalRead(4) != lastread)
  {
      digitalWrite(13,(millis()%9)
      millis()=phaseA;
      if(phaseA-interval>=4UL)
      {
      digitalWrite(12,(millis()%9)
            if(phaseA-interval>=8UL)
            digitalWrite(11,(millis()%9)
      }
  }
  lastRead = digitalRead(4)
}
// the loop function runs over and over again forever
void loop() 
{
      
}

Is that code you mean?
I am not sure with timing code one

I have never tried to code 3-phase ac using an arduino, but I do know that 3-phase phase shift is 120 degrees. If a 60 Hz ac signal has a period of 16.6667 mS, and 120 degrees is 1/3 of 360 degrees, I would think that 120 degree phase shift would be t+ 5.5555 mS and t + 11.1111 mS, so the phases would be :

A: t + 0
B: t + 5.5555 mS (120 degree phase shift)
C: t + 11.111 mS B + 120 degree phase shift)

NOT
A: t + 0,
B: t + 4 mS (90 degree phase shift)
and
C: t + 8 mS (B + 90 degree phase shift)

Thanks for advice

I will reconfigure the value for right timing,

But the problem is how to code it?

There a little more to it then just 120 + 120 + 120 = 360 you want fix power factor which means you have to keep 90 and 270 and 360 inline too.
Power factor correction: a guide for the plant engineer

The code in reply #44 is still not having a zero crossing synchronization.
Please read my replies. Their should be nothing in the 'while' braces for the synchronization. You need to do the synchronization EVERY cycle. The code in the setup function is run only once.

Plus what the others have said.

But the problem is how to code it?

By using a state machine and the blink without delay example expanded to three state machines.

@be80be
That document says:-

Low power factor means you’re not fully utilizing the electrical power you’re paying for

Which is the wrong way round. In fact industrial users are charged a punitive rate for having a poor power factor. If it were not for this extra tariff, or you are a domestic user you would actually be being charged less that the power you are using with a poor power factor.

Ninonic:
Thanks for advice

I will reconfigure the value for right timing,

But the problem is how to code it?

Hello again,

So you are trying to do 3 phase now?
Did you get single phase working first?

Mike I kind of think this it wrong first off if the voltage drops you will use more power to do the same work.
If your voltage is 240 volts load 100 amps you use 24000 Watts
Now if the voltage drops your load becomes 106 amps you use 25440 Watts
If you added a bank of caps to keep the voltage to 240 you save money because you used 1440 less watts.
By phase shifting you want change the 90 deg points to a higher level.

Mike I kind of think this it wrong first off if the voltage drops ......

But the voltage doesn't drop it is just out of phase with the current.

An electricity meter only charges for the power projected on the real axis, so you essentially get free power with an inductive load. The electricity companies don't like that so for industrial users they charge extra if the power factor drops below a certain point any time in the billing period, for the whole billing period. This is way more than normal prices hence it is worth industrial users having power factor correction capacitors on site.

For domestic users the equipment you use has power factor corrections fitted in appropriate devices. However, if you remove them then all still works and it costs you next to nothing to run.

Grumpy_Mike:
The code in reply #44 is still not having a zero crossing synchronization.
Please read my replies. Their should be nothing in the 'while' braces for the synchronization. You need to do the synchronization EVERY cycle. The code in the setup function is run only once.

Plus what the others have said.
By using a state machine and the blink without delay example expanded to three state machines.

So... I just add to void loop() function?

pin 4 is for zerocross, hmmm

sorry, its hard for me to under stand

Grumpy_Mike:
Plus what the others have said.
By using a state machine and the blink without delay example expanded to three state machines.

I ever think about that, using blink without delay sample.

but in that sample the duty cycle just for only 50:50 which mean can't use for trigger,
even I use this to start millis() %9) each pulse change, it just work for 1 phase
how I can add 2 others phase?

its so complicated for me since I must manage it in 3 phase.

be80be:
Power factor correction: a guide for the plant engineer

thanks for reference

MrAl:
Hello again,
So you are trying to do 3 phase now?
Did you get single phase working first?

Hi MrAl,

ya, I think its work but still in breadboard with 5V AC for safety.
next 3 phase with 220 AC (fused 2A) with load around 1K - 3K3 ohm

I read others post last night, still try to understand and try to coding
still can't generate 3 phase trigger pulse

pin 4 is for zerocross, hmmm

NO!
I said "say" pin 4. This means it is what ever pin you connect the zero crossing circuit to.

but in that sample the duty cycle just for only 50:50 which mean can't use for trigger,

So you change it. Look programming is not about cut and paste, it is about writing instructions that do what YOU want to do.

even I use this to start millis() %9)

Stop using that statement / method. It is stupid and it will not work for you.

its so complicated for me

I am beginning to think it is too complicated for you with your current state of knowledge. Here we are at post #53 and you appear to have made no progress at all. Get a single phase working first. You think that you have done this but I see no evidence that you have. You have posted no code that will work and the static scope shots you have posted have not shown the expected wave forms.

next 3 phase with 220 AC (fused 2A) with load around 1K - 3K3 ohm

Quite honestly with the competence you have shown so far I would be surprised if you manage to avoid an explosion. Certainly electrocution and a fire are on the cards if you continue without actually learning something.

So lets get things clear. Please post the code and the schematic for what you think is a working single phase, phase angle control. If that works then we can look at how to extend this three phase BUT you must show us that you can understand a single phase system first.

How I suppose to do?

Maybe some cut paste sometimes happen for me, but that not I wanted to.
if I know
I will write it as long as I can understand the arduino language.

So, maybe I hope you consider my limit
I know, my capabilities below standart,
But I tried so hard till this way far.

You told that millis() %9)) is stupid thing?
Do you give any better idea to code?
Please tell me

I just wanna tell in mind
(*Why don't just write down then tell me how its work? Its simple and ez for you too)

Sorry that just my mind,

So lets get things clear. Please post the code and the schematic for what you think is a working single phase, phase angle control. If that works then we can look at how to extend this three phase BUT you must show us that you can understand a single phase system first.

int lastread = LOW;
unsigned long phaseA;
//unsigned long phaseB;
//unsigned long phaseC;
unsigned const interval = 1;

// the setup function runs once when you press reset or power the board
void setup() {
 // initialize digital pin 13 as an output.
 pinMode(12,INPUT);
 pinMode(11, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(9, OUTPUT);
 while(digitalRead(12) != lastread)
 {
   digitalWrite(11,(millis()%9));
   millis()=phaseA;
   if(phaseA-interval>=4UL)
   {
     digitalWrite(10,(millis()%9));
     if(phaseA-interval>=8UL)
       digitalWrite(9,(millis()%9));
   }
 }
 lastRead = digitalRead(12)
 }
 // the loop function runs over and over again forever
 void loop()
 {
   while(digitalRead(12) != lastread)
   {
     digitalWrite(11,(millis()%9));
     millis()=phaseA;
     if(phaseA-interval>=4UL)
     {
       digitalWrite(10,(millis()%9));
       if(phaseA-interval>=8UL)
         digitalWrite(9,(millis()%9));
     }
   }
   lastRead = digitalRead(12)   
   }

If you use ISIS Proteus 7, I attached the .DSN file

triac control.zip (15.5 KB)