TechSmartSolutions / 0-10v-lighting-controller-for-Home-Assistant

The purpose of this repo is to explain how you can build 0-10v controllers that can be used for controlling lighting and other compatible devices (such as certain dehumidifiers and air conditioners) using an ESP, ESPhome and Home Assistant.
15 stars 2 forks source link

PWM Frequency of 24 Channel PWM Board does NOT fit for MeanWell drivers #9

Open p1ngb4ck opened 3 months ago

p1ngb4ck commented 3 months ago

Hi !

When I stumbled upon this project, it seemed to be exactly what I need. .. now I realize the following, stating from the docs/datasheets:

"The TLC5947 is integrated with a 4-Mhz internal oscillator. and the 12-bit GS data include 4095 steps. So the frequency of the 12-bit PWM is 4MHz and the frequency of LED is 4MHz/4095." - this means fixed pwm frequency of 4MHz.

Datasheet MeanWell Driver regarding DIM-function: "◎ Applying additive 10V PWM signal (frequency range 100Hz ~ 3KHz):" - range for pwm = 100Hz up to 3KHz. So its a completely different value-area.

The 24 Channel PWM Board example is titled with "tested" - Do you by chance know for sure, that the 4MHz 10V PWM is actually/indeed interpreted/seen as additive voltage for dimming by the driver ? If so, the 15mA per channel would be sufficient for the 10mA required for additive voltage ...

Also: I have currently built the circuit - and I am trying to get the 0V-10V range as exact as possible, with a 12V supply on specific channels, while leaving the voltage range on other channels as 0-12V (fans, using the pwm as base for an additional transistor towards "feeding" voltage supply) - what resistor ratings do you suggest ?

TechSmartSolutions commented 3 months ago

When I said “tested” that means I built it and it functioned without apparent issue. I have been using it every day since this repo went online (still using it right now!) and so far no problems.

If you’re concerned you can call or email Meanwell tech support, they are surprisingly helpful most of the time and they’ve always let me talk directly with an engineer to answer questions like this. If you’re still concerned you can ask them what would happen if you feed your drivers a 4mhz 0-10v pwm signal.

Here’s what mine is running, I think it’s 6x HLG-320’s and some smaller ones mixed in.

Honestly this thing has been amazing. I was trying to do this for a long time so it has been super helpful to have it.

On Sat, Apr 13, 2024 at 4:18 AM Oliver Kleinecke @.***> wrote:

Hi !

When I stumbled upon this project, it seemed to be exactly what I need. .. now I realize the following, stating from the docs/datasheets:

"The TLC5947 is integrated with a 4-Mhz internal oscillator. and the 12-bit GS data include 4095 steps. So the frequency of the 12-bit PWM is 4MHz and the frequency of LED is 4MHz/4095." - this means fixed pwm frequency of 4MHz.

Datasheet MeanWell Driver regarding DIM-function: "◎ Applying additive 10V PWM signal (frequency range 100Hz ~ 3KHz):" - range for pwm = 100Hz up to 3KHz. So its a completely different value-area.

The 24 Channel PWM Board example is titled with "tested" - Do you by chance know for sure, that the 4MHz 10V PWM is actually/indeed interpreted/seen as additive voltage for dimming by the driver ? If so, the 15mA per channel would be sufficient for the 10mA required for additive voltage ...

Also: I have currently built the circuit - and I am trying to get the 0V-10V range as exact as possible, with a 12V supply on specific channels, while leaving the voltage range on other channels as 0-12V (fans, using the pwm as base for an additional transistor towards "feeding" voltage supply) - what resistor ratings do you suggest ?

— Reply to this email directly, view it on GitHub https://github.com/TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5M4K47AQ6QR6YARRPXUMOLY5EBBBAVCNFSM6AAAAABGFLGDKOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2DCNBZGIZDANA . You are receiving this because you are subscribed to this thread.Message ID: <TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9@ github.com>

TechSmartSolutions commented 3 months ago

Shoot I guess image upload doesn’t work via email. I’ll try to login and show you pictures of mine currently in operation.

On Sat, Apr 13, 2024 at 4:18 AM Oliver Kleinecke @.***> wrote:

Hi !

When I stumbled upon this project, it seemed to be exactly what I need. .. now I realize the following, stating from the docs/datasheets:

"The TLC5947 is integrated with a 4-Mhz internal oscillator. and the 12-bit GS data include 4095 steps. So the frequency of the 12-bit PWM is 4MHz and the frequency of LED is 4MHz/4095." - this means fixed pwm frequency of 4MHz.

