Hello,

I got my arduino connected to a triac with a zero detection circuit.
Using this to control the number of AC pulses sent to a load. So far i am detecting each to 220V AC period and use a 10 period frame.

For example: 20% on it would send first two periods and then nothing for the rest of 8: X X _ _ _ _ _ _
70% it would send seven consecutive periods and then nothing: X X X X X X X _ _ _

Problem with this method is that especially for low loads the pause periods are too big. Ideally the Active and pause periods are spread across equally, so 50% should be X _ X _ X _ X _ and so on.

I kept trying but can’t get my head around an algorithm for achieving this. Any pseudo-code or guidance would be appreciated.

For low duty cycles 0-50% i was thinking of calculating the number of pause pulses with something like 10 div duty_cycle. Where duty cycle has values 0 - 10.

Using this connected to 2 pins:

Here’s the interrupt section (getting triggered every time voltage croesses 0)
val holds the input, a number from 0 to 10 and PWM_pin is connected to the triac, so when it goes high AC mains is connected to the load.

``````void IRAM_ATTR handleInterrupt() {
if (new_period) {
extraction_check1++;
if(val <= 5){
if (count == 1) {
digitalWrite(PWM_pin, HIGH);
count++;
}
else {
digitalWrite(PWM_pin, LOW);
count++;
if (count >= (10/val)) count = 1;
}

}  else {
if (counter == 0 && val > 0) digitalWrite(PWM_pin, HIGH);
if (counter == val) digitalWrite(PWM_pin, LOW);
counter++;
if (counter >= MAX_VALUE) counter = 0;
}
}
new_period = !new_period;

}
``````

Hello Mesmer,
Welcome to the forum.

Please read 'How to us this forum - please read' posted at the top of this and every forum. When you have done that then post your code in code tags like it says so we have some idea of what you have tried. A circuit diagram might be useful too.

Thanks.

Thanks, i updated the initial post.

I got my arduino connected to a triac with a zero detection circuit.
Using this to control the number of AC pulses sent to a load. So far i am detecting each to 220V AC period and use a 10 period frame.

For example: 20% on it would send first two periods and then nothing for the rest of 8: X X _ _ _ _ _ _
70% it would send seven consecutive periods and then nothing: X X X X X X X _ _ _

Is there some reason why you are using this mode of control rather than chopping each pulse

https://playground.arduino.cc/Main/ACPhaseControl/

Is there some reason why you are using this mode of control rather than chopping each pulse?

I can't speak for the OP obviously, but burst control means you don't need to worry about the RFI generated by chopping half cycles. Using this method is fine for a heater or similar load.

Hi,

Using this to control the number of AC pulses sent to a load. So far i am detecting each to 220V AC period and use a 10 period frame.

Is a 10 period frame, 10 cycles?
If so then getting anything better than 1 cycle in 10 ON for 10%, is as good as it is going to get.
With 220Vac, I would think you have a mains frequency of 50Hz.

So 10% = 5 pulses per second.

Pause period;
cycle = 20ms
10% duty will be 9 cycles OFF = 9 * 20 = 180ms.

You can change to 5 cycle frame, but only have 20, 40, 60, 80 and 100% steps.
Then you will have 80ms OFF times for 20% duty.

What is the problem with low duty cycle, what is the heating unit?
What is the application?

Thanks.. Tom..

Using only every second half cycle (TRIACs switch off at the each zero crossing!) means you're using only the positive or negative halves, effectively turning AC into pulsed DC.

Can have interesting consequences depending on the load.

Forget about a fixed number of cycles, instead calculate how many ON cycles should be followed by how many OFF cycles. For 10% you know that the ratio is 1:9, 1:4 for 20%, 1:3 for 25%, 1:2 for 33% and 1:1 for 50%. 40% will be 2:3 (40/(100-40)). For higher duty cycles use the inverse table, up to 9:1 for 90%.

I'd also care for symmetric load, i.e. the number of positive pulses should roughly equal the number of negative pulses. In the simplest case count full cycles, not half cycles.