Tasmota: Next try of zero crossing PWM control after recent changes

Created on 26 Jun 2020  路  14Comments  路  Source: arendst/Tasmota

Have you looked for this feature in other issues and in the docs?

Is your feature request related to a problem? Please describe.
_A clear and concise description of what the problem is._
AC Dimmer need the PWM synced with the AC sinus. This was Impossible due to the PWM implementation until know. latest changes generate a very fine and reliable signal. The zero crossing therefore only need do Trimm after some time. Not on every sinus.
Describe the solution you'd like
_A clear and concise description of what you want to happen._
Check if and how we can integrate the zero crossing as an input signal.

Describe alternatives you've considered
_A clear and concise description of any alternative solutions or features you've considered._

Additional context
_Add any other context or screenshots about the feature request here._

(Please, remember to close the issue when the problem has been addressed)

enhancement fixed

Most helpful comment

Yes, this will work. I tested it exactly with this device. Made some changes today to fix accidental reboot when you change dimmer on the webpage.

All 14 comments

AC Dimming in Tasmota is going to be a challenge because it is not a Real Time Software for making a precise ZCD.

Anyway, It can be checked also how it is implemented in ESPHome (https://github.com/esphome/esphome/pull/880)

Here are my idea how we can make it possible:

  • User PWM1 and PWMfrequency 100 or 120 depending on country
  • Use COUNTER1 as input for the zero crossing
  • Every 1000 steps (10 seconds) do some slight magic to keep the PWM start in Sync. There is now a PHASE that we might can use (@s-hadinger can you help how we can influence the phase synchronisation?)

Real Time Software is not required because be can use the PWM frequency. This is now after several fixes the last week very stable. We need "just" start the PWM with the zero cross and then check every 10 seconds if it is in phase and not shift it a few ns.

I checked the ESPHome but it looks like this is nothing we can use without breaking everything.

I changed the counter driver with just some lines. After 1 second i realign the phase with the zero trigger. Works fine on the oscilloscope. Anyhow my first test with a 60w bulb did not work. Now it look like the triac is broken. The data sheet say 2A ok and max 5A. The bulb in operation only creates about 0.3A. Not heat detected. Any idea? Will share code changes for retest.

@stefanbode Probably harmonic oscillations in the high-frequency range were created.
That kills.
https://books.google.de/books?id=4OTRBgAAQBAJ&pg=PA150&lpg=PA150&dq=Triac+RC+glied&source=bl&ots=OD3hV2Rk7e&sig=ACfU3U13Ynlf-BIL_GRs2ZpVw558e-he0A&hl=en&sa=X&ved=2ahUKEwj2l4KIsKfqAhVC_qQKHYm7BcsQ6AEwCHoECAYQAQ#v=onepage&q=Triac%20RC%20glied&f=false
Using a SSR is easier :-)

I will try to upload the reference sketch first and check if this in principal works. The bulb is a pure ohm-60W-lamp. Just to ensure not to make it to complicated fist. Anyhow this part of hardware seems more complicated than expected. SSR? Never heard. Need to google it. Will upload some pictures and videos today.

Ok, SSR solid-state-relay. I assume this will not solve the Pwm problem that you need to start with the zero crossing. Just putting 100HZ PWM will result in pulsating lamp because the RMS changes if you start in different times of the sinus. The frequency of the main slightly changes and also the esp is not 100% accurate.

Yes, a SSR is just easier to use. Zero Cross Detection is still needed and needs to be insync with switching the Relay on/off
Curios if it is not in perfect sync, it has any visual impact.

I got it working without flickring and in most situations. Support only PWM1 with COUNTER1. All changed though DIMMER command or the Web-Slider.

Remove the "core...." files from source.
Use latest PWM module (platform.ino)

[tasmota_core]
; *** Esp8266 Arduino core 2.7.1
platform                  = [email protected]
platform_packages         = https://github.com/Jason2866/platform-espressif8266/releases/download/2.8.0/esp8266-2.8.0.zip
build_flags               = ${esp82xx_defaults.build_flags}

Add xns_01_counter.ino line 79ff

    if bitRead(Counter.pin_state, index) {
      //stb mod
      // PWMfrequency 100
      // restart PWM 4-times a second (german 50Hz has to much deviation)
      // set COUNTERDEBOUNCELOW 1 to catch the raising edge
      // Zero-HIGH is typical 2ms
      if (RtcSettings.pulse_counter[index]%25 == 0 && PinUsed(GPIO_PWM1, index)) {
        // stop pwm on PIN to start in Sync with rising edge
        // calculate timeoffset to fire PWM
        uint16_t dimm_time= 10000 / Settings.pwm_frequency * (100 - light_state.getDimmer(index)) ;
        analogWrite(Pin(GPIO_PWM1, index), 0);
        delayMicroseconds(dimm_time);
        // fire small PWM signal to start TRIAC/SSR. Kill on next
        // zero phase automatic.
        analogWrite(Pin(GPIO_PWM1, index), 100);
      }
      return;

Current findings:
The often sold preconfigured Items are are cutting leading edge. Therefore you must start dependent on DIMMER late in the sinus wave the PWM. The PWM just needs 1% and can be fixed. The light intensity is defined by the delay after the zero cross before you trigger the Triac. The Triac stay open until the next zero phases. Nothing to do to stop.

Open issues:
need a setoption for the mess. Theoretically, with some changes it should be possible to drive up to FOUR Dimmer (setoption68 1). On DIMMER=0 or other low values I have exceptions. Still something wrong
Not clear if counter needs a reset from time to time.

@Jason2866, @arendst : Where can I find the source files core_esp8266_waveform... core_esp8266_wiring.... that you use in the ZIP file of core 2.8.0. These work fine and I can influence the start of the PWM. The files in TASMOTA do not have this functionality.

Done. Problem fixed!

@stefanbode Tasmota has the same files as my compilation Core "2.8" for PWM since the shutter fix.
The files are in source folder "Tasmota"
When do we see a PR :-)

The PR is now submitted. But I need more control over the PWMfrequency. Currently implemented by adding an arduino standard class. Any help is appreciated. Without this change there is a very visible pumping of the light intensity visible. Especially at low light. This is because electricity companies uses the frequency to manage their network load. You ave to follow this to have a steady light. If implementing more AC dimmer this will only work on the same AC phase. They must all share the same zero-counter. Let's see how and ifthe community likes it and what feature request are comming

Yes, this will work. I tested it exactly with this device. Made some changes today to fix accidental reboot when you change dimmer on the webpage.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wirelesssolution picture wirelesssolution  路  3Comments

ximonline picture ximonline  路  3Comments

Vujagig picture Vujagig  路  3Comments

he-so picture he-so  路  3Comments

abzman picture abzman  路  3Comments