Datasheet MeanWell Driver regarding DIM-function: "◎ Applying additive 10V PWM signal (frequency range 100Hz ~ 3KHz):" - range for pwm = 100Hz up to 3KHz. So its a completely different value-area.

The 24 Channel PWM Board example is titled with "tested" - Do you by chance know for sure, that the 4MHz 10V PWM is actually/indeed interpreted/seen as additive voltage for dimming by the driver ? If so, the 15mA per channel would be sufficient for the 10mA required for additive voltage ...

Also: I have currently built the circuit - and I am trying to get the 0V-10V range as exact as possible, with a 12V supply on specific channels, while leaving the voltage range on other channels as 0-12V (fans, using the pwm as base for an additional transistor towards "feeding" voltage supply) - what resistor ratings do you suggest ?

— Reply to this email directly, view it on GitHub https://github.com/TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5M4K47AQ6QR6YARRPXUMOLY5EBBBAVCNFSM6AAAAABGFLGDKOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2DCNBZGIZDANA . You are receiving this because you are subscribed to this thread.Message ID: <TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9@ github.com>

p1ngb4ck commented 3 months ago

Hey I was setting up everything, but when measuring, I got very very strange results. Maybe you really should check if your output is as desired for the different stages with a multimeter... What would happen if you feed a 4MHz signal, is that the driver sees it as additive voltage dimming. And yes, during my measurements, it was working in a way, that you could dim via pwm - but just not with reliable exact values, e.g. 50% pwm results in 25% voltage of 12V (4.23V or so), basically behaving like a curve

TechSmartSolutions commented 3 months ago

"I have currently built the circuit - and I am trying to get the 0V-10V range as exact as possible, with a 12V supply on specific channels, while leaving the voltage range on other channels as 0-12V (fans, using the pwm as base for an additional transistor towards "feeding" voltage supply) - what resistor ratings do you suggest ?"

That is an interesting idea, to be able to use this to generate different PVM voltages by 'stepping down' the voltage on some channels using a resistor.. I have to come clean I'm not much of an electronics engineer, I just built this to solve a problem I was having... so I can't answer the question directly, but, there might be a way that would just cost a bit more space/money; what about the mosfet boards you can find online. Using the PWM signals from the controller to feed the mosfet board, you can have a different voltage going to the mosfet board, so you can have for example 12v running on the main controller and then 4x channels connected to a mosfet board running 10v pwm. Or vice versa 10v PWM on the main board and 4x 12v channels running off the mosfet. I would use the step down converter to give you a 10v signal off your 12v supply, pretty sure you can do it easier and cheaper if you have the know how, but the mosfet boards pretty cheap and it saves all the time from figuring it out using resistors.

On Sat, Apr 13, 2024 at 4:18 AM Oliver Kleinecke @.***> wrote:

Hi !

When I stumbled upon this project, it seemed to be exactly what I need. .. now I realize the following, stating from the docs/datasheets:

"The TLC5947 is integrated with a 4-Mhz internal oscillator. and the 12-bit GS data include 4095 steps. So the frequency of the 12-bit PWM is 4MHz and the frequency of LED is 4MHz/4095." - this means fixed pwm frequency of 4MHz.

Datasheet MeanWell Driver regarding DIM-function: "◎ Applying additive 10V PWM signal (frequency range 100Hz ~ 3KHz):" - range for pwm = 100Hz up to 3KHz. So its a completely different value-area.

The 24 Channel PWM Board example is titled with "tested" - Do you by chance know for sure, that the 4MHz 10V PWM is actually/indeed interpreted/seen as additive voltage for dimming by the driver ? If so, the 15mA per channel would be sufficient for the 10mA required for additive voltage ...

Also: I have currently built the circuit - and I am trying to get the 0V-10V range as exact as possible, with a 12V supply on specific channels, while leaving the voltage range on other channels as 0-12V (fans, using the pwm as base for an additional transistor towards "feeding" voltage supply) - what resistor ratings do you suggest ?

— Reply to this email directly, view it on GitHub https://github.com/TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5M4K47AQ6QR6YARRPXUMOLY5EBBBAVCNFSM6AAAAABGFLGDKOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2DCNBZGIZDANA . You are receiving this because you are subscribed to this thread.Message ID: <TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9@ github.com>

TechSmartSolutions commented 3 months ago

Really? When I tested mine with a multimeter everything looked like I expected it to. It honestly has worked flawlessly for me and I have it on a closet full of Meanwell Drivers.

On Sat, Apr 13, 2024 at 8:50 AM Oliver Kleinecke @.***> wrote:

Hey I was setting up everything, but when measuring, I got very very strange results. Maybe you really should check if your output is as desired for the different stages with a multimeter...

