AC Dimmer

Post here first, or if you can't find a relevant section!
pokemon99
Posts: 50
Joined: Wed Jun 07, 2017 9:09 am

AC Dimmer

Post by pokemon99 » Mon Dec 11, 2017 9:45 am

Good afternoon.
There is a dimer working on the scheme http://www.instructables.com/id/Arduino ... e-circuit/
The resistor ratings are replaced, the circuit is working.
The question is this. Is it possible to replace the zero detector with a timer?

Code: Select all

volatile uint16 i = 0;            
volatile boolean zero_cross = 0;
uint16 dimming = 128; 

void zero_cross_detect() {
  zero_cross = true;
   i = 0;
  gpio_write_bit(GPIOA, 1, 0);// turn off TRIAC (and AC)
}

void handler_AC() {
  if (zero_cross == true)
  {
    if (i >= dimming) {    
      gpio_write_bit(GPIOA, 1, 1);
      i = 0;       
      zero_cross = false; 
    }
    else {
      i++; 
    }
  }

void setup()
{
  //afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);
  pinMode(PA1, OUTPUT);// Set AC Load pin as output
  attachInterrupt(PB0, zero_cross_detect, CHANGE);

  Timer2.pause();
  Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);
  Timer2.setPeriod(75); 
  Timer2.setCompare1(1); 
  Timer2.attachCompare1Interrupt(handler_AC);
  Timer2.refresh();
  Timer2.resume();
}

void loop()  {
  dimming = 95;
}

User avatar
ahull
Posts: 1729
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: AC Dimmer

Post by ahull » Mon Dec 11, 2017 10:08 am

If you mean a timer running at the mains frequency, then no. Your timer would not be synchronised to the exact frequency of the mains and this would result in unpredictable results, I imagine your light or other load would pulse at a frequency equivalent to the difference between your timers approximation of the mains frequency, and the actual mains frequency. At best this would result in a lot of flickering or pulsing depending on what you are driving, at worst it might result in whatever load you had on the device releasing the magic smoke.
- Andy Hull -

pokemon99
Posts: 50
Joined: Wed Jun 07, 2017 9:09 am

Re: AC Dimmer

Post by pokemon99 » Mon Dec 11, 2017 10:15 am

Yes, that is right. I tried to use another timer, and there are flickers and pretty strong ones.
I'm not very strong in the timers, so I thought maybe I did not start it correctly.

User avatar
ahull
Posts: 1729
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: AC Dimmer

Post by ahull » Mon Dec 11, 2017 10:35 am

The issue is that you need to actually synchronise the dimming with the zero crossing point of the mains, and this needs to be detected.

You cannot estimate it, as the mains frequency is not 100% accurate (and neither is the timer on the STM32F103), so there will always be some discrepancy between the two. So the electricity utility companies idea of what 50Hz or 60Hz is, will differ by a certain un-knowable percentage from the STM32F103's idea of what 50hz or 60Hz is, furthermore both of these values will drift over time, due to other factors, such as temperature, accuracy of crystals, speed of turbines in the power plant and so forth..

There is no escaping the need for some form of zero crossing point detector for this kind of dimmer i'm afraid. :idea:
- Andy Hull -

User avatar
RogerClark
Posts: 7686
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: AC Dimmer

Post by RogerClark » Mon Dec 11, 2017 10:46 am

I've done a lot of investigation into this, and you definitely can't replace the Zero Crossing detector... Its absolutely essential

There are a few GotYa's with this stuff

Firstly the basic zero crossing detector you are using,is very susceptible to mains noise, and its likely you will get a trigger when your fridge turns on or any fluorescent lights are turned on or off.
Also, the zero crossing is triggered long before the actual zero crossing. I can't remember exactly when its triggered but it could be 10 degrees before zero etc.
Also... The circuit is really wasteful, as it uses high wattage resistors to drop the mains voltage to the 2 or 3 v needed to light the LED in the opto coupler. Half watt resistors will get hot as they will need to dissipate around 0.96W i.e 96% of their maximum rated value

I tried this circuit and found problematic and now use a more complicated circuit, which uses a transistor as well as an opto. But at the moment I can't find the circuit I used.


In your sketch, you need to start the timer when the zero crossing occurs, and turn on the triac when the timer interrupt is called.

Because your Zero crossing detector will trigger long before the real zero crossing, you will be able to get away with turning off the triac in the zero crossing detector, but if you use a better zero crossing detector, which detects the crossing more accurately, then there can be problems with the triac not turning off in time, before it gets latched on in the next half cycle.

So I ended up just turning the triac on for a short period (in the timer ISR) in theory triacs need a reasonable long ON time, but in practice it didnt need to be that long at all

You will find with your zero crossing detector that you can't operate in the range below about 5% of phase angle and above 90 to 95%, and most firmware's cheat and below 5 they turn off all the time and above 90% they turn the triac on all the time.

This may be OK for you, but is noticeable on some loads.

One final thing, which it took me ages to resolve, is that if you switch on at 50% though the cycle, you get 50% power but if you turn on at 25% phase angle you do not get 25% power (in watts).

This is because of the nature of the sine wave. i.e very little power is in the area (V * I) in the first 25% of the cycle.
The only way to resolve this is to use a lookup table - and it took me ages to build my lookup table as the maths is not solvable by normal methods.
It has to be solved by Newton Raphson approximation.

User avatar
RogerClark
Posts: 7686
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: AC Dimmer

Post by RogerClark » Mon Dec 11, 2017 10:47 am

I forgot to say the mains frequency varies a bit, so you also need to calibrate for actual frequency.

However the electricity companies have to keep it pretty accurate as its uses for time keeping, so I didnt both with that

pokemon99
Posts: 50
Joined: Wed Jun 07, 2017 9:09 am

Re: AC Dimmer

Post by pokemon99 » Mon Dec 11, 2017 10:53 am

Oк, thanks.
But small jumps are tolerable, it's not for lamps, it's for a heating element that does not create light but only heat.

User avatar
RogerClark
Posts: 7686
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: AC Dimmer

Post by RogerClark » Mon Dec 11, 2017 11:04 am

Ok.

what you are are using is fine for a heater.

BTW. I found the circuit I used

Image

http://dextrel.net/diyzerocrosser.htm

I built a 5kW heater controller, custom PCB, But in the end I never used it.

pokemon99
Posts: 50
Joined: Wed Jun 07, 2017 9:09 am

Re: AC Dimmer

Post by pokemon99 » Mon Dec 11, 2017 11:12 am

Replaced 82k by 43k x2
4N35 - PC814
5.1k - 4.7K on 3.3v

On this code, a couple of controllers operate, from 0.5 kw to 4 kW.
There were no problems.
And in general to what I raised this issue.
The controller came in and changed the temperature sensor.
Works on pic16f690, ac dimmer, but it uses moc3023 and BTA16,
and there is no Zero Cross Detector.
So it became interesting how can it be on the timers it works
Attachments
Dimmer2.jpg
Dimmer2.jpg (53.82 KiB) Viewed 313 times

User avatar
ahull
Posts: 1729
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: AC Dimmer

Post by ahull » Mon Dec 11, 2017 11:41 am

RogerClark wrote:
Mon Dec 11, 2017 10:46 am
...
Also... The circuit is really wasteful, as it uses high wattage resistors to drop the mains voltage to the 2 or 3 v needed to light the LED in the opto coupler. Half watt resistors will get hot as they will need to dissipate around 0.96W i.e 96% of their maximum rated value
...
It occurs to me, you might get better efficiency from a capacitive dropper. https://en.wikipedia.org/wiki/Capacitive_power_supply
- Andy Hull -

Post Reply