— Reply to this email directly, view it on GitHub https://github.com/TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9#issuecomment-2053667832, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5M4K45HSZJLFZLS6BE6MFTY5FA2HAVCNFSM6AAAAABGFLGDKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJTGY3DOOBTGI . You are receiving this because you commented.Message ID: <TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9/2053667832 @github.com>

TechSmartSolutions commented 3 months ago

Pardon my responses I can't login to github so I'm replying via email. I didn't see your reply.

I'm trying to think I remember what you're saying about the curve when I was testing.. ...

I just realized I didn't include any homeassistant code for the ESP device that I was using.

Here is the code I'm using today. I think you're right it's not perfect, but in practical terms, it works perfectly for my application. I just needed to be able to control my lights to adjust the output so that it was right for my target space, which it does. ...

Here's the YAML I'm using for the controller in HA:

======BEGIN YAML for ESP device======

esphome: name: "my-light-controller"

esp8266: board: esp01_1m

logger:

api:

ota:

wifi: ssid: !secret wifi_ssid password: !secret wifi_password

ap: ssid: "saywhat" password: "odom2o930"

captive_portal:

tlc5947: data_pin: GPIO16 clock_pin: GPIO14 lat_pin: GPIO12

output:

light:

On Sat, Apr 13, 2024 at 8:57 AM Rick Sanchez C-137 @.***> wrote:

Really? When I tested mine with a multimeter everything looked like I expected it to. It honestly has worked flawlessly for me and I have it on a closet full of Meanwell Drivers.

On Sat, Apr 13, 2024 at 8:50 AM Oliver Kleinecke @.***> wrote:

Hey I was setting up everything, but when measuring, I got very very strange results. Maybe you really should check if your output is as desired for the different stages with a multimeter...

— Reply to this email directly, view it on GitHub https://github.com/TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9#issuecomment-2053667832, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5M4K45HSZJLFZLS6BE6MFTY5FA2HAVCNFSM6AAAAABGFLGDKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJTGY3DOOBTGI . You are receiving this because you commented.Message ID: <TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9/2053667832 @github.com>

p1ngb4ck commented 3 months ago

yes, this is exactly how I set it up. When measuring with a multimeter I did absolutely not get the desired values, when not running at 100% or 0% - do you have a multimeter to check?

I am investigating right now.. What I can definitely confirm already, is that an alternate circuit with the PCA9685 16channel servo pwm driver module works :

I set that up with a pwm frequency of 1kHz and using its pwm output to control a small 2N3904 NPN transistor. PWM out of the module goes to the transistor base with a 1k-ohm base resistor and a load resistor of 10k-ohms between collector and 12V source - the output produces an exakt 1kHz 10V PWM if capped to 83.34% and using 0-84 as base for 100% calculation.

p1ngb4ck commented 3 months ago

Okay I can confirm this all together now and I have a solution also.

The general idea is great don`t get me wrong. But there is some problems with the setup, I would love to see corrected, because they can cause major issues for people who use it in lots of use cases, because the circuit (just the TLC5947 one !) does not work as expected. So. What I can confirm is, using your circuit you have a kind of dimming - just not the way you expect it to act, because:

But - that just doesnt matter, as my solution now will be even much better than the "original" circuit here - providing "expected" linear results, not requiring another power supply source apart from a 5V one, that will also power the mcu - and providing REAL pwm, where the power source inside the meanwell driver itself is used and only switched by pwm. Imagine this the following way : "Inside" the driver is a small 10V V+ and GND and they are left open connected to the DIM+ and DIM- cables. You can now just "put a switch" between them and keep it pressed for 1s, then leave it not pressed for 1s and repeat - with a frequency of 300Hz to 1kHz - thats what the pwm dimming actually means. Why cant you just connect an arduino/esp GPIO-PWM-Pin ? Simply because those cant handle 10V voltage that would run over them when duty cycle is on "on". So in short - all you need is your tlc5947 adafruit module, dont provide a 10V/12V supply voltage at all, just power the module with 5V from 5V supply. This also reduces the complexity of the circuit in a great way, as it allows for a very cheap chinese small 230V to 5V/2A mini supply to be used - and just hooked to the main power of 1 lamp for example - or some other mains used anyhow. As soon as you have the module running, get 24 logic level transistors, like the ones stated in the following image, I got from a forum post on Arduino forum and 24x 1kOhms resistors. Then just hook each pwm pin (no need for the other resistors and 10V or 12V supply, just connect pwm pin) with one of the resistors to the base and collector to DIM+ and emitter to DIM-. Then you will also have expected "linear" output. You could test this also with hooking up the 5V in series with a 10k Ohms resistor to the collector side and GND to emitter, then measure voltage - it will be the percentage of 5V that you set the duty cycle to.

Wawa-Arduino-Forum-MeanWell-PWM-Dim

This was taken from a post from Wawa on the arduino-forum towards that topic. Remember : We power the TLC5947 with 5V and its PWM pins will therefore run with 5V supply voltage - and therefore we dont(!) need to take the 3.3V GPIO voltage of the ESP32/ESP8266 into account.

Hope this helps, thanks so much for the in general awesome idea to use this TLC5947 module with home assistant and stuff. Will post results from my built along with some pictures etc Regards ...

TechSmartSolutions commented 3 months ago

Thanks for all the work you did. Like I said it does work for me and I’m able to dim from 0-100, so whatever you need to make it work for you application all the power to you 👍 good work

On Sun, Apr 14, 2024 at 7:42 AM Oliver Kleinecke @.***> wrote:

Okay I can confirm this all together now and I have a solution also.

The general idea is great don`t get me wrong. But there is some problems with the setup, I would love to see corrected, because they can cause major issues for people who use it in lots of use cases, because the circuit (just the TLC5947 one !) does not work as expected. So. What I can confirm is, using your circuit you have a kind of dimming - just not the way you expect it to act, because:

  • this is not pwm dimming, this is dimming via additive voltage. You generate a specific voltage using the pwm signal, that`s also why the pwm frequency "has nothing to do" (very easily spoken) with the pwm frequency of the MeanWell driver. For generating a voltage with pwm, the higher freq is better, because it makes the voltage more "smooth" - and you could also add a small cap to improve that further. BUT: This is not PWM dimming. This is dimming via additive voltage. Problem: With this circuit, the generated voltage does NOT act as expected, regarding the value. For example, you use a 12V supply source, you would assume giving a 80% pwm duty cycle would result in 10V and a 50% duty cycle would result in 6V - but it does NOT. Take a multimeter, set the pwm duty to 50% and measure yourself. With my built of this circuit, I used 12.1V supply voltage, 50% duty cycle -> resulted in 1.859V (!!!!!!!). Either there is some bug in the code for the tlc5947 or there is sth wrong with the circuit.

But - that just doesnt matter, as my solution now will be even much better than the "original" circuit here - providing "expected" linear results, not requiring another power supply source apart from a 5V one, that will also power the mcu - and providing REAL pwm, where the power source inside the meanwell driver itself is used and only switched by pwm. Imagine this the following way : "Inside" the driver is a small 10V V+ and GND and they are left open connected to the DIM+ and DIM- cables. You can now just "put a switch" between them and keep it pressed for 1s, then leave it not pressed for 1s and repeat - with a frequency of 300Hz to 1kHz - thats what the pwm dimming actually means. Why cant you just connect an arduino/esp GPIO-PWM-Pin ? Simply because those cant handle 10V voltage that would run over them when duty cycle is on "on". So in short - all you need is your tlc5947 adafruit module, dont provide a 10V/12V supply voltage at all, just power the module with 5V from 5V supply. This also reduces the complexity of the circuit in a great way, as it allows for a very cheap chinese small 230V to 5V/2A mini supply to be used - and just hooked to the main power of 1 lamp for example - or some other mains used anyhow. As soon as you have the module running, get 24 logic level transistors, like the ones stated in the following image, I got from a forum post on Arduino forum and 24x 1kOhms resistors. Then just hook each pwm pin (no need for the other resistors and 10V or 12V supply, just connect pwm pin) with one of the resistors to the base and collector to DIM+ and emitter to DIM-. Then you will also have expected "linear" output. You could test this also with hooking up the 5V in series with a 10k Ohms resistor to the collector side and GND to emitter, then measure voltage - it will be the percentage of 5V that you set the duty cycle to. Wawa-Arduino-Forum-MeanWell-PWM-Dim.png (view on web) https://github.com/TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/assets/588481/9922c94d-1b38-4672-8fd2-d5fda31ea991 This was taken from a post from Wawa on the arduino-forum towards that topic. Remember : We power the TLC5947 with 5V and its PWM pins will therefore run with 5V supply voltage - and therefore we dont(!) need to take the 3.3V GPIO voltage of the ESP32/ESP8266 into account.

Hope this helps, thanks so much for the in general awesome idea to use this TLC5947 module with home assistant and stuff. Will post results from my built along with some pictures etc Regards ...

— Reply to this email directly, view it on GitHub https://github.com/TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9#issuecomment-2054065952, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5M4K44SG4UOITGTZJDMTALY5KBUPAVCNFSM6AAAAABGFLGDKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJUGA3DKOJVGI . You are receiving this because you commented.Message ID: <TechSmartSolutions/0-10v-lighting-controller-for-Home-Assistant/issues/9/2054065952 @github.com>

p1ngb4ck commented 3 months ago

Thank YOU mate - and - I now found out the keyword here is the gamma_correct setting that you also have in your config - this was the reason for the strange voltages - it defaults to 2.8 and together with inversion results in the mentioned result-voltage-curve if not set. So I can now confirm your circuit works as expected with the gamme correct set. Could you put that to the description for others as important fact to know, together with your conf? Thanks SOOO much. This is actually awesome. The other stuff is true though - you are applying additive voltage, not pwm, and you could get rid of the 10V/12V power supply allltogether with the module I mentioned, resistor & transistor. Also, I already managed to implement the "relay-switch-off" and stuff like that - would you mind me mentioning your awesome project, when I put my version up as a "pseudo-fork" here?

p1ngb4ck commented 3 months ago

Also, maybe just change the description to "Additive voltage dimming" - then you are completely on the technically correct side regarding the description also - could help prevent wrong assumptions for users.

I suggest following info added to the 24 Channel MeanWell - Dimmer setup with the TLC5947 Adafruit module:

As long as the gamma_correct = 1 setting is set correctly, you can provide a 12V supply source and just set the max_power setting to 0.80, resulting in max. 10V with a 100% setting. Do NOT use this for fans though, as the PWM pin is not able to switch their loads that quick. For that, you will need my setup, with the 6V 16 channel servo control PWM module, 2n222 transistors and resistors, as those transistors can handle load currents up to 700mA - enough for 12V fans (around 0.2A normally). A 2n3904 has max. current of 200mA - that is too much on the edge for my liking.

Sorry for that wall of text, but I though I could leave my findings here, to save time for others. Best regards =) and thx again for the awesome project. Please put up more info for others, as this is really really great as soon as it works as intended ! Best regards

TechSmartSolutions commented 3 months ago

I can link your fork from the main description page on this repo!Yes the gamma correct was required and I will add it with a description of sample config file to the readme/repo. Thank you for taking the time to further this project! I hope that it’ll help others.On Apr 14, 2024, at 2:49 PM, Oliver Kleinecke @.***> wrote: Also, maybe just change the description to "Additive voltage dimming" - then you are completely on the technically correct side also - could help prevent wrong assumptions for users.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

p1ngb4ck commented 2 months ago

Hey mate, just as an update in case it is interesting:

First of all - I think I owe you "kind of" an apology - while it is indeed true, that you are using additive voltage dimming with the circuit you created - that additive voltage dimming method is the better / preferable solution compared to pwm dimming directly. Reason is, that the true pwm dimming is much more prone to longer cable issues. The solution I made with true pwm also works - but is inferior to your solution. I was able to build my own two prototypes right now, using both the tcl5947 and the pca9685 board together with npn transistor circuits now, and I have PWM, additive Voltage dimming and fan control combined and working, as well as an additional sensor board connectable via i2c (works over long cables also) that will go inside the tent then. Currently I am building a separate pcb - people could then order a cheap controller board from a pcb manufacturer very cheap, without the hassle of building the whole circuit.

Thanks a lot for your work again, will update as soon as project is rdy for "deployment" :D

TechSmartSolutions commented 2 months ago

Hey man, no apology necessary I started this git page to share what I did so that others can benefit, and you did! It makes me glad you found it useful and grateful you were able to contribute to the project with all your research and information.  I struggled to figure how to get a working gadget for years so I really felt like I had to share it as I couldn’t be the only one out there trying to do it.  On May 13, 2024, at 8:56 AM, Oliver Kleinecke @.***> wrote: Hey mate, just as an update in case it is interesting: First of all - I think I owe you "kind of" an apology - while it is indeed true, that you are using additive voltage dimming with the circuit you created - that additive voltage dimming method is the better / preferable solution compared to pwm dimming directly. Reason is, that the true pwm dimming is much more prone to longer cable issues. The solution I made with true pwm also works - but is inferior to your solution. I was able to build my own two prototypes right now, using both the tcl5947 and the pca9685 board together with npn transistor circuits now, and I have PWM, additive Voltage dimming and fan control combined and working, as well as an additional sensor board connectable via i2c (works over long cables also) that will go inside the tent then. Currently I am building a separate pcb - people could then order a cheap controller board from a pcb manufacturer very cheap, without the hassle of building the whole circuit. Thanks a lot for your work again, will update as soon as project is rdy for "deployment" :D

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>